These are the built-in functions and macros defined by the sic
programming language.
This document was generated on Sat Jun 22 17:51:53 2019.
(abs arg1)
Return the absolute value of the (numeric) argument.
(add arg1 arg2 ...)
Addition. Accepts 2 or more arguments and returns the sum
(and expr1 expr2 ....)
Macro
Short-circuited boolean 'and'. Evaluates arguments until one is nil; returns the result of the last argument evaluated.
The actual work is done by and-eval; this just quotes the arguments.
(and-eval '(expr1 expr2 ...))
Evaluate expressions left to right until one evaluates to false. Returns the result of the last expression evaluated.
(ceil arg1)
Round up
(cond ( (cond-expr) (val-expr) ) ( (cond-expr-2) ) ... )
Macro
Classic Lisp conditional evaluation (more or less).
Takes a series of (usually) two-item lists of expressions and for each list evaluates the first expression. If the result is true, it evaluates the second expression and returns its result. Otherwise, it proceeds to the next list.
If all test expressions return nil
, the result of the cond
expression is also nil.
If a condition list contains only one item and its first
(i.e. only) expression evaluates true, that is also the result of
the whole cond
expression.
The heavy lifting for this is done by cond-eval
.
(cond-eval '( ( (cond-expr) (val-expr) ) ( (cond-expr-2) ) ... ) )
Back-end for the cond
and or
macros.
Evaluates each cond-expr until one returns true, then evaluates and returns the result of the corresponding val-expr. If 'val-expr' is omitted, returns the result of the cond-expr instead.
(defmacro foo (a1 a2 a3) ... )
Macro
Defines a macro and points a global at it.
Note that macro support in sic
is still primitive. In
particular, sic
currently does not have a way to define variadic
functions in sic
itself. This means that most effective macros
are written in C++.
(defun foo (a1 a2 a3) ... )
Macro
Defines a function (i.e. a fun
) and points a global at it.
(div arg1 arg2)
Division
(each function list)
Evaluate function over each item in the list, discarding the result(s).
(eq? arg1 arg2)
Compare arguments for equality, as defined by the various types:
String -- An identical sequence of characters Number -- Numerical equality Pair and List -- All elements are equal All others: -- Pointer equality (i.e. they're the same obj)
Objects must have the same type to be identical.
(eval '(+ 2 2))
Evaluate the argument as an expression
(first list)
Returns the first item in a list.
(floor arg1)
Round down
(fold fn initial list)
Evaluate fn on each item in list, calling it two arguments: the result of previous fn call and the current item. For the first item, the first argument for 'fn' is 'initial'.
(fun (arg1 arg2 ...) body-statements)
Macro
Defines and returns a fun
(i.e. a function that will always
execute in the global scope) with the given arguments and body.
Most of the time, you will want to call defun
or lamba
instead.
The result is unnamed unless you explicitly assign it to a variable
and it does not have access to current local variables the way
lambda does.
Expands to a call to make-function
.
(ge arg1 arg2)
Tests if the first argument is greater than or equal to the second. Arguments must be numbers.
(gt arg1 arg2)
Tests if the first argument is greater than the second. Arguments must be numbers.
(if (condition) (true-expr) (optional-false-expr) )
Macro
Macro implementing the 'if' control structure. Expands to a
cond-eval
expression.
(lambda (arg1 arg2 ...) body-statements)
Macro
Defines and returns a lambda (i.e. a function that captures the local scope) with the given arguments and body.
Expands to a call to make-function
.
(le arg1 arg2)
Tests if the first argument is less than or equal to the second. Arguments must be numbers.
(let ((a value) b (c value) (d)) ... )
Macro
Creates a local scope and defines zero or more local variables in, then evaluates the remaining lists as expressions in this context.
Variable definitions may be either symbols or two-item lists containing the symbol and an expression. In the latter case, the expression is evaluated and the result is stored in the variable. Otherwise, the variable is initialized to nil.
One-item lists containing just the name are also allowed; they are equivalent to the bare symbol.
(let-eval '((a value) b (c value) (d)) '(expr1 expr2 ...) )
Evaluates a let
operation. First list defines the locals, the
second list is eval'd in their context.
Back-end function for the let
macro.
(list ...)
Return a list containing the values of each of the arguments in the
order they were given. This is different from '(a b c)
in that
the arguments will have been evaluated.
(llen arg1)
Return the length of the given list or zero if the argument is not a list.
(lt arg1 arg2)
Tests if the first argument is less than the second. Arguments must be numbers.
(macro (arg1 arg2 ...) body-statements)
Macro
Defines and returns a macro (i.e. a function that takes zero or more unevaluated arguments and returns a new expression that is then evaluated by the system (typically a modified form of the given arguments, but that is not required.)
You will almost certainly want to use defmacro
instead of this.
Expands to a call to make-function
.
(make-function formals body lambda? macro?)
If 'lambda?' is true, it evaluates in the defining function's scope instead of the toplevel scope.
(map function list)
Evaluate function over each item of the list and return a list of the results.
(mod arg1 arg2)
Modulo
(mul arg1 arg2)
Multiplication
(ne? arg1 arg2)
Compare items for inequalty. True if and only if eq?
would
return false on these arguments.
(not arg1)
Boolean inversion. Returns nil
if the argument is true and t
if the argument is false.
(nth a-list 4)
Return the nth index of a list; zero-based.
(or expr1 expr2 ...)
Macro
Short-circuited boolean or
operation. Evaluate arguments until
one is true, returning its value. Remaining arguments are not
evaluated. Returns nil if no true result is found.
Expands to a cond
expression (e.g. (cond-expr '( (expr1) (expr2) ...) )
)
(pair arg1 arg2)
Create a pair object holding the two arguments.
(print ...)
Print each argument's string representation to stdout.
(progn ...)
Return the value of the last argument, or nil if there is none. This is used to evaluate a sequence of expressions; it's basically 'let' without local variables.
(quote x)
Returns x unevaluated. This is treated as a special case by
eval
, which evaluates calls to this function itself and prevents
the argument from being evaluated. (Note: NOT functions with
this name; this specific function. Assigning it to a new variable
will not defeat this, nor will creating a local function named
quote
.)
If you somehow manage to trick eval
into calling this function,
it will simply return its argument.
(rest list)
Returns a list without its first item.
(round arg1)
Round toward nearest integral value
(second arg1)
Returns the second item in a list or nil if there is none.
(set symbol value)
(setq sym value)
Macro
Assignment macro. Expands to set
with sym
quoted.
(str-to-num arg1)
Given a string, attempt to parse it as a decimal number and return the value as a Sic number. Returns nil if this doesn't work.
(sub arg1 arg2)
Subtraction.
(third arg1)
Returns the third item in a list or nil if there is none.
(tl-set global-symbol value)
Like set
but always only modifies the global namespace. Creates
the variable if it doesn't exist.
(trunc arg1)
Truncate toward zero
(while (condition) (expr1) ... )
Macro
Basic while
loop.
Evaluates the first expression and, if true, evaluates the remaining expressions in order. Repeats this until the first expression evaluates to false.