6.20 Implicit Forms
Rhombus parsing is driven by bindings even for forms that have no apparent name, such as a literal expression like 7 or square brackets like [1, 2, 3]. In those cases without an apparent name an implement form is used to give meaning to the term, whether in an expression position, binding position, or other kind of position. For positions that allow only prefix operators, such as definition positions, only prefix implicits are used. Here are all of the implicit forms:
#%literal —
used for anything other than an identifier, keyword, operator, or compound form #%parens —
used for (…) #%brackets —
used for […] #%braces —
used for {…} #%quotes —
used for '…' #%call —
used as an infix form when a parsed form is followed immediately by a (…) term #%index —
used as an infix form when a parsed form is followed immediately by a […] term #%comp —
used as an infix form when a parsed form is followed immediately by a {…} term; this implicit form is not bound by rhombus #%juxtapose —
used as an infix form when a parsed form is followed immediately by a non-compound term; this implicit form is not bound by rhombus #%block —
used for a block formed with : (by itself as a would-be parsed term); this implicit form is not bound by rhombus #%alts —
used for a block formed with | (by itself as a would-be parsed term); this implicit form is not bound by rhombus #%body —
used by forms that contain a body sequence, such as block, the body of fun, and the result part of a match clause; the lexical context of the : or | that forms a block determines the #%body binding that is used
expression |
#%literal literal |
|
binding operator |
#%literal literal |
|
annotation |
#%literal literal |
|
repetition |
#%literal literal |
A literal is any individual term other than an identifier, keyword, operator, parenthesized term, bracketed term, braced term, quoted term, block, or alternatives.
> 7
7
> #%literal 7
7
> fun only_sevens(7): "yes"
> only_sevens(7)
"yes"
> only_sevens(8)
only_sevens: argument does not satisfy annotation
argument: 8
annotation: matching(7)
Produces the same value as expr, same binding as bind, and so on. Multiple expression, bindings, etc., are disallowed.
> (1+2)
3
3
> x
3