; sexpr.lsp: data and programs are both S-expressions
;   sbcl --script sexpr.lsp

; 1. a heterogeneous list: a number, a string, a symbol, a list, a float
(defvar mix (list 1 "two" 'three (list 4 5) 6.5))
(format t "mix        = ~s~%" mix)
(format t "types      = ~s~%" (mapcar #'type-of mix))
(format t "4th elem.  = ~s, its length ~a~%" (fourth mix) (length (fourth mix)))

; 2. a piece of program, quoted, is just a list
(defvar expr '(+ 1 2))
(format t "~%expr       = ~s~%" expr)
(format t "first      = ~s (a ~a)~%" (first expr) (type-of (first expr)))
(format t "rest       = ~s~%" (rest expr))
(format t "evaluated  = ~s~%" (eval expr))

; 3. a function definition is a list too
(defvar def '(defun cube (x) (* x x x)))
(format t "~%def        = ~s~%" def)
(format t "length     = ~a, first = ~s~%" (length def) (first def))
(eval def)                              ; run the list as a program
(format t "(cube 3)   = ~a~%" (cube 3))

; 4. build a program out of data, then run it
(defvar built (list '* 6 7))
(format t "~%built      = ~s -> ~a~%" built (eval built))
