File tree 1 file changed +16
-6
lines changed 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 3
3
"""
4
4
@static
5
5
6
- Partially evaluate an expression at parse time.
6
+ Partially evaluate an expression at macro expansion time.
7
7
8
- For example, `@static Sys.iswindows() ? foo : bar` will evaluate `Sys.iswindows()` and insert
9
- either `foo` or `bar` into the expression.
10
- This is useful in cases where a construct would be invalid on other platforms,
11
- such as a `ccall` to a non-existent function.
12
- `@static if Sys.isapple() foo end` and `@static foo <&&,||> bar` are also valid syntax.
8
+ This is useful in cases where a construct would be invalid in some cases, such as a `ccall`
9
+ to a os-dependent function, or macros defined in packages that are not imported.
10
+
11
+ `@static` requires a conditional. The conditional can be in an `if` statement, a ternary
12
+ operator, or `&&`\` ||`. The conditional is evaluated by recursively expanding macros,
13
+ lowering and executing the resulting expressions. Then, the matching branch (if any) is
14
+ returned. All the other branches of the conditional are deleted before they are
15
+ macro-expanded (and lowered or executed).
16
+
17
+ # Example
18
+
19
+ Suppose we want to parse an expression `expr` that is valid only on MacOS. We could solve
20
+ this problem using `@static` with `@static if Sys.isapple() expr end`. In case we had
21
+ `expr_apple` for MacOS and `expr_others` for the other operating systems, the solution with
22
+ `@static` would be `@static Sys.isapple() ? expr_apple : expr_others`.
13
23
"""
14
24
macro static (ex)
15
25
if isa (ex, Expr)
You can’t perform that action at this time.
0 commit comments