Macros
Macros are shorthands that take exactly one parameter and get replaced with a function call whenever referenced.
They do not exist at runtime, and as such may not be assigned to variables, object properties, and list elements. They cannot be passed as a value, since they aren't real variables.
Sparkle comes with built-in macros, such as print.
print "hello world"call Sparkle's Terminal's print with just "hello world"User-defined Macros
Custom macros may be defined using macro as the value of a variable. Note that this
variable does not exist during runtime, and as such cannot be used as a value.
let double be macro with just x as x times 2Internally, this gets converted into a function with a randomized UUID.
let __double_60a049b1987c488b8ab156d3a242666e be function with just x as x times 2Macros can be run simply by referencing their name, followed directly by an expression that will be taken as its only parameter.
let once be 1
let twice be double once
print twice # 2Of course, internally this uses the aforementioned generated function.
let twice be call __double_60a049b1987c488b8ab156d3a242666e with just onceBuilt-In Macros
Sparkle has a handful of built-in macros, to aid with very common tasks.
The following
print "hello world"is equivalent to
call Sparkle's Terminal's print with just "hello world"The following
ask "enter your name: "is equivalent to
call Sparkle's Terminal's ask with just "enter your name: "The following
pause "Press enter to continue..."is equivalent to
call Sparkle's Terminal's pause with just "Press enter to continue..."The following
assert name is equal to "sparkle"is equivalent to
call Sparkle's System's assert with just name is equal to "sparkle"The following
exit 0is equivalent to
call Sparkle's System's exit with just 0The following
sleep 500is equivalent to
call Sparkle's System's sleep with just 500