26 comments

[ 3.5 ms ] story [ 70.1 ms ] thread
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)

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

For a fairly liberal definition of "from scratch", of course...
Exactly. Once could say you can write all of perl in perl by using eval().
Sure, but the article doesn't use eval.
(comment deleted)
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')

Obligatory Sagan quote: “If you want to make an apple pie from scratch, you must first create the universe.”
(comment deleted)
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.

Does (((λ f . (λ x . (f x))) (λ a . a)) (λ b . b))) reduce into the identity function?
How about a C version? Always feel that using scheme/lisp/etc is cheating a bit :)