6 ms·
7 lines of code, 3 minutes: Implement a programming language from scratch
- akkartik 16y agoI wonder: What's a minimal language in this vein with lisp-style macros?
- mahmud 16y agoA lisp with T, NIL, if, and lambda, like "tiny-lisp" here: http://tfeb.org/lisp/hax.html#CONDUITS http://tfeb.org/lisp/hax.html#CONDUITS Literally, a package hack with zero implementation :-) Import defmacro and friends and you have it.
- fadmmatt 16y agoThat's a good question, actually. Lisp macros need knowledge of the structure of the s-expression. Certainly one can Church encode s-expressions and provide defmacro. Gensym is trickier. Hygiene might be really challenging. I might actually try that out. (/article author)
- akkartik 16y ago"Lisp macros need knowledge of the structure of the s-expression." I recently rediscovered this for myself: http://arclanguage.org/item?id=11880 http://arclanguage.org/item?id=11880
- fogus 16y agoMcCarthy's original could give you macros, although they would be extremely cumbersome. I've been wanting to implement some sort of macro system in my minimal Lisp impl. http://github.com/fogus/lithp http://github.com/fogus/lithp
- stcredzero 16y agoA challenge: get something comparable to macros out of Forth.
- celoyd 16y agoI could be wrong – it’s been a while now – but isn’t that what forth’s “immediate” is?
- silentbicycle 16y agoYeah, immediate words are executed during compilation.
- inquisitor20 16y agothis looks suspiciously similar to my analysis of programing languages class
- jorgeortiz85 16y agoIf you went to the University of Utah, he probably taught it (http://matt.might.net/#teaching http://matt.might.net/#teaching).
- messel 16y agoepic sms (small world syndrome) if this was his teacher
- raghus 16y agosws?
- petercooper 16y agoUnless you live in Australia.
- fadmmatt 16y agoIt will look suspiciously similar to the Scripting Language Design and Implementation class that I'll be teaching. This kind of stuff also showed up in my program analysis and advanced compiler classes, too. One of the class projects was to implement first-class macros, and we used an interpreter that looked a lot like the one from this article: http://matt.might.net/articles/metacircular-evaluation-and-first-class-run-time-macros/ http://matt.might.net/articles/metacircular-evaluation-and-f... (/article author)
- dugmartin 16y agoBe glad you didn't go to school 20 years ago. I had to build a Lisp-1 REPL in Pascal on an IBM mainframe without a debugger for my programming languages class. (I also had to walk to class barefoot in the snow uphill both ways)
- ramchip 16y agoFor a fairly liberal definition of "from scratch", of course...
- Periodic 16y agoI'm often annoyed that between language theory and language implementation there is the trouble of lexing and parsing. Both are complex and take a lot of time and know-how (at least for me as they never work right the first time), and it's not until you have those done that you can actually work on language features. Lisp is handy from it's data-is-code mentality it already has a general-purpose parser built in. It's something that is fairly easy to implement for functional languages which is much harder to implement for OOP languages.
- someone_here 16y agoExactly. Once could say you can write all of perl in perl by using eval().
- Hoff 16y agoObligatory Sagan quote: “If you want to make an apple pie from scratch, you must first create the universe.”
- deleted 16y ago
- johkra 16y agoDoes (((λ f . (λ x . (f x))) (λ a . a)) (λ b . b))) reduce into the identity function?
- fadmmatt 16y agoYes.
- brianobush 16y agoHow about a C version? Always feel that using scheme/lisp/etc is cheating a bit :)