Advanced Computing Environment
brix-os project page
Extensions allow code to be executed at compile-time which modifies the compiler state or injects code into the program. It is possible to use extensions to create simple code substitution but requires extra boilerplate code. The `macro and `open-macro flags automate this process by wrapping a pattern with scope and injection code. Parameters and any variables exist only within the pattern but the pattern may access variables from the parent scope by prefixing them with the $ operator. A descriptive compile-time exception is thrown if the variables can't be found in the parent scope.
empty? = defx`open-macro (c:collection_interface) -> (typeOf c).isEmpty(c)
Patterns must be complete expressions and can not depend on substituion to acquire addition parameters.
foo = defx`macro (a:Number) ->
a +; // incomplete pattern x :=
foo(1) 2; // invalid message := "a message" if not
empty? message, echo message; // valid
Copyright © 1995-2017 Brand Huntsman