1,-1- integer number value1.0,-1.0,1.,.0- fractional number value"something"- string literal valuesomething- symbol value#n,#nil,#null- nil value#t,#truetrue value#f,#false- false value(a . b)- pair ofaandb(a b)- list ofa,bandnil(a b . c)- list ofa,bandc'(a b . c)- evaluates to whatever comes after'
Functions can be:
- builtin - built into language functions, all arguments evaluated
- special form - built into language construction that do not evaluate arguments at call, but follow inner conditions
(fn a b)calls functionfnwith paramseval aandeval b
Returns first argument unevaluated.
(quote <form>) => <form>
Evaluates forms in order and returns last result.
(begin ...<form>) => eval last <form>
Creates a closure that captures current environment.
Forms evaluated in order and last result is returned.
(lambda <name>? <arguments-names-list> ...<form>) = eval last <form>
Name is for debug purposes only
Binds value to a name in the current environment.
(define <name> <form>) >= #nil
Can contain shorthand version of lambda definition:
(define (<name> <arguments-names-list>) ...<form>) >= #nil
Mutate an existing binding or creates new one in current environment.
(set <name> <form>) >= #nil
Checks if environment has binding.
(is-set? <name>) >= #t|#f
Get an existing binding or return nil.
(get <name>) >= #nil
Create new variable bindings in parallel on new environment and execute a series of forms in that environment.
(let (...(<name> <form>)) ...<fors>) >= #nil
Evaluates left to right, returns first falsy or last value. Short-circuits.
(and ...<form>) => first falsy | last value
Evaluates left to right, returns first truthy or last value. Short-circuits.
(or ...<form>) => first truthy | last value
(if <condition> <then> <else>) => eval(<then>) | eval(<else>) | #nil
(cond ...(<condition> ...<form>) (else ...<form>)) => first matching result | #nil
Create value of type throw that is should trigger early return of said value after any evaluation.
It carries first argument (as reason) and evaluation stack reference.
(throw <form>)
Special form for intercepting throw values and ensuring cleanup logic is executed.
(try <body> ...[(catch (<symbol>)? ...<forms>)|(finally ...<forms>)])
Special form to trigger an immediate exit from the current function, carrying a value.
(return <form>)
Execute a series of forms in specified environment.
($<environment> ...<forms>)
Creates object with of named fields.
(object ...:<symbol>,<form>)
Takes exactly 2 arguments and returns a pair (left . right).
(cons <left> <right>) => (<left> . <right>)
Evaluates each argument and constructs a new list containing the results.
(list ...<form>) => (...<eval<form>>)
Returns the left / right element of a pair.
(car <pair>) => <left>
(cdr <pair>) => <right>
Calls a function with supplied arguments, all arguments are concatinated into one list.
(apply <fn> ...<arguments>) => result
Applies a function to each element of a list and returns a new list of results.
(map <fn> <list>) => <list>
Sequentially applies all arguments. Integers promoted to fractional if any argument is fractional.
(+) => 0
(+ ...<number>) => sum
(- <number> ...<number>) => difference
(*) => 1
(* ...<number>) => product
(/ <number> ...<number>) => quotient
Applies structural check between each consequence pairs.
(= <value> ...<value>) => true if all equal
<value> can be any of this:
boolnumberstringpair- compares both sides recursivelyfn- compared by referencesymbol- compared by reference
Examples:
(= #t #t) => true
(= 1 1) => true
(= 1 1.0) => true
(= "a" "a") => true
(= '(1 2) '(1 2)) => true
(= ''1 ''1) => true
(= if if) => true
(= (lambda (a) a) (lambda (a) a)) => false
(= 'a 'a) => true
(define a 1) (define b 1) (= a b) => false
Applies operators between each consequence pairs.
(< <value> ...<value>) => true if strictly increasing
(> <value> ...<value>) => true if strictly decreasing
(<= <value> ...<value>) => true if non-decreasing
(>= <value> ...<value>) => true if non-increasing
<value> can be any of this:
numberstringpair- compares both sides recursively
Applies identity check between each consequence pairs.
(eq? <form> ...<form>) => true if all equal
Examples:
(eq? #t #t) => true
(eq? #t #f) => false
(eq? 1 1) => true
(eq? 1 1.0) => false
(eq? "a" "a") => false
(eq? '(1 2) '(1 2)) => false
(define a '(1 2)) (eq? a a) => true
(eq? ''1 ''1) => false
(define a ''1) (eq? a a) => true
(eq? if if) => true
(eq? (lambda (a) a) (lambda (a) a)) => false
(define b (lambda (a) a)) (eq? b b) => true
(eq? 'a 'a) => true
(define a 1) (define b 1) (eq? a b) => false
nil?, symbol?, pair?, list?, bool?, number?, integer?, fractional?, boxed?, string?, procedure?, special-form?, builtin?, closure?
Type checks first argument.
(<type>? <form>) => bool
boxed? check can also test if value instance of some known type
(boxed? <typename> <form>)
Returns false if argument is truthy, true if falsy.
(not <form>) => true | false
Boxed values provide a mechanism for custom data types with dedicated constructors, accessors, and memory management:
(new <constructor> ...<form>) => <boxed> - will instantiate boxed value using constructor with arguments
#.<constructor>(...<form>) => <boxed> - will instantiate boxed value using constructor with arguments
(<boxed> ...<field-identifier>) - create nested boxed value by traversing a series of field identifiers on an object
(set <boxed> <form>) - set value to boxed value
(set ,(<boxed> ...<field-identifier>) <form>) - set value to nested boxed value
((<boxed> ...<field-identifier>) ...<form>) - call boxed value with arguments
Where field-identifier can be number or symbol:
(<boxed> 1 symbol 2)
field-identifier is not evaluated by default, but it creates quasiquoted environment and evaluates ,<value>.
(<boxed> unref) - try to unref referrence boxed value
(<boxed> unbox) - try to unbox boxed value to native data type
Shortcut to create vector instance is
#(...<form>) => <vector>
Vector implements indexed access with signed index overflow and boundaries check
(<vector> 0) => <first form>
(<vector> -1) => <last form>
(#(1 2 3) 4) => <throw: out of bound>
Fields and methods:
(<vector> count) => <number of elements>
:stdout | :stderr | :stdin | <fd-id>
Print arguments to file.
(print '<FD>? ...<argument>) => #nil
Flash file descriptor.
(print-flash '<FD>?) => #nil
Print arguments to file and newline.
(println '<FD>? ...<argument>) => #nil
Print arguments to file.
(print '<FD>? <format-string> ...<argument>) => #nil