Lisp Index Page

Table of Contents

This is the lisp index page, containing general staff for lisp.

There's a page for corresponding APIs of common lisp, racket, clojure, emacs lisp.

1 Lisp-1 vs. Lisp-2

Lisp-1 has seperate namespace for functions and variables, while Lisp-2 only have one universal namespace.

Lisp-1 includes Elisp, common lisp. All scheme are lisp-2.

2 fold & unfold

In academic functional programming literature, folds are often called catamorphisms, unfolds are often called anamorphisms, and the combinations of the two are often called hylomorphisms. They're interesting because any for-each loop can be represented as a catamorphism. To convert from a loop to a foldl, package up all mutable variables in the loop into a data structure (records work well for this, but you can also use an algebraic data type or a list). The initial state becomes the accumulator; the loop body becomes a function with the loop variables as its first argument and the iteration variable as its second; and the list becomes, well, the list. The result of the fold function is the new state of all the mutable variables.

Similarly, every for-loop (without early exits) can be represented as a hylomorphism. The initialization, termination, and step conditions of a for-loop define an anamorphism that builds up a list of values for the iteration variable to take. Then, you can treat that as a for-each loop and use a catamorphism to break it down into whatever state you wish to modify.

3 Car & Cdr

The names CAR and CDR derive from the history of Lisp. The original Lisp implementation ran on an IBM 704 computer which divided words into two parts, called the “address” part and the “decrement”; CAR was an instruction to extract the contents of the address part of a register, and CDR an instruction to extract the contents of the decrement. By contrast, “cons cells” are named for the function ‘cons’ that creates them, which in turn was named for its purpose, the construction of cells.

4 Reference

Author: Hebi Li

Created: 2018-01-21 Sun 17:56