Skip to content

Function Reference

Silvio Mayolo edited this page Dec 6, 2019 · 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.

Note also that many functions have "default" return values if they are called with no arguments. A function with a string or integer default return value will also return that value if coerced to a number or a string, respectively. Any other function will return 0 or "" if coerced.

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

cond / i

(cond args ...)

cond is the general form of an if-statement. The operator considers its arguments in pairs. The first of each pair is evaluated. If it returns a truthy value, the second of the pair is evaluated and returned. Otherwise, the next pair is considered. If there are an odd number of arguments, the final argument is considered an "else" clause and is returned if none of the conditions match. If there is no "else" clause and no conditions match, the value () is returned.

Programmers from other languages should think of cond as an if-else-if statement. For example, the expression (cond c1 e1 c2 e2 default) is equivalent to if c1 then e1 elsif c2 then e2 else default end in Ruby.

-

(- forms ...)

For each line of input to STDIN, the variable % will be bound to the line, then forms will be executed in order, then % will be printed to the screen. If % did not exist before this block was entered, it will be unbound when the block is exited. The - block is designed to behave similarly to Perl's while (<>) {} block. The final value of the final iteration is returned. This loop respects the loop contiue value &&l and will return the final value iterated if exited abnormally.

loop / -&

(loop arg forms ...)

Interprets arg as a sequence, which takes one argument. For each element in the (infinite) sequence, evaluates forms with % bound to the element. This loop respects the loop continue value &&l and will return nil if exited.

define / ,-

(define)

Binds the variable % to the local function scope. If % was already bound in an outer scope, its value is inherited. The value of % is returned.

(define x ... y)

Binds each variable in the local function scope, inheriting values where possible. No arguments are evaluated. The value of the variable referenced by the final argument is returned. Non-symbol arguments are ignored. Mnemonic: , is lowercase <, so define's abbreviation looks like <-.

undefine / -,

(undefine)

Unbinds % if it exists. If it does not, this operator is a no-op. Returns (). Unbinding % can be handy inside of a - form, if it makes sense not to print one or more of the lines, for - will not print if the variable % does not exist.

(undefine x ... y)

Unbinds each variable. Arguments are not evaluated. Any argument which references a variable that does not exist or which is not an atom is ignored. Returns (). Mnemonic: -, does the opposite of the bind operator ,- and is that operator backwards.

Global Values

Important: These are values, not functions. Thus, it is not necessary to wrap them in parentheses.

o

o

The value 1.

w

w

The value 2.

t

t

The value 10.

n

n

The value (). In numerical context, () coerces to 0, so this can also be a useful way to get the numerical value 0.

#,

#,

The value " " by default. This variable can be altered and will be used as a list delimiter when puts needs to output a list.

#,,

#,,

The value " . " by default. This variable can be altered and will be used as a list delimiter when puts needs to output a dotted list.

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.

divides / //

(divides)

Returns the constant -100

(divides x)

Returns whether x is a power of 10.

(divides x y)

Returns whether x divides evenly into y. If x is zero, then the result is false.

(divides x y ...)

Returns whether each argument divides evenly into the subsequent argument. If any divisor is zero, the result is false.

mod / md

(mod)

Returns the value 500.

(mod x)

Returns the value of x modulo 10. The result is always positive.

(mod x y)

Returns the value of x modulo y. The sign of the result will always equal the sign of the divisor. If y is zero then the result is x.

even / ev

(even)

Returns 64.

(even x)

Returns whether x is an even number.

(even x ...)

Returns a list of Booleans indicating whether each argument is even.

odd / od

(even)

Returns 32.

(even x)

Returns whether x is an odd number.

(even x ...)

Returns a list of Booleans indicating whether each argument is odd.

prime / pm

(prime)

Returns 128.

(prime x)

Returns true if and only if x is a prime number. This function uses the ring-theoretic definition of prime numbers, so a negative number is prime if and only if its absolute value is.

(prime x ...)

Returns a list of Booleans indicating whether each argument is prime.

up

(up)

Returns 9,999.

(up x)

Returns x squared.

(up x y)

Returns x to the power of abs(y).

(up x y ... z)

Performs exponentiation right-associatively.

mo

(mo)

Returns % minus one.

(mo x)

Returns x minus one.

(mo x ... y)

Returns x minus each subsequent argument minus one, so that (mo x y z) is equivalent to (m x y z 1).

po

(po)

Returns % plus one.

(po x)

Returns x plus one.

(po x ... y)

Returns x plus each subsequent argument plus one, so that (po x y z) is equivalent to (p x y z 1).

mt

(mt)

Returns % minus two.

(mt x)

Returns x minus two.

(mt x ... y)

Returns x minus each subsequent argument minus two, so that (mt x y z) is equivalent to (m x y z 2).

pt

(pt)

Returns % plus two.

(pt x)

Returns x plus two.

(pt x ... y)

Returns x plus each subsequent argument plus two, so that (pt x y z) is equivalent to (p x y z 2).

sum-digits / sd

(sum-digits x)

Coerces x to a number and sums the digits of x.

(sum-digits x ... y)

Coerces each argument to a number, sums all of the digits, and returns the total sum.

prime-factors / pf

(prime-factors n)

Coerces n to a number and returns a list of the unique prime factors of n. If n is negative, the prime factors of its absolute value will be given. If n is 0, 1, or -1, () will be returned.

prime-factorize / pz

(prime-factorize n)

Coerces n to a number and returns a list of the prime factors of n. If n is negative, the prime factors of its absolute value will be given. If n is 0, 1, or -1, () will be returned. The resulting list is such that, assuming n is a positive integer greater than 1, the product of elements in the list will produce the original element n.

next-prime / px

(next-prime)

Returns the smallest prime number that is strictly greater than %.

(next-prime x)

Returns the smallest prime number that is strictly greater than x.

(next-prime x n)

Returns the nth prime after x. If n is 1 then this is equivalent to (next-prime x). If n is 0 then (next-prime x 0) is the next prime greater than or equal to x. If n is negative, then the expression evaluates to the nth prime before x. Note that, like with the prime function, this function uses the ring-theoretic definition of prime numbers, so numbers like -2, -3, and -5 are prime as well as the "usual" prime numbers.

(next-prime x n ... m)

Returns the nth prime relative to x for each index provided.

Boolean Operators

bitand / b&

(bitand)

Returns -1, whose two's complement representation is the identity value of bitand.

(bitand x ...)

Returns the bitwise conjunction of all of the arguments, coerced to numbers.

bitor / b;

(bitor)

Returns 0, whose two's complement representation is the identity value of bitor.

(bitor x ...)

Returns the bitwise disjunction of all of the arguments, coerced to numbers.

bitxor / b%

(bitxor)

Returns 256.

(bitxor x)

Coerces x to a number and returns its complement. That is, returns x with all bits flipped.

(bitxor x ...)

Performs bitwise exclusive-or to join the values, all coerced to numbers, together.

boolnorm / bn

(boolnorm)

Returns 999.

(boolnorm x)

Normalizes the value, returning 0 if x is falsy and 1 if x is truthy.

(boolnorm x ...)

Boolean normalizes each value, returning a list of zeros and ones.

String Operations

strings / s

(strings)

Returns the empty string "". The abbreviation for this function is s, and in some cases a well-placed S is a shorter way to yield the empty string than the two-character "".

(strings x ...)

Coerces each argument to a string and concatenates them.

split / sp

(split)

Returns the string "0123456789".

(split x)

Splits the string x into a list, delimited by spaces.

(split x d)

Splits the string x into a list, delimited by the string d. If d coerces to the empty string, then splits x into individual characters.

(split x ... z d)

Splits each string into lists using the given delimiter and then flattens the resulting list.

inter / ps

(inter)

Returns ")!@#$%^&*("

(inter xs)

Intercalates the list into a single string, delimited by spaces.

(inter xs d)

Intercalates the list into a single string, separating elements with d.

(inter xs ... ys d)

Flattens the argument list and then intercalates, using the delimiter d.

read / rd

(read)

Returns ().

(read x)

Reads x as a ShinyLisp expression. Returns the expression if successful, and throws an error on failure. The expression is not evaluated.

(read x ... y)

Reads each expression and returns a list of the resulting expressions.

each-char / ec

(each-char s)

Performs ROT-13 on the string provided.

(each-char s x)

If x is a number, performs ROT-x on the string. Otherwise, coerces x to a function and executes it on each ASCII value in s, producing a new string from the results.

(each-char s f ... g)

Coerces all except the first argument into functions and applies the functions, cyclically, to s. So if two functions are supplied then the first will be applied to every other character, starting with the first, and the second will be applied to every other character, starting with the second.

string-replace / sr

(string-replace s)

Removes all characters which are not alphanumeric or underscore from the string s.

(string-replace s x)

Removes all instances of the string x from the string s.

(string-replace s x y)

Replaces all occurrences of the string x with the string y in s. Alternatively, y can be a 0-ary function which will be called for each occurrence of x to get the replacement text.

match-count / mc

(match-count r)

Counts the number of (non-overlapping) times the regular expression r matches in the string %. If the regular expression does not match or is not formatted correctly, 0 is returned.

(match-count r s ...)

Counts the number of (non-overlapping) times the regular expression r matches in any of the strings provided, returning the total sum of times.

match / mr

(match r)

Returns whether r matches the string in %. If r successfully matches, then the regular expression variables are bound to the appropriate match values from the first match.

(match r s ...)

Returns whether r matches any of the strings. If r successfully matches, then the regular expression variables are bound to the appropriate match values from the first match.

replace / =r

(replace r)

Removes all instances of the regular expression r in %, returning a new string. The regular expression variables are bound in the caller's scope to the last match.

(replace r s)

Replaces all instances of r in % with s. The value s should either be a string or a function returning a string. If it is a function, it will be called with zero arguments but with the regular expression variables bound. In either case, any backslash sequences of the form \& in the resulting string are replaced with the matched text, and any backslash sequences of the form \n are replaced with the nth capture group (1-indexed).

(replace t r s)

Replaces all instances of r in t with s. The value s should either be a string or a function returning a string. If it is a function, it will be called with zero arguments but with the regular expression variables bound. In either case, any backslash sequences of the form \& in the resulting string are replaced with the matched text, and any backslash sequences of the form \n are replaced with the nth capture group (1-indexed).

uc

(uc)

Converts % to uppercase, using standard casing rules, not ShinyLisp casing rules.

(uc x)

Converts x to uppercase, using standard casing rules, not ShinyLisp casing rules.

(uc x ...)

Converts each argument to uppercase, using standard casing rules, not ShinyLisp casing rules.

ucx

(ucx)

Converts % to uppercase, using ShinyLisp casing rules.

(ucx x)

Converts x to uppercase, using ShinyLisp casing rules.

(ucx x ...)

Converts each argument to uppercase, using ShinyLisp casing rules.

lc

(lc)

Converts % to lowercase, using standard casing rules, not ShinyLisp casing rules.

(lc x)

Converts x to lowercase, using standard casing rules, not ShinyLisp casing rules.

(lc x ...)

Converts each argument to lowercase, using standard casing rules, not ShinyLisp casing rules.

lcx

(lcx)

Converts % to lowercase, using ShinyLisp casing rules.

(lcx x)

Converts x to lowercase, using ShinyLisp casing rules.

(lcx x ...)

Converts each argument to lowercase, using ShinyLisp casing rules.

Lists and Sequences

list / l

(list exprs ...)

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

take / tk / car

(take)

Returns 10,000

(take xs)

If xs is a cons cell, its car is returned. Otherwise, xs itself is returned. On a proper list, this has the effect of returning the first element.

(take n xs)

Returns the first n elements of the list xs. The value n is coerced to a number. If n is zero, then () is returned. If xs is not a list then xs is returned. If xs is not long enough to support the operation, the entire list is once again returned.

(take n m ... xs)

Returns a list of results, containing the first n elements of the list, followed by the next m, and so on. Like with the other forms of take, if repeated application ever yields a non-cons value, including (), the value itself is returned.

drop / dp / cdr

(drop)

Returns the value 2,048

(drop xs)

Returns the cdr of xs if xs is a cons cell, or returns xs itself otherwise. On a proper list, this has the effect of dropping the first element.

(drop n xs)

After coercing n to a number, returns the list xs with the first n elements dropped. If xs is not a cons cell, then xs itself is returned. If xs is too short, then the final cdr of xs is returned.

(drop n m ... xs)

Calling drop with three or more arguments is equivalent to calling it with each index separately. That is, (drop n m k xs) is equivalent to (list (drop n xs) (drop m xs) (drop k xs) with the caveat that the arguments are evaluated in standard applicative order and xs is only evaluated once total.

map / a

(map)

Returns the uppercase alphabet, as a string.

(map xs)

Coerces the argument to a list and reverses it.

(map f xs ...)

Zips the list arguments together, coercing as necessary, and then applies f to each argument list in the resulting zipped list. When any one of the arguments terminates, the zipped list terminates. A list of the results is returned.

filter / e

(filter)

Returns the lowercase alphabet, as a string.

(filter xs)

Returns the argument, coerced to a list, with all falsy elements removed.

(filter f xs)

Coerces the xs argument to a list and removes all elements of the list for which f returns falsy when called.

range / rg

(range)

Returns the constant 1337.

(range n)

Coerces n to a number and returns a list of integers from 1 to n, inclusive.

(range n m)

Coerces both arguments to numbers and returns a list of integers from n to m, inclusive. If n > m then the list will be decreasing; if n < m, then the list will be increasing; and if n = m, then the list will contain only one element.

(range n ...)

Coerces all arguments to numbers and returns a list of integers starting with the first argument, counting to the next, then the next, and so on until the final argument. For example, (range 4 6 3 1) returns the list (4 5 6 5 4 3 2 1).

cons / c

(cons)

Returns the value (() . ()). That is, a cons cell with () as both the car and the cdr.

(cons x)

Returns the value (x . x), except that x is evaluated only once.

(cons x ...)

Returns a dotted list containing all of the arguments with the cdr of the final cons cell being the last argument. So (cons 1 2 3) returns (1 2 . 3)

sort / st

(sort)

Returns the list containing integers from 1 to 10, inclusive.

(sort xs)

Sorts the list of elements, returning a new list.

(sort f xs)

Treating f as a binary less-than-or-equal-to comparator, sorts the list of elements and returns the sorted list. The comparator provided should not have any observable side effects.

(sort f x ...)

Collates the arguments into a list and sorts it using the given comparator. The comparator should not have any observable side effects.

foldl / fl

(foldl)

Returns 1,000,000.

(foldl xs)

Returns the sum of elements in the list.

(foldl f xs)

Performs the binary operation f on elements of the list to produce a result, associating to the left. If the list contains one element then f is not called and the element is returned. If the list is empty, then f is not called and () is returned.

(foldl f x ... y xs)

All of the middle arguments are combined together and prepended to the final argument xs. The resulting list is folded over, associating to the left, using the rules of the two-argument form of foldl.

foldr / fr

(foldr)

Returns -1,000,000.

(foldr xs)

Returns the product of elements in the list.

(foldr f xs)

Performs the binary operation f on elements of the list to produce a result, associating to the right. If the list contains one element then f is not called and the element is returned. If the list is empty, then f is not called and () is returned.

(foldr f x ... y xs)

All of the middle arguments are combined together and prepended to the final argument xs. The resulting list is folded over, associating to the right, using the rules of the two-argument form of foldr.

insert / it

(insert xs)

Returns a list identical to xs but with () inserted at the end.

(insert x xs)

Returns a list identical to xs but with x inserted at the end.

(insert n x xs)

Returns a list identical to xs but with x inserted at the nth position. If n is negative, inserts at the beginning. If n is greater than the length, inserts at the end.

(insert n x m ... z xs)

Calling insert with more than three argument recursively invokes (insert n x (insert m ... z xs)).

remove / rm

(remove xs)

Returns xs but with the last element removed. If there is no last element, xs is returned.

(remove n ... m k xs)

Removes the kth, then the mth, then ... the nth element of xs, returning the result of removal.

nth / nh

(nth xs)

Returns the last element of xs.

(nth n xs)

Returns the nth element of xs, where the value n is considered modulo the length of xs.

(nth n ... m xs)

Returns a list of elements from specific positions in the list. All indices are considered modulo the length of xs.

sequence / sq

(sequence)

If no arguments are passed to sequence, it returns (sequence 0).

(sequence n)

Returns a function representing a sequence. The returned function shall take one argument, an 0-based index K, and return the Kth element in the sequence. If N is not passed, it defaults to zero. Any further arguments to the returned function are evaluated but ignored. See below for a list of sequences available.

(sequence n y ys ...)

If any additional arguments are passed to sequence, they are evaluated but ignored. However, the behavior changes if at least two arguments are passed. A sequence function is still returned. However, in this case, when the returned function is called with index K, the first K elements of the sequence are returned in a list. If K is not supplied, it defaults to one. Any further arguments are evaluated but ignored. See below for a list of sequences available.

The following are the valid values for n. The value n is always coerced to a number. If a negative number is passed, a function representing the sequence of () infinitely repeated is returned. If an invalid positive number is passed, the behavior is undefined.

  • 0 - The Fibonacci sequence 0 1 1 2 3 5 8 13 ...
  • 1 - The 2^n sequence 1 2 4 8 16 32 64 128 ...
  • 2 - The identity sequence 0 1 2 3 4 5 6 7 ...
  • 3 - The prime numbers 2 3 5 7 11 13 17 19 ...

seq-while / sw

(seq-while seq)

Given a sequence seq, returns the first 100 elements.

(seq-while seq p)

Given a sequence seq, returns the longest prefix of seq for which the predicate p returns true. The return value will be a list.

(seq-while seq f ... g)

Returns the longest prefix for which all of the predicates return true.

count / ct

(count)

Returns an infinite sequence starting at 1 and counting upward by 1.

(count n)

Returns an infinite sequence starting at n and counting upward by 1.

(count n dn)

Returns an infinite sequence starting at n and counting upward by dn.

map-sequence / ms

(map-sequence f ss ...)

Given a function f and a some sequences ss, returns a new function. The new function takes any number of lists xs and zips ss and xs together to produce a finite list of argument lists. Each argument list is, in turn, passed to f. The resulting accumulated list made from the return values of f is returned.

Stack Manipulation

stack-push / vv

(stack-push)

Pushes the value of % onto the stack #v.

(stack-push x)

Pushes the value of x onto the stack #v.

(stack-push x ... y)

Pushes each argument onto the stack #v, with the first argument ending up on the top of the stack. Mnemonic: v looks like a down arrow, and we're pushing down onto the stack.

stack-pop / v%

(stack-pop)

Pops a value off the stack #v and returns it. If the stack is empty then () is returned.

(stack-pop n)

Pops the nth value off the stack #v, where 0 is the top element of the stack. n will wrap around if it is out of bounds. If the stack is empty then () is returned.

(stack-pop n ... m)

Pops each value off the stack #v sequentially, returning a list of the popped values. Note that this is done sequentially, so later indices in the argument list will be relative to the stack after popping the earlier indices off the stack. Mnemonic: % is lowercase of the caret ^, which looks like an up arrow, and we're popping up off the stack

stack-peek / v&

(stack-peek)

Returns the top element of #v without modifying it. Returns () if the stack is empty.

(stack-peek n)

Returns the nth element of #v without modifying it. The index wraps around, if needed. Returns () if the stack is empty.

(stack-peek n ... m)

Returns a list of results, looking up each index in the stack #v and wrapping as needed. Mnemonic: & is adjacent to ^ (for popping from the stack) on the keyboard.

stack-into / v-

(stack-into f)

Pops one value off the stack #v and calls f, passing that value as an argument. This behaves identically to (f (stack-pop)).

(stack-into n f)

Pops n values off the stack #v and calls f with them as arguments. The argument list will always contain exactly n elements and will be padded with () as needed. The top values of the stack will appear at the front of the argument list.

(stack-into n f x ...)

Pops n values off the stack #v and calls f with them as arguments. The latter arguments x ... will precede the stack elements in the f argument list. So if the stack contains (a b c), then the call (stack-into 2 f x y) will result in the call (f x y a b) and the stack will become (c).

stack-arrange / v!

(stack-arrange)

Swaps the top two elements of the stack #v, returning the old top element of the stack.

(stack-arrange n)

Buries the top element of the #v stack n elements down. This function does not wrap, so if n is greater than the length of the stack, the top element will be pushed down to the bottom of the stack. Returns the old top of the stack. Note that (stack-arrange 1) is a no-op, and (stack-arrange 2) is equivalent to (stack-arrange).

(stack-arrange n m)

Swaps the nth and mth elements of the stack #v, returning a list containing the nth and mth elements, in that order. This function's indices do wrap.

(stack-arrange n m ... k)

Rotates the stack elements at the specified indices. As an example, if the stack is (a b c d e f g) then the call (stack-arrange 2 4 6) will return (c e g) and will leave the stack with (a b g d c f e).

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

quit / qx

(quit)

Aborts the program immediately. This is mainly intended to be used as a convenient method of exiting the REPL. If run from within a script, this will abort the program and bypass the normal printing of the % variable that would occur.

reset

(reset)

Resets the interpreted environment, making the system act as though it was just started. The code then continues from the current execution point. In general, this function should only be called from the REPL to reset the current environment. It can be invoked from a script, but care should be taken to make sure no important variables are accidentally reset. If reset is called from within a function or any nontrivial scope, it will throw an error.

eval / el

(eval x)

Evaluates the given ShinyLisp expression, often the output of the read function. Returns the result of evaluation.

(eval x ... y)

Evaluates the arguments in order, returning the final result.

loop-out / l%

(loop-out)

Sets the loop continue value &&l to the logical negation of its current value. If the loop continue value does not exist, defines and sets the loop continue value to false.

Higher Order Functions

apply / ap

(apply)

Returns 2,147,483,647, the largest value that can fit into a 32-bit unsigned integer.

(apply f)

Applies the function f to itself. That is, (apply f) is equivalent to (f f) except that f is only evaluated once.

(apply f x y ... z xs)

Every argument from the second to the penultimate argument is collected into a list and prepended onto the final argument, which must be a proper list. Then f is called with the argument list that was created from the arguments.

id / d

(id)

Returns ().

(id x)

Returns x.

(id x ...)

Returns the first argument.

compose / ,

(compose)

Returns the identity function.

(compose f ...)

Composes the functions and returns the resulting composition. The final argument is given the exact argument list provided to the composed function. Each other function is given a single argument: the result of the prior function call. So ((compose f g h) x y) returns the value of (f (g (h x y))).

hook / hk

(hook)

Returns a function which reverses its argument list. So ((hook) x y z) returns the list (z y x), except that the arguments are evaluated in the standard order.

(hook f)

Returns a function which reverses the argument list and applies f to it. So ((hook f) x y z) returns the value of (f z y x), except that argument evaluation is done in the traditional order. The expression (hook) with zero arguments is equivalent to (hook list), assuming list has not been redefined.

(hook f g)

Returns a function which applies g to each argument, then applies f to the whole thing. So ((hook f g) x y z) returns the value of (f (g x) (g y) (g z)) with the caveat that g is evaluated only once.

(hook f g ...)

Returns a function which zips the g arguments with the argument list provided and then applies f to the result. So ((hook f g h k) x y z t) returns (f (g x) (h y) (k z)). The longer of the function list and the argument list is truncated, but all arguments are still evaluated exactly once.

join / jn

(join)

Returns a function which duplicates each of its arguments into a list. So ((join) x y z) results in the list (x x y y z z), except that each argument is evaluated only once.

(join f)

Returns a function which duplicates each of its arguments and applies the resulting list to the provided function. So ((join f) x y z) results in the value of (f x x y y z z), except that each argument is only evaluated once.

(join f x ... y)

Duplicates the arguments and applies the function f to all of them. So (join f x y z) results in the value of (f x x y y z z) except that each argument is evaluated only once.

two-curry / tc

(two-curry)

Returns 1,000.

(two-curry f)

Forces f to wait for two argument lists, concatenating them together. Thus, (((two-curry f) x y) z t) evaluates to (f x y z t).

(two-curry f x ... y)

Awaits another argument list before calling f. Thus, ((two-curry f x y) z t) evaluates to (f x y z t).

forward / ;;

(forward)

Captures the current argument list !! and returns a function which, given a list of functions, invokes each in order with the current argument list as arguments. So ((forward) f g h) is roughly equivalent to (progn (f args ...) (g args ...) (h args ...)), where args is a special variable containing the argument list at the time (forward) was invoked.

(forward f ...)

Returns a function that, given a list of arguments, invokes each function in order with the given argument list. The argument list to the returned function is treated like that of apply, so the last argument is interpreted as a list. That is, ((forward f g h) x y z) is roughly equivalent to (progn (apply f x y z) (apply g x y z) (apply h x y z)).

pull-out / p%

(pull-out f)

Uncurries the first argument of f, returning a new function that takes a single argument list. So ((pull-out f) x y z) simplifies roughly to ((f x) y z). As a special case, ((pull-out f)) simplifies to (f f), except that f is evaluated only once.

(pull-out f g ... h)

Uncurries the first argument and applies the functions in sequence to it. So ((pull-out f g h) x y z) is roughly equivalent to ((f (g (h x))) y z). Likewise, ((pull-out f g h)) translates down to (f (g h)).

Comparisons

==

(==)

Returns the constant 100.

(== x)

Returns whether x is equal to %. If % does not exist, it is treated as being ().

(== x ys ...)

Returns 1 if the values are all equal and 0 otherwise. Values are equal if and only if they have the same type and the same underlying data. Numbers, atoms, and strings are compared for equality in the usual way. The nil value () is equal to itself and only itself. Cons cells are equal if and only if their corresponding components are equal.

All other values, such as built-in functions and special operators, currently compare unequal to everything, even to themselves. This behavior may change. It is not recommended to pass built-in operators to ==.

less-than / c,

(less-than x ...)

Transitively applies the comparison operator to check if each provided value is less than its successor in the argument list. All arguments are coerced to numbers. Mnemonic: c for "comparison" and , is the lowercase form of <.

less-eq / =,

(less-eq x ...)

Transitively applies the comparison operator to check if each provided value is less than or equal to its successor in the argument list. All arguments are coerced to numbers. Mnemonic: = for "equality comparison" and , is the lowercase form of <.

greater-than / c;

(greater-than x ...)

Transitively applies the comparison operator to check if each provided value is greater than its successor in the argument list. All arguments are coerced to numbers. Mnemonic: c for "comparison" and ; is the lowercase form of >.

greater-eq / =;

(greater-eq x ...)

Transitively applies the comparison operator to check if each provided value is greater than or equal to its successor in the argument list. All arguments are coerced to numbers. Mnemonic: = for "equality comparison" and ; is the lowercase form of >.

str-less-than / ,c

(str-less-than x ...)

Transitively applies the comparison operator to check if each provided value is less than its successor in the argument list. All arguments are coerced to strings. Mnemonic: c for "comparison" and , is the lowercase form of <.

str-less-eq / ,=

(str-less-eq x ...)

Transitively applies the comparison operator to check if each provided value is less than or equal to its successor in the argument list. All arguments are coerced to strings. Mnemonic: = for "equality comparison" and , is the lowercase form of <.

str-greater-than / ;c

(str-greater-than x ...)

Transitively applies the comparison operator to check if each provided value is greater than its successor in the argument list. All arguments are coerced to strings. Mnemonic: c for "comparison" and ; is the lowercase form of >.

str-greater-eq / ;=

(str-greater-eq x ...)

Transitively applies the comparison operator to check if each provided value is greater than or equal to its successor in the argument list. All arguments are coerced to strings. Mnemonic: = for "equality comparison" and ; is the lowercase form of >.

Input / Output

puts / pu

(puts)

Outputs the value of the variable %.

(puts exprs ...)

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

gets / ge

(gets)

Reads one line of input from STDIN and returns it.

(gets n)

Coerces n to a number and reads n lines of input from STDIN, returning a list.

gets-all / ga

(gets-all)

Reads the remainder of STDIN and returns it as one large string.

print

(print)

Outputs the value of the variable %. The function print is designed to print a read-friendly string, while puts is designed to print user-friendly values. For instance, print will print quotes around strings, while puts will simply print the contents of the string.

(print exprs ...)

Outputs each expression to stdout on a separate line. This function always returns (). The function print is designed to print a read-friendly string, while puts is designed to print user-friendly values. For instance, print will print quotes around strings, while puts will simply print the contents of the string.

print-greek / pgk

(print-greek n)

Prints the nth letter of the Greek alphabet followed by a newline, where "Alpha" is the 0th letter. The value n is considered modulo 24. The value returned is always ().

(print-greek n ... m)

Performs print-greek for each argument separately, in order.

eof

(eof)

Returns whether or not STDIN has been exhausted. Note: This function may not behave correctly when run within the REPL, as it does not fully understand its interactive nature.

argv / av

(argv)

Returns a list containing the command line arguments passed to the script. In the REPL, this function always returns ().

(argv n)

Returns the nth command line argument, wrapping around if necessary. Negative indices count from the back of the argument list.

(argv n ... m)

Returns the corresponding elements from the command line argument list in a list.

Miscellaneous

(None)

Clone this wiki locally