@ operator

From MiniScript Wiki
Revision as of 16:47, 5 October 2023 by JoeStrout (talk | contribs) (Created page with "Normally in MiniScript, whenever a variable a used in an expression, if it refers to a function, that function is automatically invoked. The <c>@</c> operator suppresses this...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Normally in MiniScript, whenever a variable a used in an expression, if it refers to a function, that function is automatically invoked. The @ operator suppresses this invocation, allowing you to work with a function reference without invoking it.

Example

Try the following at any interactive MiniScript REPL:

f = rnd    // makes f contain the result of calling [[rnd]]
f          // prints that result
f          // prints that SAME result again (f is just a number
f = @rnd   // makes f refer to the [[rnd]] function
f          // invokes f, and prints a random number
f          // invokes f again, printing a DIFFERENT result