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.
Lisp in fewer than 200 lines of C
101–108 of 108 posts
Re: Lisp in fewer than 200 lines of C
#102Earlier 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.
Re: Lisp in fewer than 200 lines of C
#103Earlier 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.
Re: Lisp in fewer than 200 lines of C
#104Earlier 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.
Re: Lisp in fewer than 200 lines of C
#105Earlier 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
Then again, inline does not mean what most people think.
Re: Lisp in fewer than 200 lines of C
#106Your opinion is welcome. Alain Marty
Re: Lisp in fewer than 200 lines of C
#107If 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
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):
Re: Lisp in fewer than 200 lines of C
#108If 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.
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!