Skip to content

triumphantomato/LispInFiveDays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lisp in Five Days

Let's learn about Lisp!

Screen Shot 2022-03-31 at 4 48 09 PM

Audience

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.


Day Zero - Python Refresher

How to learn:

  1. Use the Python REPL to experiment with things, then check StackOverflow to confirm your understanding
  2. 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) = x where x is a list with exactly two values is legit
  • The unpacking operator * and how *args works

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()

Day One - LISP Intro

  • 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 sbcl functioning and play around in the REPL a bit but don't invest too much time in Common Lisp tooling
  • 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

  1. How is programming in Lisp the same or different from your favorite language?
  2. Can a program written today in $your_language run without edits 20 years later? Is it common for a library to be "done" and not need updates for years afterwards?
  3. Who is Phyllis Fox? (See Grönlund's video on Lisp history)
  4. What was Lisp invented for, and why was it not intended to be a programming language? (See again Grönlund's video)

Day Two - Lisp in Python

Some questions for reading

  1. What are the pros/cons of valuing interface simplicity over implementation cost (as in Lisp), or vice versa (as in C/UNIX)?
  2. What happens to the barrier to entry to programming depending on which paradigm you value more?

Day Three - Lisp in Python

Some questions for reading

  1. Norvig - Pay special attention to syntax vs. semantics in Norvig. Don't worry if you don't understand all his code immediately.
  2. 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?

Day Four - Lisp in Lisp:

  • 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:

  1. Graham - you should be well equipped to move through this text with some speed now. You can use your rlwrap sbcl Common 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.

Day Five - Some Beautiful Lisp:

  • 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!)

Go Beyond

  • 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

About

Let's learn about Lisp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors