# Reserved keywords

Reserved keyword are, with symbols and literals, the basic constituents of the writing system. With couple of exception, reserved keywords are in fact special forms. During the execution, a special

assert

The `assert` special form check for equality between two operands. Both objects must be of the same type. If the equality test fails, the special form print a message and abort the execution. By default, the assertion checking is turned off. The interpreter option `-f assert` enables the assertion checking. When the interpreter is compiled in debug mode, the assertion checking is turned on by default.

assert "form 1" "form 2"
assert true (== 1 1) assert 3 (+ 2 1)
block

The `block` special form defines a new nameset for sequential execution of regular form or implicit form. When the block form is evaluated, the block nameset is linked to its parent nameset. When all forms have been executed, the block nameset is destroyed and the result of the last evaluation in the block is considered to be the result of the block evaluation.

block "regular form" block "block form"
trans a 1 block { assert a 1 trans a (+ 1 1) assert a 2 assert ..:a 1 } assert 1 a
class

The `class` special form creates a new class object. Without argument, an instance of that class is created without data members.

class
const Color (class) trans Color:preset (red green blue) { const this:red red const this:green green const this:blue blue } const red (Color 255 0 0) const green (Color 0 255 0) const blue (Color 0 0 255)
const

The `const` special form binds a symbol with an object and marks it as a constant symbol. When used with three or four argument, a gamma expression is automatically created. `const` can also be used to bind class or instance members.

const symbol "object" const symbol "argument" "body" const symbol "argument" "closed variables" "body"
const number 123 const max (x y) (if (> x y) x y)
delay

The `delay` special form delays the evaluation of the form argument by creating a `Promise` object. The promise evaluate to itself until a call to force the evaluation has been made. When the promise has been forced, the evaluation result is stored. Further call to force will produce the same result.

delay "form"
trans y 3 const l ((lambda (x) (+ x y)) 1) assert 4 (force l) trans y 0 assert 4 (force l)
do

The `do` special form is used to build loop with forward condition. The loop construct accepts either 2 or 3 arguments. With 2 argument, the first argument is the loop body and the second argument is the loop condition which must evaluates to a boolean object. With 3 arguments, the first argument is the initial condition that is executed only once.

do "body" "condition" do "initial" "body" "condition"
const number-of-digits (s) { const len (s:length) trans index 0 trans count 0 do { trans c (s:get index) if (c:digit-p) (count:++) } (< (index:++) len) eval count }
enum

The `enum` special form creates an enumeration from a list of literal. The result object is an `Enum` object that holds the enumerated items. An item evaluation results with an `Item` object that is bound to the enumeration object.

enum "literal" ...
const e (enum E1 E2 E3)
errorln

The `errorln` special form prints on the interpreter error stream a set of arguments. Each arguments have to be a literal which are converted to a string. When all arguments have been printed a new line character is printed. The `error` special form behaves like `errorln` excepts that a new line character is not printed at the end of the arguments.

errorln errorln "nil" errorln "literal list"
errorln errorln "hello millennium" ' ' 2000
eval

The `eval` special form simply evaluates the object argument. The form is useful when returning an argument from a lambda or gamma expression using an implicit form.

eval "object"
const ret (x) (eval x) eval (protect (+ 1 2))
for

The `for` special form provides a facility to iterate on iterable objects. The `Cons`, `List` and `Vector` objects are typical iterable objects. For each iterable objects, a symbol is set after each iteration. Each object symbol value can be used for further computation. The iteration stops when one of the objects iterator is at the end position.

for "symbol list" "iterable object list" "body"
# compute the scalar product of two vectors const scalar-product (u v) { trans result 0 for (x y) (u v) (result:+= (* x y)) eval result }
force

The `force` special form forces the evaluation of its argument. If the argument evaluates to a promise object, the promise evaluation is forced. If the argument is not a promise, `force` keyword behaves like `eval`. When a promise has been forced, further call to force will not change the evaluation result.

force "object"
trans y 3 const l ((lambda (x) (+ x y)) 1) assert 4 (force l) trans y 0 assert 4 (force l)
if

The `if` special form executes a form based on the evaluation of a boolean expression. In its first representation, `if` executes a form if the condition is evaluated to true. An alternate form can be specified and is executed if the boolean expression evaluates to false. It is an error to use a conditional form which does not evaluate to a boolean object.

if "condition" "true form" if "condition" "true form" "else form"
const max (x y) (if (> x y) x y)
lambda

The `lambda` special form creates a new closure object with eventually a set of arguments and a set of closed variables. In its first form, the closure is declared with a set of arguments or nil to indicate no argument. In its second form, the closure is declared with a set of arguments and a set of closed variables. The closed variables are evaluated at the construction of the closure and become part of the closure object. When the closure is called, a new nameset is created and linked with the parent nameset. The set of calling arguments are bounded in that nameset with the formal argument list to become the actual arguments. The set of closed variables is linked at runtime to the closure nameset. A lambda or gamma expression can have its argument declared as `const` argument.

lambda "nil" "body" lambda "argument list" "body" lambda "argument list" "closed variables list" "body"
const no-args (lambda nil (+ 1 1)) const add (lambda ((const x) (const y)) (+ x y)) const closed (lambda (x) (y) (+ x y))
launch

The `launch` special form creates a new thread by executing the form argument in a normal thread. The created thread is added in the normal thread list by creating a clone of the interpreter and starting immediately the execution of the form with the cloned interpreter. The command returns the thread object in the calling thread. When the thread terminates, the thread object holds the result of the last executed form. The main thread is suspended until all normal threads have completed their execution.

launch "form" launch "thread" "form"
launch (println "hello world")
loop

The `loop` special form executes a loop based on an initial condition, an exit condition and a step form. The initial condition is only executed one time. The exit condition is tested at each loop iteration. The `loop` special form creates its own nameset since the initial condition generally binds symbol locally for the loop.

loop "init form" "exit form" "step" "form"
loop (trans i 0) (< i 10) (i:++) (println i)
nameset

The `nameset` special form creates a new nameset. With no argument, a new nameset is created and no parent is binded to this nameset. With one argument, the argument must evaluate to a nameset and that nameset is used as the parent one. If a nameset has to be created with the global nameset as the parent, the symbol `...` can be used to reference the top level nameset. The symbol `.` references the current nameset. The symbol `..` references the parent nameset of the current nameset.

nameset nameset "parent nameset"
const local-nameset-not-bound (nameset) const local-nameset-bounded (nameset ...) const ...:global-nameset (nameset)
println

The `println` special form prints on the interpreter output stream a set of arguments. Each arguments have to be a literal which is converted to a string. When all arguments have been printed a new line character is printed. The `print` special form behaves like `println` excepts that a new line character is not printed at the end of the arguments.

println println "nil" println "literal list"
println println "hello millennium" ' ' 2000
protect

The `protect` special form take a single argument and returns it without evaluation. Protect is mainly use to get a symbol or form object.

protect "object"
const cons (protect (+ 1 2))
return

The `return` special form causes the current expression to stop its evaluation and returns the argument or nil. The `return` keyword is primarily used in lambda or gamma expressions. If used in a top level block, the block execution is stopped and the control is transferred to the top level.

return "object"
return (+ 1 2)
sync

The `sync` special form is a form synchronizer. Within a multi-threaded environment, the engine guarantees that only one thread will execute the form. The other threads are suspended until the form has been completed.

sync "form"
const print-message (code mesg) ( sync { errorln "error : " code errorln "message: " mesg } )
switch

The `switch` special form is a form selector. The first argument is the object to switch. The second argument is a list of forms with an object matcher and an execution form. The `else` special form can be used as default matcher.

switch "selector" "list of conditions"
const get-primary-color (color value) ( switch color ( ("red" (return (value:substr 0 2)) ("green" (return (value:substr 2 4)) ("blue" (return (value:substr 4 6)) ) )
throw

The `throw` special form throws an exception. Without argument, an exception of type user-exception is thrown. With one argument, the exception id is set. With two arguments, the exception id and exception reason are set. With three arguments, the exception id, exception reason and exception object are set. An exception object represented by the symbol `what` can also be thrown. This is the method used to re-throw an exception.

throw throw what throw "id" throw "id" "reason" throw "id" "reason" "object"
throw throw "type-error" throw "type-error" "invalid argument"
trans

The `trans` special form creates or sets a symbol with an object. `trans` searches in the current nameset only. If a symbol is found, it is set with the object. If the symbol is not found, it is created in the current nameset. The `trans` keyword can also be used with qualified names. With 3 or 4 arguments, `trans` creates automatically a lambda expression.

trans symbol "object" trans symbol "argument" "body" trans symbol "argument" "closed variables" "body"
trans a 1 trans fact (n) (if (< n 1) 1 (* n (fact (- n 1))))
try

The `try` special form catch an exception in the current execution nameset. The first argument is a form to execute. The optional second argument is the exception handler to be called in case of exception. If there is no exception handler, all exceptions are caught. The result of execution is either the result of the form execution, or the exception object in case of exception, or nil if the exception is a native one. If there is an exception handler, the handler is executed with a new nameset and the special symbol `what` is bound to the exception. If the exception is nil, the symbol `what` is undefined.

try "form" try "form" " exception handler"
try (+ 1 2) try (throw) try (throw "hello") try (throw "hello" "world") try (throw "hello" "world" "folks")
unref

The `unref` special form unreference a symbol.

unref symbol
const number 123 unref number
while

The `while` special form is used to build loop with backward condition. The loop construct accepts either 2 or 3 arguments. With 2 argument, the first argument is the loop condition and the second argument is the loop body that must evaluate to a boolean. With 3 arguments, the first argument is the initial condition that is executed only once.

while "condition" "body" while "initial" "condition" "body"
const gcd (u v) { while (!= v 0) { trans r (u:mod v) u:= v v:= r } eval u }