1 Built Ins
FelixBrendel edytuje tę stronę 7 lat temu

Built-in functions

Regular functions

Symbol Argument Count Argument Types Description Accepted Keywords
+ any :number Adds up the arguments
- any :number Subtracts the arguments from the first one
* any :number Multiplies the arguments together
/ any :number Divides the arguments
= any overloaded Checks if all the arguments are equivalent
pair 2 any Returns a pair of the two arguments
first 1 :pair Returns the first element of the pair
rest 1 :pair Returns the rest of the pair
eval 1 any Evaluates the argument
prog any any Combines multiple expressions to one
list any any Returns a list of the arguments
print 1 any Prints the arguments :end :sep
read 0 or 1 any Reads a string from stdin
type 1 any Returns the type of the argument
exit 0 or 1 :number Exits the interpreter with the given exit code

Special forms

Symbol Argument Count Argument Types Description
and any any Logic and (with short circuiting)
or any any Logic or (with short circuiting)
not 1 any Logic not
if 2 or 3 any First arguments is the condition, second the “then” part, the optional thirt is the “else” part
quote 1 any Returns the argument without evaluating it (as the syntax tree)
define 2 :symbol, any Defines a Symol in the the current environment

Reference

+

Accepts any number of arguments of type :number and returns the sum of them.

(+ 1 2 3) ;; 1 + 2 + 3
> 6.00000

-

Accepts any number of arguments of type :number and returns the difference of the first number to the sum of the other arguments.

(- 10) ;; watch out !
> 10.00000

(- 10 2 3 1) ;; 10 - 2 - 3 - 1 => 10 - (2 + 3 + 1)
> 4.00000

*

Accepts any number of arguments of type :number and returns the product of them.

(* 3 4 2) ;; 3 * 4 * 2
> 6.00000

/

Accepts any number of arguments of type :number and returns the quotient of them.

(/ 100)
> 100.00000

(/ 100 5 2) ;; ((100 / 5) / 2)
> 10.00000

=

Accepts any number of arguments of any type and compares them, returning 1.00000 if they are all equivalent (might still be different objects) or nil if they are not all the same. The finction is overloaded for all the built-in types

(= 100)
> 100.00000

(/ 100 5 2) ;; ((100 / 5) / 2)
> 10.00000

pair

first

rest

eval

prog

list

print

read

type

exit

and

or

not

if

quote

define