Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions runtime/src/main/fusion/modules/fusion/procedure.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,26 @@ Equivalent to `(lambda () body ...)`.

// TODO This should use (provide (rename_out (thunk ||)))
// but the documentation is wrong.
(defpub ||
(defpub_syntax ||
'''
(|| body ...+)

Returns a zero-argument procedure that evaluates the `body` forms.
Equivalent to `(lambda () body ...)`.

See also [`|`](fusion/procedure.html#|).
''' thunk)
'''
(lambda (stx)
(let [(body (unsafe_pair_tail (syntax_unwrap stx)))]
(if (is_pair body)
(datum_to_syntax
(pair (quote_syntax lambda)
(pair (quote_syntax ())
body))
(quote_syntax context)
stx)
(wrong_syntax stx "Expected at least one body form")))))


(defpub (compose p1 p2)
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ SyntaxValue doExpand(Expander expander, Environment env)
throw new SyntaxException(null, message, this);
}

if (resolveSyntaxMaybe(env) != null)
{
String message = "Invalid use of syntax form as identifier expression.";
throw new SyntaxException(null, message, this);
}

Binding b = resolve();
if (b instanceof FreeBinding)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void write(Evaluator eval, Appendable out)
SyntaxValue expand(Expander expander, Environment env, SyntaxSexp stx)
throws FusionException
{
// TODO reject if not at top level
final Evaluator eval = expander.getEvaluator();

SyntaxChecker check = check(eval, stx);
Expand All @@ -87,7 +88,14 @@ SyntaxValue expand(Expander expander, Environment env, SyntaxSexp stx)
for (int i = 1; i < arity; i++)
{
SyntaxSymbol identifier = check.requiredIdentifier(i);
children[i] = expander.expandExpression(env, identifier);

// We don't want to expand the identifier since it might be syntax
// and that will fail. But we do want to determine its binding so
// we can look up documentation at runtime. This may resolve to a
// FreeBinding, which will trigger an unbound-identifier error
// during compilation, which is appropriate.

identifier.resolve();
}

return stx.copyReplacingChildren(eval, children);
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/test/fusion/scripts/bool.test.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
// Here's the bindings we expect to be available:
(module check_bindings '/fusion/bool'
[
and, cond, if, is_bool,
// These syntax forms cannot be verified this way.
// https://github.com/ion-fusion/fusion-java/issues/122
// and, cond, if, or, unless, when

is_bool,
is_false, is_true, is_truthy, is_untruthy,
not, or, unless, when,
not,
])


Expand Down
4 changes: 4 additions & 0 deletions runtime/src/test/fusion/scripts/syntax.test.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
(datum_to_syntax [id] id)


// Syntax forms cannot be used as expressions
(expect_syntax_error (list 1 if 2))


//==========================================================================
// is_identifier

Expand Down