Live data from Hacker News

Lisp in fewer than 200 lines of C

carld.github.io

101–108 of 108 posts

Re: Lisp in fewer than 200 lines of C

#101
post #82

Earlier quoted context omitted.

Even better if you make it: template constexpr bool is_space(const T & x) { return x == ' ' || x == '\n'; } Debuggable, type safe and same performance as straight C code.

And throw an `inline` in there just to be more likely to end up with something macro-like.

“inline” is more about linkage than about actual inlining. The compiler will in-line regardless of that attribute.

Re: Lisp in fewer than 200 lines of C

#102
post #96
post #80

Earlier quoted context omitted.

Nope. It still can be an atom. Only if it's a pair (i.e. a cons with two cells, not just one) it prints the next.

Even if that were possible (and with this codebase, I don't think it is), I don't see any code in this function that would print the atom in such a case. It seems like it would just print nothing.

Look harder, it does. There are only cons (pair) and atoms.

Re: Lisp in fewer than 200 lines of C

#103
post #102
post #96

Earlier quoted context omitted.

Even if that were possible (and with this codebase, I don't think it is), I don't see any code in this function that would print the atom in such a case. It seems like it would just print nothing.

Look harder, it does. There are only cons (pair) and atoms.

Can you give me an example program that, when fed as input, would cause this if-statement to evaluate to false?

Re: Lisp in fewer than 200 lines of C

#104
post #102
post #96

Earlier quoted context omitted.

Even if that were possible (and with this codebase, I don't think it is), I don't see any code in this function that would print the atom in such a case. It seems like it would just print nothing.

Look harder, it does. There are only cons (pair) and atoms.

The author just confirmed, the if-statement does nothing: https://github.com/carld/micro-lisp/issues/9

Re: Lisp in fewer than 200 lines of C

#105

Earlier quoted context omitted.

And throw an `inline` in there just to be more likely to end up with something macro-like.

`constexpr` is implicitly `inline`: http://en.cppreference.com/w/cpp/language/inline

orthogonally, templates are also implicitly inline.

Then again, inline does not mean what most people think.

Re: Lisp in fewer than 200 lines of C

#107

If you like this, you might like Lisp interpreter written in assembly in a single file. It is one of the best commented code ever written imo. https://github.com/marcpaq/arpilisp

It seems like arpilisp is inspired by jonesforth[0]. Although not directly stated, the style is similar and the acknowledgements mentions Richard Jones. Anyone interested in implementing simple programming languages might also want to take a look at jonesforth. [0]: https://github.com/nornagon/jonesforth

Arpilisp author here.

Yes, jonesforth definitely inspired and influenced me; that's why Jones is first in the Acknowledgements section.

If you're curious, I keep a list of single-file implementations of programming languages (including jonesforth):

https://github.com/marcpaq/b1fipl

Re: Lisp in fewer than 200 lines of C

#108

If you like this, you might like Lisp interpreter written in assembly in a single file. It is one of the best commented code ever written imo. https://github.com/marcpaq/arpilisp

Since this is written in assembly is it much faster than a C version since this one can manage its own stack frames and stack variables and such? I always imagined that’s the case and that a lisp implemented fully in assembly would be the trick to a super fast lisp that can complete with Go.

Arpilisp author here.

If you were to implement the same Lisp in C then compare, then maybe the assembly variant would be faster for the reasons you mention. Or maybe not.

Also, I modeled arpilisp after the original Lisp. That's barely a first step, and possibly the wrong first step, for anything non-trivial, including applications requiring a "super fast lisp that can compete with Go."

But I didn't write arpilisp for performance. I wrote it to learn and share. Enjoy!

Post reply on HN