Let's learn about Lisp!
You'll get the most out of this course if you:
- Have tried a couple programming languages
- Are comfortable in python
- Haven't worked much with compilers or interpreters before
You will learn:
- How interpreters work, practically (including developing an intuition for abstract syntax trees)
- What makes Lisp special, and beautiful
- Some ways to think about programming languages
For the curious, my own attempts at implementing a basic Lisp interpeter can be found at main.py (in python) and main.lisp (in lisp), following Nielsen and Graham respectively.
How to learn:
- Use the Python REPL to experiment with things, then check StackOverflow to confirm your understanding
- Run the code. Type every example out and run it. Modify the examples. Once you get the hang of it, try to complete the function or write the sub-routine before looking at the example. Understand why the example is different and what you got wrong, or what different choices you made.
Review:
- List comprehensions
.zip().map()- List manipulations:
.pop(),.strip(),.join() - The role of
_(to ignore an input) - Assignment operator - it assigns RH to LH, so
(_, exp) = xwhere x is a list with exactly two values is legit - The unpacking operator
*and how*argsworks
Exercises
These exercises review some helpful python concepts. The learning purpose of each exercise is listed below it.
Ex 1. Write a python program that takes a plaintext file as a command line argument and prints its contents to screen without any spaces.
.strip()- loading an external file via command line
Ex 2. Write a python program to sum a variable amount of arguments together.
*args
Ex 3. Modify your program from Ex 1. to split the input file's text into two lists, each containing every other word. So listOne contains all odd words (word 1, word 3, word 5...) and listTwo contains all even words. Then use zip() and join() to reprint the text file in order, two words at a time.
zip()join()
Ex 4. Use map() to modify your program from Ex 3. to print each word reversed.
map()
- Watch a talk on LISP history - Let's LISP like it's 1959 - Kristoffer Grönlund, 2019
- Skim to see what's special about Lisp - A Road to Common Lisp - Steve Losh, 2018
-
- do enough to get
rlwrap sbclfunctioning and play around in the REPL a bit but don't invest too much time in Common Lisp tooling
- do enough to get
- Main Text - Lisp as the Maxwell's Equations of Software- Michael Nielsen, 2012
- Work until section titled: A nontrivial example: square roots using only elementary arithmetic
Some questions for reading
- How is programming in Lisp the same or different from your favorite language?
- Can a program written today in
$your_languagerun without edits 20 years later? Is it common for a library to be "done" and not need updates for years afterwards? - Who is Phyllis Fox? (See Grönlund's video on Lisp history)
- What was Lisp invented for, and why was it not intended to be a programming language? (See again Grönlund's video)
- Main Text - Lisp as the Maxwell's Equations of Software- Michael Nielsen, 2012
- Continue until section titled: An interpreter for Lisp
- Read about Lisp vs. C - Worse is Better - Richard Gabriel
- Read about the death of Lisp in college curricula - Lisp and Smalltalk are dead: It's C all the way down - Mark Guzdial, 2009
Some questions for reading
- What are the pros/cons of valuing interface simplicity over implementation cost (as in Lisp), or vice versa (as in C/UNIX)?
- What happens to the barrier to entry to programming depending on which paradigm you value more?
- Main Text - Lisp as the Maxwell's Equations of Software- Michael Nielsen, 2012
- Work through entirety of section titled An interpreter for Lisp
- Read about why you should learn compilers - Rich programmer food - Steve Yegge, 2007
- Read about Lisp interpreter innards - How to write a lisp interpreter in python - Peter Norvig
Some questions for reading
- Norvig - Pay special attention to syntax vs. semantics in Norvig. Don't worry if you don't understand all his code immediately.
- Yegge - Enjoy his wit. Consider the problems he poses and their real-world applicability. Consider determinism vs. stoachsticism. Can you give examples of each approach? Which do you think will be more successful? Does it vary by field?
- Bounce between the Graham and Nielsen as appropriate - Graham is a more "axiomatic" derivation of Lisp in Lisp, and is beautiful for that reason, while Nielsen does a good job explaining the semantics of
eval. - Read The Roots of Lisp (Postscript - right-click -> save as) - Paul Graham, 2002
- Lisp as the Maxwell's Equations of Software - Michael Nielsen, 2012
- Work from section titled Lisp in Lisp through end, finish tomorrow if needed
Reading Notes:
- Graham - you should be well equipped to move through this text with some speed now. You can use your
rlwrap sbclCommon Lisp environment from the Losh article to implement what you would like. - I recommend reading this before doing the Nielsen Lisp in Lisp work. I find Graham's explanation clearer.
- Read Paul Graham's Beating the Averages for a fun view on Lisp as a competitive advantage, and Patrick Collison on Stripe choosing Ruby for some counterpoint (N.B.: Patrick helped Paul with his latest Lisp-dialect, Bel)
- Work through The Y Combinator - Mike Vanier - to understand footnote 3 from Graham's essay on The Roots of Lisp
Reading Notes:
Vanier - this is a beautiful text. You'll walk away understanding:
- Lazy vs. strict evaluation languages
- Weak vs. strong typing in languages
- And how this is different from dynamic vs. static typing
- How to use the Y combinator to implement recursion without a recursive function call (to be frank, I'm still working through this myself!)
- Read about practical applications of the Y Combinator - Y in Practical Programs - Bruce McAdam, 2001 (Postscript - right-click -> save as)
- Read about how to successively grow the Lisp interpreter Graham explains into a language with practical numbers, side-effects, and sequential execution (and to understand those concepts) The Art of the Interpreter - Guy Lewis Steele Jr. and Gerald Jay Sussman, 1978
- Watch Compiler innards (in Ruby) Compiler From Scratch - Gary Bernhardt, 2017
- Build your own Lisp with this end-to-end tour (in C) BuildYourOwnLisp
- Watch Growing a Language - Guy L Steele Jr., OOPSLA Keynote, 1998
