Reading — step 1 of 5
Learn
~1 min readS-Expressions
Common Lisp has multiple binding forms:
defparameter — top-level dynamic binding:
(defparameter *pi* 3.14159) ; convention: earmuffs for globals
defvar — like defparameter but only sets if undefined.
let — local lexical binding:
(let ((x 10)
(y 20))
(+ x y)) ; 30
let* — sequential let (later bindings can refer to earlier):
(let* ((x 10)
(y (* x 2)))
(+ x y)) ; 30
Reading stdin:
(let ((line (read-line)))
(parse-integer line))
read-line reads one line. parse-integer parses to int. Easier shortcut for numeric input: (read) which auto-parses Lisp atoms.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…