2.2 Static and Dynamic Lookup
expression | |
This binding is not exported by rhombus/static, and a binding to indicate static mode is exported, instead.
definition | |
A static . accesses a component of a target only when the access can be resolved statically, otherwise the . form is a syntax error.
A static #%index looks up a value only when the lookup operator can be specialized statically (e.g., to a list or map lookup), otherwise the lookup form is an error.
A static ++ works only when the append operation can be specialized statically (e.g., to a list or map append), otherwise the operator use is an error.
A static #%call does not require static information about functions and methods for calls, but it reports an error when the number of supplied arguments is inconsistent with static information that is available for the called function or method. Similarly, := assignment to a property is rejected if static information does not declare the property as supporting assignment.
A static with requires static information for a class on the left-hand side of with (i.e., the object to be functionally updated). An error is reported if a field name supplied on the right-hand side of with does not correspond to the field of the class.
A static for requires static information for each sequence on the right-hand side of an each form to specialize the iteration statically.
For each of these forms, static mode is detected by checking the binding of #%dynamism using the scopes of form’s operator or identifier.
Other forms not provided by rhombus might also be sensitive to dynamic mode versus static mode. Macro implementations can use syntax_meta.is_static to determine a mode.
See also Static by Default.
> class Posn(x, y)
ps[0].x
> fun bad_lookup(ps):
ps[0].x
[]: specialization not known (based on static information)
ps[0].x
x: no such field or method (based on static information)
> block:
Posn(1, 2, 3)
Posn: wrong number of arguments in function call (based on static information)
definition | |
> class Posn(x, y)
> fun (ps):
ps[0].x
#<function:fun>
A call to dynamic has no static information, even if its argument has static information, so wrapping a call to dynamic around an expression has the effect of discarding any static information available for the expression.
> class Posn(x, y)
[]: specialization not known (based on static information)
x: no such field or method (based on static information)
#<function:fun>