Coding Challenge #30 - Lisp Interpreter
John Crickett
Helping you become a better software engineer by building real-world applications.
This challenge is to build your own Lisp interpreter.
Lisp is a general-purpose, multi-paradigm programming language suited for a wide variety of industry applications. It is probably most widely know for being the programming language built into Emacs. As well as that it was used to build Hacker News (Paul Graham is a Lisp fan), Grammarly, Circle CI (actually using the modern dialect Clojure) and Boeing.
Intermission!
Two quick announcements:
The Challenge - Building Your Own Lisp Interpreter
In this Coding Challenge you are going to build your own simple Lisp interpreter. Like all the challenges, you can tackle it in any programming language you like. Bonus points if you go all Inception on it and build the interpreter in a modern version of Lisp, like Clojure or Racket!
If you want to learn a little Lisp (which is a fun thing to do), I pulled together some tutorial material in a LinkedIn post: 10 ways to learn Lisp. In the meantime here’s a very brief introduction.
There are two fundamental elements to Lisp syntax, atoms and s-expressions. 1, :cc and t are all atoms, where as (+ 1 2) and (defun hello () "Hello Coding Challenges") are s-expressions. In these examples 1 and 2 are integers, :cc is a symbol and t is an atom denoting true.
An s-expression is either an atom or an expression, for example (a b c). Where a, b, and c can all then be either atoms or s-expressions. Mathematical operations are in prefix notation.
Step Zero
Coding Challenges like the majority of common programming languages arrays is zero based, we start with Step 0! For this step please setup your IDE / editor of choice and programming language of choice.
Step 1
In this step your goal is to tokenise the expressions in a string. My personal approach to this would be to use?test-driven development?(TDD) to build tests for some example Lisp, i.e.:
Be sure to add your own test cases too.
Continued...
You can find Step 2 and beyond on the?Coding Challenges?website as Build Your Own Lisp Interpreter.
Or if you'd rather get the whole challenge delivered to you inbox every week, you can subscribe on the?Coding Challenges Substack.
Building things for the internet
1 年Building a lisp is a great project and i would definitley encourage everyone to give it a go! For anyone out there trying this out here is a few links to check out for inspiration. - Peter Norvigs implementation in pythong https://norvig.com/lispy.html?/?https://norvig.com/lispy2.html - Great book on writing parsers and compilers in golang. https://compilerbook.com/ - My own implementation in golang https://github.com/ebuckley/gol
--
1 年https://www.fiverr.com/s/1dENXz As a new UI/UX designer help me start my career
Empowering engineering leaders to release faster and lead with confidence ?? DM me to learn more ? Engineering Expert ? Coach ? XPer ? Top Mentor ? SuperDad? ? Author ? Speaker
1 年John now that we're at Challenge #30, do you set them up to incrementally build on prior knowledge or are all examples independent?
??Unpacking Software Architecture
1 年I can't decide if the parentheses make Lisp easier or harder to write a parser for.
Software Engineer | MPhil (ACS, Cantab.)
1 年Lisp, the OG functional programming language. Nice warm-up before I write my dissertation.