Skip to content

Function Reference

Silvio Mayolo edited this page Jun 7, 2017 · 34 revisions

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.

Special Operators

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 / q

(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)).

Arithmetic

p

(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

(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 Operations

list / l

(list exprs ...)

All of the expressions given are put into a list, which is returned.

Control Flow

progn / pgn

(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).

Input / Output

puts / pu

(puts exprs ...)

Outputs each expression to stdout on a separate line. This function always returns ().

Miscellaneous

cond / i

==

sequence / sq

take / tk / car

drop / dp / cdr

apply / ap

map / a

filter / e

less-than / c,

less-eq / =,

greater-than / c;

greater-eq / =;

str-less-than / ,c

str-less-eq / ,=

str-greater-than / ;c

str-greater-eq / ;=

range / rg

quit

cons / c

bitand / b&

bitor / b;

bitxor / b%

boolnorm / bn

hook / hk

id / d

compose / ,

sort / st

divides / //

foldl / fl

foldr / fr

join / jn

mod / md

even / ev

odd / od

strings / s

prime / pm

up

mo

po

mt

pt

split / sp

inter / ps

insert / it

remove / rm

nth / nh

read / rd

eval / el

two-curry / tc

seq-while / sw

print-greek / pgk

each-char / ec

string-replace / sr

o

w

t

n

uc

ucx

lc

lcx

Clone this wiki locally