Live data from Hacker News

Mal – Make a Lisp, in 68 languages

github.com

11–20 of 74 posts

Re: Mal – Make a Lisp, in 68 languages

#11

Writing/understanding a lisp interpreter is a longstanding item on my TODO list. Question: how do I go from tackling this to tackling compilers?

Make it generatem a simple bytecode format, that you can map into Assembler macros.

Choose a good Macro Assembler like NASM or YASM, and implement the bytecodes as macros.

It won't win any benchmark, but you will get native executables.

Or use Lisp macros to generate the code.

Here is a Scheme based tutorial.

http://icem-www.folkwang-hochschule.de/~finnendahl/cm_kurse/...

Re: Mal – Make a Lisp, in 68 languages

#12
post #3

This is a fantastic way to "waste" a weekend, and there's so much learning to be had. The radically simple implementation of TCO really surprised me.

See the design narrative at “Step 5: Tail call optimization”[0] in The Make-A-Lisp Process[1].

[0]: https://github.com/kanaka/mal/blob/master/process/guide.md#s...

[1]: https://github.com/kanaka/mal/blob/master/process/guide.md

Re: Mal – Make a Lisp, in 68 languages

#15

Writing/understanding a lisp interpreter is a longstanding item on my TODO list. Question: how do I go from tackling this to tackling compilers?

Make a very decent interpreter for a language that is good for writing compilers (without a question, a Lisp of some sorts, of course, ha).

Then, write the compiler in that language.

The compiler walks the code just like the interpreter, but instead of interpreting, it spits out a translation.

Spitting out some kind of translation into something isn't a very high bar; the difficulties are all in optimization: things like analyzing lexical scopes for the presence of closures which escape, so as to be able to stack-allocate environments that aren't captured by closures. Plus all those other difficult things: like turning a program into a graph of basic blocks and doing flow analysis; register allocation, selection of instructions for a myriad target machines, debugging suport, and so on. Any of these requirements can be excluded from a compiler, yet it's still a compiler.

The "Lisp in 500 lines of C" (plus accopmanying .lisp) file implemented a compiler. The complete source is hard to find, but here is a derivative project: https://github.com/jackpal/lisp5000

A chunk of init500.lisp implements compilation to C. Search the file for terms like "compile" and also "deftransform".

If you've ever written a macro, you've written a piece of a compiler. Macros take an input syntax tree and spit out a new one. Many actions traditionally associated with a compiler (by Lisp-unaware computer scientists) can be done by macros or in the macro expander. Basic compiling is a lot like macro expansion. It can actually be Lisp-to-Lisp even; the transformers can spit out a Lisp data structure representing a target language. (Heck GCC spits out a Lisp-like data structure for intermediate code. Of course; it was originally a project started by Stallman.)

Re: Mal – Make a Lisp, in 68 languages

#16

Writing/understanding a lisp interpreter is a longstanding item on my TODO list. Question: how do I go from tackling this to tackling compilers?

Work through The Make-A-Lisp Process[0], which finishes at “Step A: Metadata, Self-hosting and Interop.”[1]

From there, you’ll be more than ready to generate machine code.

[0]: https://github.com/kanaka/mal/blob/master/process/guide.md

[1]: https://github.com/kanaka/mal/blob/master/process/guide.md#s...

Re: Mal – Make a Lisp, in 68 languages

#19
post #13
post #8

Earlier quoted context omitted.

Writing an interpreter (or compiler) greatly enhances one's programming skills.

Why not work on improving an existing one ?

While we're at it, why don't we replace high school math tests with one question: "Solve the Riemann hypothesis". We can replace the physics curriculum with "Unify quantum mechanics with general relativity", and throw out computing courses in favour of "Prove whether or not P = NP".

It's important to re-do things which others have already worked out, in order to reach a greater understanding :)

Re: Mal – Make a Lisp, in 68 languages

#20
post #13

Earlier quoted context omitted.

Why not work on improving an existing one ?

While we're at it, why don't we replace high school math tests with one question: "Solve the Riemann hypothesis". We can replace the physics curriculum with "Unify quantum mechanics with general relativity", and throw out computing courses in favour of "Prove whether or not P = NP". It's important to re-do things which others have already worked out, in order to reach a greater understanding :)

Whatever.

I learned how to implement Lisp by reading the source code for multiple compilers. Started with Franz Lisp, then KCL and CMUCL. I don't feel that a toy interpreter is going to teach the same things.

Post reply on HN