📓 literature/the-little-schemer.md by @ryan

The Little Schemer

tags : [[lisp]] [[functional programming]] [[Scheme]]

Some of my examples are written in Emacs Lisp, as at the time I hadn’t installed a Scheme interpreter. It doesn’t make a huge difference.

1. Toys

2. Do It, Do It Again

3. Cons the Magnificent

(defun firsts (l)
    (cond
    ((null l) '())
    (t (cons (car (car l)) (firsts (cdr l)) ))))

(firsts '((a b) (c d))) ;; => (a c)
a c

5. Oh My Gawd: It’s full of Stars

6. Shadows

The Seventh Commandment : Recur on the subparts that are of the same nature

An attempt at value (for only +) in Emacs Lisp: “`emacs-lisp (defun my-value (nexp) (cond ((atom nexp) nexp) ((eq (car (cdr nexp)) ‘+) (+ (value (car nexp)) (value (car (cdr (cdr nexp)))))) (t nexp)))

  (my-value '(1 + 2))
```

The Eighth Commandment : Use help functions to abstract from representations