The REPL, Expressions and Evaluation

3.1 Using the REPL

CL-USER> (+ 1 2)
3
CL-USER> (* 2 (+ 3 4))
14
CL-USER> "hello"
"hello"
CL-USER> *                            ; * holds the last result (** and *** the ones before)
"hello"
CL-USER> (describe 'car)              ; documentation and info
CL-USER> (documentation 'mapcar 'function)
CL-USER> (apropos "hash-table")       ; search for symbols
CL-USER> (load "hello.lisp")
CL-USER> (compile-file "hello.lisp")  ; produce a .fasl (compiled file)
CL-USER> (quit)                       ; (sb-ext:exit) in SBCL

3.2 Evaluation Rules

Self-evaluating objects (numbers, strings, characters, keywords, t, nil) evaluate to themselves.

Symbols evaluate to their variable value.

Conses (lists) are evaluated as:

Special operators (if, let, quote, setq, progn, function, lambda forms, ...) with their own rules

Macro calls, which are expanded and then the expansion is evaluated

Function calls: arguments are evaluated left to right, then the function is called

(quote (+ 1 2))           ; (+ 1 2)
'(+ 1 2)                  ; same
(list '+ 1 2)             ; (+ 1 2)
(eval '(+ 1 2))           ; 3
`(1 ,(+ 1 1) ,@(list 3 4)); (1 2 3 4): backquote, comma, comma-at
(progn (print 1) (print 2) 3)   ; evaluates forms in order, returns the last

3.3 Comments and Conventions

Naming: kebab-case, *earmuffs* for special (global dynamic) variables, +plus-signs+ for constants, -p suffix for predicates (evenp, string-prefix-p; p alone for one-word names, -p for multi-word), make- for constructors, and % prefix for internal functions.

;;;; File header comment (four semicolons)
;;; Section comment (three)
;; Comment about the following code (two)
(foo) ; trailing comment (one)
#| block comment
   #| nestable |# |#
#+nil (this form is ignored by the reader)    ; "feature expression" commenting trick