What does HackerNews think of mal?

mal - Make a Lisp

Language: Assembly

#1 in Bash
#1 in C
#1 in C++
#1 in C#
#1 in Clojure
#1 in Docker
#1 in Java
#1 in JavaScript
#2 in PHP
#3 in Python
#1 in Ruby
#1 in Scala
#1 in Swift
>Would be interesting to see how the interpreter works actually...

It's quite easy to see, there are interpeters for Lisp in like 20 lines or so.

Here's a good one:

https://norvig.com/lispy.html

(It has the full code in a link towards the bottom)

There's also this:

https://github.com/kanaka/mal

> I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

Yes, but macros (like special forms, but macros can be user implementable) have some "special" powers regarding controlling the evaluation of the code they produce.

Here's some more discussion with examples:

https://stackoverflow.com/questions/42470940/how-is-the-defu...

I always recommend Make a Lisp [0]. It's a guided experience creating a Lisp in whatever language you already know. If you go through all the steps, you'll have created a self hosting Clojure-like Lisp.

For me implementing a Lisp piece by piece helped me better understand its core ideas.

[0] https://github.com/kanaka/mal

For me it was the "Make a Lisp" project. Reading the architectural diagram of a Lisp interpreter, and browsing its implementation in many (~87) programming languages.

https://github.com/kanaka/mal

Especially where the guide explains how tail-call optimization works, my mind was blown.

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

Studying the project changed the way I understand code. Since then I've created my own little Lisps in about three or four versions/languages. Next I'd like to write one in WebAssembly Text format, which is already in a Lisp-shaped syntax.

Here's how I did it, I would say it's solid, approachable, and enjoyable:

Go through the first half of Crafting Interpreters [0]. And then try to complete mal - Make a Lisp [1]. That's it. You'll only need these two.

P.S. People also say good things about Build Your Own Lisp [2], but I didn't finish it because I find spending quite some time writing C doesn't make me feel I'm enjoying something elegant.

[0]: https://craftinginterpreters.com/ [1]: https://github.com/kanaka/mal [2]: https://buildyourownlisp.com/

> It's on github

... at https://github.com/kanaka/mal

Fun fact: I got to work with Joel at a Clojure-based startup, LonoCloud (since acquired by ViaSat). Super sharp dude, and very helpful about MAL. Definitely recommend.

the classic introduction to building a lisp (interpreter) in different programming languages is:

https://github.com/kanaka/mal

Writing a Lisp interpreter in C/C++ is cheating. You get readable code and a standard library for free. Don't get me wrong, it's surely fun, but if you really wanna learn about things, you need to write a Lisp interpreter in Assembly. It's a much more satisfying experience.

Jokes aside, I'm hoping the author continues to feel free to spend their time implementing whatever idea they come across that is interesting. Sure, it's not as advanced as implementing something in C/C++, but maybe the authors goal was just to understand their preferred lisp (Clojure) better, rather than trying to understand C/C++ better?

> Bonus points if you get to optimize tail recursion. (I didn't, but I didn't try to, so I don't consider it a failure.)

Is this as complicated as people put it? I've never implemented my own lisp, but MAL (https://github.com/kanaka/mal) makes it seem like a relatively easy step in the process.

No questions (yet) but I found this a really good post. I'm a Rust newbie and I've coincidentally just started working through 'Crafting Interpreters' using Rust as my implementation language. Some of your code has helped clarify things in my mind.

My actual long-term goal is to build a VM in Rust and then use this to re-do the Make A Lisp project [0]. I completed this a couple of years ago using C# but felt vaguely uneasy that I was using C# to do the heavy lifting associated with garbage collection, etc.

[0] https://github.com/kanaka/mal

Want to plug in my favourite https://github.com/kanaka/mal basically make a lisp in lot of language.

Really give you ther idea of what is needed in build a programming language. Soemthing won't quite obvious. until you I down and write code. Example the ability to rewind, go back to a few earlier token.

people have accumulated a lot of lisp impl on Make A Lisp repo

https://github.com/kanaka/mal

Reminds me of this: https://github.com/kanaka/mal Highly recommend trying it out. Making a lisp is surprisingly easy and fun. Plus you get your own programming language out of it.
Somebody took the Make A Lisp challenge (https://github.com/kanaka/mal) quite serious :D
Maybe not a starting point because it’s too advanced, but Make A Lisp has example implementations for +80 languages now: https://github.com/kanaka/mal
I was wondering if anyone knows of a resource in the same vein as [1] or [2] but to implement a prolog interpreter instead of lisp.

1: https://github.com/kanaka/mal

2: http://www.buildyourownlisp.com/

Build one. Like this: https://en.wikipedia.org/wiki/SECD_machine

Or maybe use that SoC with its FORTH as microcode to implement SECD on top of it.

Or look into https://github.com/kanaka/mal & https://en.wikipedia.org/wiki/POP-11 for matching and mixing.

This is a bit tangential but what helped me most in picking up Lisp was writing my own. Until I worked through Make A Lisp [0] I don't think I really "got" Lisp. You can work in whatever language you're familiar with. You build a Lisp similar to Clojure and learn a lot of important concepts by implementing them.

[0] https://github.com/kanaka/mal

Thanks to the author for an enjoyable intellectual journey, it's a wonderful series of articles.

Having tried my hand at following the Make a Lisp project ¹, implementing an interpreter in a couple of languages, it's fascinating to see the process of designing the language and compiler from the ground up, discussing various tradeoffs for simplicity, reasons for internal data structure, etc.

In fact, I think I'm learning more about C99 than Lisp - there's something about creating a language (or just following along like me), by necessity it leads to the foundations of computing/programming, the concepts that make up the basis of all languages. It's a perfect (meta)subject for an educational project.

¹ https://github.com/kanaka/mal

I approached this wondering if it would be somewhat like 'Make a Lisp' or similar [0], that as a competent programmer you could start within minutes of starting to read the instructions.

It doesn't seem like that. I think this is because

* it has comprehensive background for newbies (e.g. the idea of setting breakpoints in a debugger)

* it is the accompaniment for a separate book

* it has some serious background assumptions (e.g. you know calculus)

* graphics programming is much, much harder than making a lisp.

[0] https://github.com/kanaka/mal

[Edit: formatting]

A few weeks ago, I went through "Make a Lisp" [1] using C#. It only took a few days to get to a pretty useful implementation. I "cheated" quite a bit using the existing C# implementation from the repo as a reference, but my end result looks pretty different. Learned a TON. Highly recommended.

[1] https://github.com/kanaka/mal

After following Make A Lisp [1] and seeing how easy it is to parse and get all that power, other syntax just seems sadistic for both the language developer and the users.

[1] https://github.com/kanaka/mal

Try writing an interpreter! “Make a Lisp“[0] and Norvig’s “(How to Write a (Lisp) Interpreter (in Python))”[1] really helped me understand the basics.

[0] https://github.com/kanaka/mal

[1] https://norvig.com/lispy.html

I was speaking generally in terms of self learning in compilers. Your criticism was that the article focused too heavily on the front end and that the magic or the needed focus is on back end issues (scheduling, selection).

I think there are a couple things in play here. Folks working with text, semi-structured data, synthesizing from disparate sources, etc will be front end heavy. Tokenization, lexing, is important outside of more than compilers, like loading binary formats from network or disk into memory.

For backend work, being able to extend or modify existing backends is important for languages targeting different runtimes (Spark, Beam, Impala). This can be in targeting new architectures or for predicate pushdown into data processing pipelines. Lots of different applications to use those skills.

Compilers and Database systems are an incredible microcosm of many areas of CS.

Areas of self study I think are nice are

MAL - Make a Lisp https://github.com/kanaka/mal

Nand2Tetris, project 11 https://www.nand2tetris.org/project11 (one should start from zero and make your way here, it is journey not a destination)

An educational software system of a tiny self-compiling C compiler, a tiny self-executing RISC-V emulator, and a tiny self-hosting RISC-V hypervisor. http://selfie.cs.uni-salzburg.at

LLVM is a huge system, libFirm is a much smaller, simpler system that includes a c front end. From their site

> libFirm is a C library that provides a graph-based intermediate representation, optimizations, and assembly code generation suitable for use in compilers.

https://pp.ipd.kit.edu/firm/

I also recommend checking out the Make a Lisp project: https://github.com/kanaka/mal

You can see the source code for a small Lisp interpreter in 81 different languages.

- Practical Common Lisp

- Land of Lisp - http://landoflisp.com/ - watch the video, it's hilarious

- Build Your Own Lisp - http://www.buildyourownlisp.com/ - Learn C by creating a lisp in C

- In the spirit of making your own lisp, I would recommend https://github.com/kanaka/mal - learn any language, by making a lisp in that language

A few things I did in the past I would definitely recommend:

* Make a Lisp https://github.com/kanaka/mal — tutorial on how to make a lisp language interpreter.

* Make an 8 bit computer https://eater.net/8bit — tutorial on making a simple 8 bit computer out of a bunch of AND, OR, NAND chips. Really helps you understand how computers work, what microcode is, etc. Honestly, building it wasn't quite as much fun as I thought it would be, but just learning how to build one was very useful.

Not a book, but an interesting self-guided course and apparently a great way to pick up a new language: Make A Lisp [0],[1],[2]

Basically, work through building a lisp interpreter in any given language (C, Java,...bash, vimscript) in 10 steps. Each step is backed by tests, and these tests help to guide you through the process. Very cool.

[0]http://kanaka.github.io/lambdaconf/

[1]https://github.com/kanaka/mal

[2]https://www.youtube.com/watch?v=jVhupfthTEk

I ran into “Make Your Own Lisp Interpreter in 10 Steps”[0] recently, and I’ve enjoyed walking through it. It works through a basic repl to macros, tail recursion, and finally self hosting! (I haven’t made it that far yet)

The guide [1] has been interesting to follow, and I appreciate the author’s approach to building a Lisp interpreter as a way to pick up a new language. For example, his interpreter, mal, has implementations in every thing from ada, nasm, and bash, to C, Ruby, rust, python and everything between.

Videos walking through the guide are available too [2], [3]

[0] https://github.com/kanaka/mal

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

[2] https://www.youtube.com/watch?v=jVhupfthTEk

[3] https://www.youtube.com/watch?v=X5OQBMGpaTU

I used Nim for my implementation of Make A Lisp[1]. I use Python every day and the jump was pretty straightforward. Almost copy and paste from some things. I don't have to think about static types much, but it was a welcome change. I loved having macros to play with, too. I spent a lot of time with docs which aren't bad.

As for the "mental capacity" I felt the same about finally getting into Rust. Spending some time with Nim actually helped me bridge the gap from Python to Rust.

[1] https://github.com/kanaka/mal

If you're interested in things being implemented in non-standard languages, I would check out the Make-A-LISP project on Github [1]. Someone even took it upon themselves to write an implementation in AWK :) [2]

[1] https://github.com/kanaka/mal/ [2] https://github.com/kanaka/mal/tree/master/awk

MAL (Make a Lisp) is a good one around building a lisp.

https://github.com/kanaka/mal

Lots of examples across 72 languages.

Well, building an interpreter isn't that difficult. Even less so, if you're building one on top of a good dynamic language (which was the case with Dart in my original list). If you're interested in getting started, these are good intros to the basics:

- http://www.buildyourownlisp.com/

- https://github.com/kanaka/mal

If you enjoy this sport, there's also Make-a-Lisp (MAL), an ongoing project to write lisp in every programming language:

https://github.com/kanaka/mal

In particular, here's their R version:

https://github.com/kanaka/mal/tree/master/r

I don't want to take away from this, but any time a home built lisp interpreter comes up with a "let me show you how it works", I always have to reference back to the MAL (make a lisp) project:

https://github.com/kanaka/mal

I find it's better to write it yourself than just have it explained to you. It really doesn't take that long to do, and it's broken into nice chunks of discrete work.

I've been writing my own lisp (in Clojure) by following the make-a-lisp[0] process guide. So far it's been challenging and interesting. It gives clear direction without being too hand-holdy.

[0] https://github.com/kanaka/mal

The subculture of OS makers is far smaller than the subculture of esoteric programming language enthusiasts. Its inevitable if templeos works the esolang people will descend upon it. There's probably a hundred, maybe a thousand Intercal programmers for every templeos enthusiast and they all love a new challenge.

https://en.wikipedia.org/wiki/Esoteric_programming_language

Personally I've been thinking of doing make-a-lisp in templeos. There's no point in doing make-a-lisp in qbasic or gnu awk or makefiles because its already been done. But make-a-lisp on templeos is, I believe, completely uncharted ground ... so in my infinite spare time ...

https://github.com/kanaka/mal

The only thing you need to do to understand lisp's entrancement is to write an interpreter for it, and in doing so you'll see why it's easier to write a lisp interpreter than it is for any other language. All you need to understand the appeal is a look at https://github.com/kanaka/mal.

Personally I learned the appeal of lisp while following this tutorial on writing a scheme in Haskell: https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_.... There's a reason there'll never be a tutorial like that for a toy Haskell interpreter.

Once again pimping one of my favorite DIY projects - Make A Lisp. Lisp in (almost) every language!

https://github.com/kanaka/mal

I find it to be a great tool for both learning about Lisp and the language you're writing your mal implementation in.

On the topic of writing lisps, an obligatory link to my favorite project: Make a Lisp

https://github.com/kanaka/mal

This reminds me of MAL [1], which stands for "Make A Lisp" or Make, A Lisp" depending on whether you're talking about the whole project or just the make version. It branched out into being implementations of a lisp in over two dozen languages, with instructions to help in writing your own. I was working on a haxe version before my motherboard recently bit the dust.

[1] https://github.com/kanaka/mal

Creating a Lisp is a great way to learn a language. https://github.com/kanaka/mal/ has thorough tests and step by step instructions to help you along the way, definitely recommend checking it out.
This is very similar to miniMAL [0]. They even have a miniMAL interpreter written in miniMAL [1] in the Make a Lisp project [2].

[0] : https://github.com/kanaka/miniMAL [1] : https://github.com/kanaka/mal/tree/master/miniMAL [2] : https://github.com/kanaka/mal

I bring this up every time, because it's a great approach to writing a compiler, and for showing off Lisp. Even better, if you get really stuck, there are already examples out there to learn from, in multiple languages.

Make A Lisp (MAL)

https://github.com/kanaka/mal

What is always missing for me in these lists is a tutorial for knocking together a small lambda calculus + dependently typed interpreter in C. Not ML, Not Ocaml, not, Haskell, not any language that has _already_ got lambdas in it!

Always when I read these I see, "get your Haskell compiler and..." and I'm like, if I knew Haskell well enough to do that I wouldn't be doing this tutorial in the first place.

Case in point, article says "particularly for programming pracitioners who didn’t learn it at school." -- Correct! I taught myself Basic, I taught myself a bit of x86 assembler, most importantly, I taught myself C. My working mental model of a computer is the C machine model. And even now, now that I know Ruby with its lambdas, I know that Ruby is written in C. And the Linux kernel. And Nginx (C++ maybe? Dunno). And on, and on.

Show me the tutorial where I can build, _in C_ a bare bones working (tail recursion) implementation of the lambda calculus with type inference and dependent (algebraic?) types and I'll shake your hand and call you a champion.

Closest I've seen is Make A Lisp - https://github.com/kanaka/mal but I don't think it has the sweet types and tail recursion and other good stuff. PS: bonus points if Regexen are native type :)

(Open to suggestions (I am))

If you're really interested in learning and grokking Lisp, you could do worse than trying to implement it yourself.

https://github.com/kanaka/mal

Fully working lisp in 10 (easy to not so easy) steps.

https://github.com/kanaka/mal

This is more than a weekend's worth of work, but the work is incremental, so you will see benefits from point 0. This was a lot of fun for me, and it helped shine light on some of the darker corners of Go.

I'm still working on a version of it myself, using it to experiment with different coding styles, interfaces, and libraries. A lot of fun.

Neat seeing the python and the lisp implementation next to each other. It reminds me of 'Make A Lisp'[0].

[0]: https://github.com/kanaka/mal