Hacker News new | past | comments | ask | show | jobs | submit login
7 lines of code, 3 minutes: Implement a programming language from scratch (might.net)
99 points by adg001 on June 28, 2010 | hide | past | favorite | 24 comments



For a fairly liberal definition of "from scratch", of course...


Obligatory Sagan quote: “If you want to make an apple pie from scratch, you must first create the universe.”


I'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.


Exactly. Once could say you can write all of perl in perl by using eval().


Sure, but the article doesn't use eval.


You make your own eval for the lambda calculus, so that's not entirely accurate ;)

Edit: (Yes I know the difference, and I changed the he to 'you')


Does (((λ f . (λ x . (f x))) (λ a . a)) (λ b . b))) reduce into the identity function?


Yes.


this looks suspiciously similar to my analysis of programing languages class


It 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-f...

(/article author)


Be 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)


If you went to the University of Utah, he probably taught it (http://matt.might.net/#teaching).


epic sms (small world syndrome) if this was his teacher


sws?


Unless you live in Australia.


I wonder: What's a minimal language in this vein with lisp-style macros?


That'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)


"Lisp macros need knowledge of the structure of the s-expression."

I recently rediscovered this for myself: http://arclanguage.org/item?id=11880


McCarthy'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


A lisp with T, NIL, if, and lambda, like "tiny-lisp" here:

http://tfeb.org/lisp/hax.html#CONDUITS

Literally, a package hack with zero implementation :-)

Import defmacro and friends and you have it.


A challenge: get something comparable to macros out of Forth.


I could be wrong – it’s been a while now – but isn’t that what forth’s “immediate” is?


Yeah, immediate words are executed during compilation.


How about a C version? Always feel that using scheme/lisp/etc is cheating a bit :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: