enter lisp expressions to let them be evaluated. lisp is about lists: (a b (1 2)) is a list, containing the items a and b and the list (1 2) nil is the empty list keywords so far: ', quote: prevent an expression from being evaluated >'a -> a car: first element of list >(car '(a b c)) -> a cdr: rest of list >(cdr '(a b c)) -> (b c) cons: construct a list from car and cdr >(cons 'a '(b c)) -> (a b c) add: add numbers >(add 1 2 3) -> 6 sub: subtract two numbers mul: multiply numbers div: divide two numbers (integer result) mod: calculate modulus of two numbers eq: check for equality >(eq 0 1) -> nil >(eq 0 0) -> t (t represents truth) def: define a function >(def sqr (lambda (n) (mul n n))) -> sqr >(sqr 3) -> 9 (calling that function) setq: bind an atom to a value > (setq a '(1 2 3)) >a -> (1 2 3) list: make a list >(list a 'b 'c) -> ((1 2 3) b c) atom: is it an atom (i.e. no list) >(atom nil) -> t eval: evaluate an expression > (eval (cons 'add a) -> 6 cond: make a decision >(cond ((eq a nil) 'foo) (t 'bar)) -> bar lambda: evaluate with parameters >((lambda (n) (add n 1)) 3) -> 4 the standard example for a recursive lisp function is the faculty: >(def fak (lambda (n) (cond ((eq n 0) 1) (t (mul n (fak (sub n 1))))))) >(fak 10) -> 3628800 some more standards: >(def append (lambda (a b) (cond ((eq a nil) b) (t (cons (car a) (append (cdr a) b)))))) >(append '(a b c) '(d e f)) -> (a b c d e f) >(def reverse (lambda (l) (cond ((eq l nil) nil) (t (append (reverse (cdr l)) (cons (car l) nil)))))) >(reverse '(a b c d e f)) -> (f e d c b a)
***DISCLAIMER*** Make sure audio is turned on Scratch stores audio values with higher precision than normal variables for some reason so I abused that (: