Skip to content

Special Form Details

Έρικ Κωνσταντόπουλος edited this page Nov 29, 2016 · 2 revisions

? (if statement)

Syntax: (? cond if-true if-false)

The if statement is more of a ternary function than an actual operator. The interpreter evaluates the condition but not the clauses before passing it to the internal ArcIf function. Once inside the function, it is decided which clause to evaluate and return.

@ (while loop)

Syntax: (@ cond loop-body)

The @ special form is both a while loop and a list generator. It takes a condition and a loop body, and evaluates the body as long as the condition has a Boolean value of true. It also compiles the result of evaluating each iteration into a list, and returns it when the loop is over.

f (for loop / list comprehension)

Syntax: (f symbol iterable loop-body)

This assigns the given symbol to each element of the iterable in turn, and evaluates the loop body for each. It compiles all of the results into a list and returns it.

: (set variable)

Syntax: (: variable-name value)

Sets the value of the variable to the given value.

F (Anonymous function aka lambda)

Syntax: (F (arg1 arg2 ...) function-body)

Creates an anonymous function with parameters inside the list of args returning the result of evaluating the function body with those parameters set.

Note: F was chosen over the more traditional λ partly because of byte count (in UTF-8, λ is two bytes), partly because F is easier to type, and partly for the mathematical-looking notation of F(x).

' (Quote / list)

Syntax: (' literally anything)

Returns its arguments as a list without evaluating them. Can be used as a list constructor.


Recipes

Named functions

Named functions can be implemented by combining the : and F special forms. For example, this snippet defines a named function +3 which adds 3 to its argument:

(: +3 (F(x)
  (+ x 3)))