-
Notifications
You must be signed in to change notification settings - Fork 2
#define
These directives can be used to set variables in the current scope. This is only supported if there is a variable binder that supports the setting and unsetting of variables. Note that the #block
directive introduces such a binder, in other words you can always use #define
within a block scope.
$$#define varA = <exprA>; varB = <exprB>; ... /$$
$$#define varA$$
...
$$/define
$$#define fnA(arg0, arg1) = arg0 + arg1; .... /$$
$$#define fnA(arg0)$$
...
$$/define$$
$$#define int fnA(string arg0, Foo.Bar.SomeType arg1) = ... /$$
$$#define foo =? unknown /$$
- May be empty: yes
- May be nested: yes
As noted by the last syntax example, =?
is supported instead of =
to allow for unknown variables in the definition. These resolve to null by default.
$$#define foo = 'bar'$$
Foo is the new $$foo$$!
#define
can be usefull for snippet re-use as it can take parameters e.g.
$$#define hello(x)$$
Hello $$x$$!
$$/define$$
This can then be called using, e.g. $$hello('Marcus')$$
.
Note that currently parameter values must be strings (or will be converted to string) unless specified. Other variations:
$$#define int parse(x) = System.Int32.Parse(x) /$$
$$#define int foo(int a, int b) = a + b /$$
$$#define foo(int x)$$
$$x + 7$$
$$/define$$
Note: when no type is specified, string
is assumed. When the #define
directive has a body, no type specifier is allowed because it is set to string
.
This differs from the #let
directive in that #let
only binds a name within the statement, without affecting the context in any way. #define
causes global changes visible across files. Note that the Jefferson.FileProcessing
adds support for file-level scopes. This can be used to read in a tree of files in which for every file the variables of its ancestors are accessible but it cannot alter these.
Currently no type can be specified in a #define except when functions are used.