S-Expressions, Atoms and Lists
3.1 S-Expressions
An s-expression (symbolic expression) is either an atom or a list of s-expressions in parentheses.
42 ; number atom
3.14 ; float
"hello" ; string
foo ; symbol
#t #f ; booleans (Scheme); t / nil in Common Lisp; true / false in Clojure
(1 2 3) ; list of numbers
(a (b c) (d (e f))) ; nested lists form trees
() ; the empty list3.2 Prefix (Polish) Notation
Function calls put the operator first: (operator arg1 arg2 ...).
No operator precedence: parentheses make the structure explicit.
(+ 1 2) ; 3
(+ 1 2 3 4 5) ; 15: variadic, no precedence rules needed
(* 2 (+ 3 4)) ; 14
(- 10 (/ 8 2)) ; 6
(max 3 9 2) ; 9
(< 1 2 3) ; #t: chained comparison3.3 Reading Lisp Code
Read Lisp by indentation, not by counting parentheses. Editors handle the parentheses (paredit, smartparens, parinfer).
(define (average a b)
(/ (+ a b)
2))