I'm looking to write a really basic one in javascript except using plain arrays. No parsing or tokenizing for me.
I'm looking to write a really basic one in javascript except using plain arrays. No parsing or tokenizing for me.
There are also the Lis.py articles which are incredibly good:
https://norvig.com/lispy2.html
You mentioned you want to write your lisp in javascript so you'll be getting quite a lot of functionality for free: memory allocation and garbage collection. That alone solves an enormous amount of problems. Just in case anyone reading is going to write in C, here's an excellent introduction to the topic:
https://journal.stuffwithstuff.com/2013/12/08/babys-first-ga...
Don't forget to spill the registers.
evalExpression:
switch peekChar
( evalFunctionCall
0-9 parseNumber
" parseString
a-zA-Z parseAndGetVariable
evalFunctionCall
fn = evalExpression
arguments = evalExpression until )
fn(arguments)This inlines the diffs between the original SICP and the new one that is implemented in Javascript too.
[0] https://github.com/kanaka/mal
[1] https://github.com/kanaka/mal/blob/master/process/guide.md
[Edit] Just wanted to reiterate that lexing/parsing Lisp is easy as per the MAL instructions. IIRC the things that I found hardest (in C#, as a C# newby) were understanding how to implement the closures required to support function definition, and then implementing Lisp's macro expansion.
https://okmij.org/ftp/tagless-final/
This embeds the target language as combinators in a host language, so you can construct and evaluate programs.
https://higherlogics.blogspot.com/search/label/tagless%20int...
The style of the construction is what matters most. If you're using JS then you're already giving up types, but the higher order abstract syntax is what lets you embed and play with language semantics.
A little later I used Norvig's Scheme implementation from chapters 22 and 23 of PAIP (https://norvig.github.io/paip-lisp/#/?id=paradigms-of-artifi...).
I liked Norvig's a little better. It starts with a simple interpreter and adds improvements step-by-step, winding up with an optimizing compiler that targets a bytecode VM.
That approach makes a lot of implementation details manifest in a way that is easy to grasp. For example, I think I understood continuations much better after seeing Norvig's account of how to implement them.