- set
- Sets the value of a symbol:
(set 'A 42)
A => 42
- put, get & prop
- Set and get the property of a symbol
(put 'A 'foo 42)
(get 'A 'foo) => 42
(prop 'A 'foo) => (42 . foo)
- =
- Equality
(= 42 42) => T
(= '(1 (2 . 3) 4) '(1 (2 . 3) 4)) => T
(= "foo" "bar") => NIL
- cond
- Conditional
(cond
(= 42 1)
NIL
T ;; always matching conditional
123) => 123
- do
- Execute every expression in list, returning the result of the last one
- let
- Bind symbols to values for the expression. Saves and restores the existing bindings. Supports list destructuring.
(let (L (1 2 3 4)
(A B . C) L)
(list A B C))
=> (1 2 (3 4))
- cons
- Create a cons cell.
(cons 1 2) => (1 . 2)
(cons 1 (cons 2 (cons 3 NIL))) => (1 2 3)
- pair
- Returns T if argument is a cons cell
- car
- Returns the car of a cell
(car ("foo" . 42)) => "foo"
- cdr
- Returns the cdr of a cell
(cdr ("foo" . 42)) => 42
- list
- Create a list of the arguments
(list 1 2 3) => (1 2 3)
- make
- Create a list accumulator, putting every call within the make into a list
(make
(link "foo")
(cond
(= 42 T)
(link 'nope))
(link 123)) => ("foo" 123)
- loop
- Loops over its expressions. If an expression is (T ..truthy expression..) or (NIL ..expr eval'ing to NIL..) the loop is exited
(set 'N 5)
(make
(loop
(T (= N 0))
(link N)
(set 'N (- N 1))))
=> (5 4 3 2 1)
- quote
- Quote all the arguments. Reader shortcut: '
(+ 1 2) => 3
(quote (+ 1 2)) => ((+ 1 2))
'(+ 1 2) => (+ 1 2)
- eval
- Evaluate the expression
(eval '(+ 1 2)) => 3
- apply
- Applies the function to all the arguments, with the last argument list splat.
(apply + 1 2 (3 4 5)) => 15
- Math: + - * /
- Math using fixed nums
(+ 1 2) => 3
(/ 1 2) => 0
(* 123456789123456789 123456789123456789) => 15241578780673678515622620750190521
- Functions
Parameters in list:
'((X Y) (+ X Y)) ;; with evaluated args
'((X . REST) (apply + X REST)) ;; with evaluated args and rest bindings
('((X Y) (+ X Y)) 3 4) => 7
Single symbol parameters:
'(@ (apply + @)) ;; @ is list of evaluated args
(set 'sum '(@ (apply + @)))
(sum 1 2 3 4) => 10
'(X (eval X)) ;; f-expression, the function gets the un-evaluated args passed as a list to X
(set 'if '(ARGS (let ((COND THEN ELSE) ARGS) (cond COND (eval THEN) T (eval ELSE)))))
(make (if T (link 42) (link "foo"))) => (42)