That was comparing Smalltalk to C#, but it is a similar idea. Smalltalk and Lisp belong to that elite fraternity of programming languages where the ability to easily extend the syntax is built into the language. The mechanisms are different, but the expressive power is similar.
Well, I've heard that Blocks get you most of the way to Macros, but not quite. I'm wondering if the "not quite" part is something beyond what's afforded by the Rewrite Tool.
The Rewrite Tool is not dynamic. Perhaps this is the key? But 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.
"Order of Blocks reversed"
``@rcv
ifTrue: `Block2
ifFalse: `Block1
Just be careful to cache the result of the compilation by method name and Class, and this wouldn't be too much slower than a conventional #perform:
This particular example would let you dynamically call any method, but with all of the if-then-else equivalents with the then and else clauses swapped.
"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.
Comments
Yes, there was a recent article on HN about "your language features are my libraries."
http://blog.bitquabit.com/2009/05/20/your-language-features-...
That was comparing Smalltalk to C#, but it is a similar idea. Smalltalk and Lisp belong to that elite fraternity of programming languages where the ability to easily extend the syntax is built into the language. The mechanisms are different, but the expressive power is similar.
Well, I've heard that Blocks get you most of the way to Macros, but not quite. I'm wondering if the "not quite" part is something beyond what's afforded by the Rewrite Tool.
The Rewrite Tool is not dynamic. Perhaps this is the key? But 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.
Something like:
Where aMatchingPattern would be something like: Then aRewritePattern could be something like: Just be careful to cache the result of the compilation by method name and Class, and this wouldn't be too much slower than a conventional #perform:This particular example would let you dynamically call any method, but with all of the if-then-else equivalents with the then and else clauses swapped.
Would this constitute Smalltalk Macros?
"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.