Skip to the content ForoHackers
Log inJoin

Lisp and Scheme: start here

Lisp and Scheme
#575 · Ophuscado · · Report

Lisp is a family of languages, including Scheme and Common Lisp, in which programs are written as nested lists. Code and data share one shape, so programs can build and transform programs. That makes Lisp a classic way to learn what a language is, and its ideas, from garbage collection to closures and macros, shaped almost everything that came after.

Key concepts

  • S-expressions: a program is a tree of parenthesised lists, with the operator first.
  • Code as data: because code is a list, a program can read, build and rewrite code.
  • Macros: functions that run at compile time and transform code before it is evaluated.
  • First-class functions and closures: functions are values; lambda creates them.
  • Recursion and lists: cons cells, car and cdr, and recursive processing of lists.
  • The evaluator: a Lisp interpreter written in Lisp is only a page long.

Vocabulary

  • Cons cell: a pair, the building block of lists.
  • REPL: the interactive read-eval-print loop where Lisp is usually developed.
  • Homoiconicity: the property that code has the same structure as data.
  • Tail call: a call in final position; Scheme requires it to use no extra stack.

What to study, in order

  1. Basic expressions, defining functions and recursion in a Scheme or Lisp prompt.
  2. Lists and higher-order functions: map, filter and fold by hand.
  3. Closures and local state, with a counter and an accumulator.
  4. Write a small evaluator for a Lisp in Lisp, or in another language.
  5. Macros: write a few, then learn how hygiene avoids name clashes.
  6. Read the language's standard or report and a short program in an editor extension.

Related tags

#functional-programming #interpreters #language-design #compilers

Log in or join to reply.