5 ms·
A Lisp in 99LOC
- OhMeadhbh 1y agoPreviously: * https://news.ycombinator.com/item?id=32100035 https://news.ycombinator.com/item?id=32100035 * https://news.ycombinator.com/item?id=32095655 https://news.ycombinator.com/item?id=32095655 and * https://BI6.US/CO/N/20250420.HTML#/042402 https://BI6.US/CO/N/20250420.HTML#/042402
- eqvinox 1y agoHoly cow this is —structurally, not just expression— some of the worst C code I have ever seen, with the abuse of the 'double' type, 'T' cast that looks like a declaration, endian dependency, and strict aliasing violations galore… does this even work on a modern compiler? o.O
- omoikane 1y agoIt does not, because there is a syntax error on line 81 (extra close parenthesis): https://github.com/Robert-van-Engelen/tinylisp/blob/2d0fb35b7bde11027384691aa34c3c2648945153/src/lisp850.c#L81C10-L81C11 https://github.com/Robert-van-Engelen/tinylisp/blob/2d0fb35b...
- Y_Y 1y agoBrought to you by this marvellous commit with the message "update", https://github.com/Robert-van-Engelen/tinylisp/commit/40c6c0462ac49b47bf239b544dc7f3feeb777bb3#diff-537de3a4eaf1685f9181ab8126e148407db2fdcb62afe2b6164b5c4456cc489aR18-L80 https://github.com/Robert-van-Engelen/tinylisp/commit/40c6c0...
- OhMeadhbh 1y agoYeah. It's munged to fit in 99 lines.
- eqvinox 1y agoThat's besides my point, which is why I said "structure, not just expression". It could've used a struct rather than wedging tags into a double's first byte and still be 99 lines.
- Spivak 1y agoIf that's the trick you object to then you will be sad to hear that Ruby uses it.
- fami-com 1y agoThat's a standard technique in interpreters. All non-toy Javascript engines use it, for example.
- cardiffspaceman 1y agoNan-boxing is awesome.
- messe 1y agoSurpringly readable though, despite all that, if you've ever implanted a language in similar constraints.
- messe 1y ago*implemented. Too late to edit now.
- f1shy 1y agoCertainly not the worst I have seen, by far; but yes, not pretty. IMHO “Just for making it shorter“. I would very much prefer 200 lines of actually readable nice code.
- sevensor 1y agoFor reading, I enjoyed fe, which was very clear: https://news.ycombinator.com/item?id=36239175 https://news.ycombinator.com/item?id=36239175
- f1shy 1y agoYes! Exactly what I meant. 700 lines, but of code that can be understood, and looks clearly as C. Also btw, the general file structure, the documentation, I prefer fe any day of the week. Thanks for pointing that out, I will take a look at it.
- curtisszmania 1y ago[dead]
- nivertech 1y agoA better starting point: https://github.com/Robert-van-Engelen/tinylisp/blob/main/tinylisp.pdf https://github.com/Robert-van-Engelen/tinylisp/blob/main/tin...
- lisper 1y agoLisp in ~100 lines of Python: https://flownet.com/ron/l.py https://flownet.com/ron/l.py
- f1shy 1y agoOr from the venerable: https://norvig.com/lispy.html https://norvig.com/lispy.html
- ginko 1y agoCan’t you just “import lisp”?
- lisper 1y agoUm, no? Python 3.11.6 (v3.11.6:8b6ee5ba3b, Oct 2 2023, 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import lisp Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'lisp'
- coderatlarge 1y agocan it execute the y-combinator?
- spyrja 1y agoIt doesn't appear to, but you could always add this to the included common.lisp file: (define Y (lambda (f) (lambda args ((f (Y f)) . args))))
- f1shy 1y agoI’m pretty sure does not handle TCO… so probably not, unless with a huge stack.
- gbacon 1y agoSee tinylisp-extras.c for TCO. https://github.com/Robert-van-Engelen/tinylisp/blob/2d0fb35b7bde11027384691aa34c3c2648945153/src/tinylisp-extras.c#L262 https://github.com/Robert-van-Engelen/tinylisp/blob/2d0fb35b...
- jhbadger 1y agoIt's interesting that he seems to have written this for a pocket computer, because there actually was a pocket computer of similar vintage that had LISP built in -- 1989's Casio AI-1000 https://pockemul.com/index.php/2020/04/27/pockemul-1-10-0-new-release/ https://pockemul.com/index.php/2020/04/27/pockemul-1-10-0-ne...
- forgotpwd16 1y ago>C code in this project is strongly Lisp-like in compact form Kinda reminds me J-flavored Whitney's one-page J interpreter.
- mark_l_watson 1y agoThe commented longer program listing was fun to read.