You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently macros allow for native code to rewrite the stream. These macros can replaced with programs written in Rejoice using a new define-syntax interpreter, defining "syntax" over the atom stream. Syntax requires two pieces of code: a regex-like pattern for matching the stream, and a template for the output stream.
Using lists as an example:
define-syntax [ %any* ] >> ~any &any list`
The pattern [ %any* ] expects the symbol [ followed by zero or more symbols, collected as a group and given the name any, and the symbol ]. The prefix % says the next symbol is a name, and not a literal. The first atom in the pattern must be a symbol, and it is how the syntax is dispatched. There cannot be more than one syntax using the same dispatch symbol. Then, for the output any is the name of the group. The prefix ~ says to ungroup the atoms. The prefix & returns the number of atoms in the group, and list` is a symbol.
Pattern language:
a -> literal value 'a'
%a -> any atom, given the name 'a'
%a+ -> one or more atoms, grouped and named 'a'
%a* -> zero or more atoms, grouped and named 'a'
%a? -> zero or one atoms, named 'a'
%a:sym -> any symbol, named 'a'
%a:int -> any integer, named 'a'
%a:bool -> any boolean, named 'a'
%a:char -> any character, named 'a'
Rewrite language:
a -> literal value 'a'
~a -> if 'a' is a group, splice it into the stream
&a -> if 'a' is a group, the length of the group
Out of scope: Identifying which symbols in a pattern are adjacent.
The text was updated successfully, but these errors were encountered:
Currently macros allow for native code to rewrite the stream. These macros can replaced with programs written in Rejoice using a new
define-syntax
interpreter, defining "syntax" over the atom stream. Syntax requires two pieces of code: a regex-like pattern for matching the stream, and a template for the output stream.Using lists as an example:
The pattern
[ %any* ]
expects the symbol[
followed by zero or more symbols, collected as a group and given the nameany
, and the symbol]
. The prefix%
says the next symbol is a name, and not a literal. The first atom in the pattern must be a symbol, and it is how the syntax is dispatched. There cannot be more than one syntax using the same dispatch symbol. Then, for the outputany
is the name of the group. The prefix~
says to ungroup the atoms. The prefix&
returns the number of atoms in the group, and list` is a symbol.Pattern language:
Rewrite language:
Out of scope: Identifying which symbols in a pattern are adjacent.
The text was updated successfully, but these errors were encountered: