-
Notifications
You must be signed in to change notification settings - Fork 0
Function Reference
All of the possible methods of calling a function are listed here. If a method is not listed, it should be considered undefined behavior. For instance, passing no arguments to the =
operator is undefined behavior.
For all functions except those under the "Special Operators" section, it is assumed that the standard applicative evaluation order of arguments is applied. That is, after the function itself is evaluated, each argument is evaluated in order, first to last, before being passed in to the function.
Important: Special operators are NOT functions. They do not follow the normal evaluation rules. If a special operator is ever treated as a value, the consequences are undefined.
(= y)
The value y
is evaluated and assigned to the variable %
.
(= x y)
The value y
is evaluated and assigned to the variable indicated by x
, which is not evaluated. If x
is not an atom, y
is evaluated and discarded.
(= xs ... y)
The value y
is evaluated once and assigned to all of the variables given. Any non-atom variables are ignored.
(quote expr)
The expression is returned, unevaluated. The quote
operator has two forms of syntax sugar attributed to it. Like in most Lisps, a single quote preceding an expression like 'expr
is equivalent to (quote expr)
. Additionally, in ShinyLisp, square brackets will quote the operand, so [foo bar baz]
is equivalent to (quote (foo bar baz))
.
(p xs ...)
All of the expressions are coerced into numbers and summed together. If no expressions are provided, 0
is returned. Note that p
(short for "plus") is used for addition. The usual symbol +
is a capital =
, which is used for assignment.
(m)
The m
function with no arguments returns the value -1
.
(m x)
The value x
is coerced to a number and negated. So -x
, the additive inverse of x
, is returned.
(m x ys ...)
All of the arguments are coerced to numbers, then each of ys
is subtracted from x
. Note that m
(short for "minus") is used for subtraction to parallel the use of p
for addition.
(& xs ...)
The arguments are coerced together and their product is returned. If no arguments are supplied, 1
is returned. Note that &
is the lowercase form of *
, which is used in most languages for multiplication.
(/ x)
Currently, passing zero or one argument to /
is undefined behavior, as the language does not yet support floating point values. Eventually, passing a single argument to /
will yield the reciprocal. Do not yet rely on this behavior.
(/ x ys ...)
All of the arguments are coerced to numbers. Then each of ys
is divided in turn by x
, yielding the final value. If any of the divisors is equal to zero, the dividend x
is returned. Currently, division truncates toward negative infinity, but floating point numbers may be supported in the future.
(list exprs ...)
All of the expressions given are put into a list, which is returned.
(progn exprs ...)
The value of the last expression is returned. If progn
is called with no arguments, it returns ()
. This function is useful for concisely sequencing multiple expressions together. Note that curly braces act as syntax sugar for progn
, so {foo bar baz}
is equivalent to (progn foo bar baz)
.
(puts exprs ...)
Outputs each expression to stdout on a separate line. This function always returns ()
.