Skip to content

Comment on Thank you pg and rtmparent

Comments

"I could imagine a Smalltalk function that takes a method, applies a Rewrite Tool syntactic transformation to its source, compiles the method as a Block, then calls this Block with the arguments that would've been send to the original method."

I don't understand what you said, but in non-hygenic Lisp macros (the kind you get in CL, Arc, and Clojure) a macro is simply a function that expands into code before being compiled or evaluated. You can almost think of it as an extremely clever query-replace functionality in your text editor that always happens before you compile or run your program.

This is why so many Lispers claim that Lisp is at the top of the heap when it comes to language power. If you can arbitrarily expand your code into some other form at compile time, you can pretty much do anything any other language can do. A canonical example of this is that the object system added to Common Lisp is just a bunch of macros. Name your programming paradigm, and there's a very good chance someone has implemented it in Lisp, with macros.

What you describe sounds more complex than Lisp macros, which brings us to the necessity of all the parentheses. The idea of macros only works well when the language is built up out of a data-structure supported by the language. In Lisp, of course, programs are lists and macros let you do anything to your program that you can do to a list. When people try to add "macros" to languages where the code is not a data structure, there usually needs to be some intermediate representation of the parse tree, and then things tend to start getting ugly as the relation to what the source code would look like is quickly lost.

Having said all that, I'm curious if anyone that knows both Smalltalk and Lisp can name concrete examples of programming in Smalltalk and finding something you were unable to do without macros.

The Rewrite Tool meta-syntax allows you to do a few nifty things. It is also "an extremely clever query-replace functionality" and in the scheme I proposed, you could "decorate" a function, such that a transformed version is called at runtime.

The Rewrite Tool also gives you access to the Smalltalk Parse Tree, though this isn't quite as pretty as Lisp's. However, you can very easily apply a Visitor to your AST. Perhaps even better, there's also a { : ... } syntax for executing arbitrary Smalltalk code to do your transform.

which brings us to the necessity of all the parentheses

Yes, Lisp is it's own AST! That's amazingly brilliant! Makes software toolsmithing equivalent to just plain programming.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.