Skip to content

Definitions

Unlocked edited this page Mar 7, 2018 · 2 revisions

Syntax

Standard definition

The syntax is defname = <expression> where defname is the name being defined and <expression> is the expression that defname is being set to. The <expression> in a standard definition is evaluated at define-time, and not at call time. For call-time evaluation, a function must be used.

Because equality checking can share the same syntax as definition, standard definition will always be prioritized when syntactic context applies. Anything that could be a valid name or function definition will be seen as a name being defined in this case. In order to do real equality checking with defined names, put the equality expression in parentheses.

Function definition

While one can simply use the function literal as the expression in a standard definition to define a function, functions also have a special form definition:
funcname(a, b, c, ..., z) = <expression>
Where funcname is the function name, a, b, c, ..., z is the argument list, and <expression> is the unevaluated expression.

The memo keyword may also preceed a function definition to memoize the resultant function.

Update

A name cannot normally be redefined. For example:

x = 10
x = 5

Will throw an error on the second line, because x is already defined. To bypass this and change the value of the defined name anyways, the update keyword may be used at the very start of the line, before anything else. Reserved names may not be updated.

update memo

The update memo funcname call may also be used as shorthand. If funcname is a name which is defined to be a function, update memo funcname will enable the memoize flag and clear the cached memo values (if applicable). This might be useful in the following situation:

f(x)=x+1
memo g(x)=f(x)/2
g(9)
> 5
update f(x)=x+2
update memo g

Because g(9) had been cached to evaluate to 5, it would've incorrectly returned 5 when it should return 5.5 based on the new definition of f. update memo prevents that.

Valid names

The first character of a name may be any letter, uppercase or lowercase, or _. The rest of the characters may be those characters as well as any digit. A defined name cannot be a reserved name.

Clone this wiki locally