Produces the same result as
expr. Using
#%expressionforces the parsing of a form as an expression.
Examples:
The
#%expressionform is helpful in recursive definition contexts where expanding a subsequent definition can provide compile-time information for the current expression. For example, consider a
define-sym-casemacro that simply records some symbols at compile-time in a given identifier.
and then a variant of
casethat checks to make sure the symbols used in the expression match those given in the earlier definition:
If the definition follows the use like this, then the
define-sym-casemacro does not have a chance to bind
idand the
sym-casemacro signals an error:
> (let () (sym-case land-creatures 'bear [(bear) 1] [(fox) 2]) (define-sym-case land-creatures bear fox))eval:11:0: sym-case: expected an identifier bound via
define-sym-case
at: land-creatures
in: (sym-case land-creatures (quote bear) ((bear) 1)
((fox) 2))
But if the
sym-caseis wrapped in an
#%expression, then the expander does not need to expand it to know it is an expression and it moves on to the
define-sym-caseexpression.
> (let () (#%expression (sym-case sea-creatures 'whale [(whale) 1] [(squid) 2])) (define-sym-case sea-creatures whale squid) 'more...)'more...
Of course, a macro like
sym-caseshould not require its clients to add
#%expression; instead it should check the basic shape of its arguments and then expand to
#%expressionwrapped around a helper macro that calls
syntax-local-valueand finishes the expansion.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4