Ted Leung on the air
Ted Leung on the air: Open Source, Java, Python, and ...
Ted Leung on the air: Open Source, Java, Python, and ...
Sat, 10 May 2003
macros vs keyword messages
It's great when you actually learn something new, and I seem to do that quite frequently in the weblog world. Here's today's:
Patrick Logan, who I remember from comp.lang.dylan days, had this to say about syntax extension:
[00:12] |
[computers/programming/lisp] |
# |
TB |
F |
G |
3 Comments |
While Smalltalk doesn't have syntax macros like Lisp, Smalltalk *does* have simpler block syntax and keyword arguments.This use of keyword messages and closures is really interesting. In Chapter 8 of On Lisp, Graham lists 6 reasons to use macros. Delaying or altering evaluation is an aspect of the first 4 reasons. Reason 5 involves using the calling environment, which you very rarely want to do, reason 6 involves using a new lexical environment, which you also rarely want to do, and reason 7 is inlining which is a performance annotation. I'd be curious to see some examples of this type of Smalltalk code.The effect is that new keyword messages can take block closures, which essentially delay evaluation until the method behind the message decides to evaluate them, and the message send looks an awful lot like new syntax, very clean.
Many uses of macros in Lisp, frankly, are simply created to hide the appearance of the lambda keyword. Of course there are more "legitimate" uses of macros, but these are less common.
Ted%2C%0D++In+response+to+your+request+for+a+Smalltalk+example+of+code+using+block+closures+as+a+substitute+for+language+macros%2C+take+a+look+at+the+following%3A%0D%0Dhttp%3A%2F%2Fwww%2Ewhysmalltalk%2Ecom%2Farticles%2Fdemers%2Fprojectwhere%2Ehtm
Posted by Rich Demers at Sat May 10 05:42:41 2003
Posted by Rich Demers at Sat May 10 05:42:41 2003
Ted,
In response to your request for a Smalltalk example of code using block closures as a substitute for macros, take a look at the referenced page.
Sorry about the formatting of that last comment. I was using a different tool to send a comment.
Rich Demers
Posted by Rich Demers at Sat May 10 05:47:14 2003
In response to your request for a Smalltalk example of code using block closures as a substitute for macros, take a look at the referenced page.
Sorry about the formatting of that last comment. I was using a different tool to send a comment.
Rich Demers
Posted by Rich Demers at Sat May 10 05:47:14 2003
Let's try Rich's link again:
http://www.whysmalltalk.com/articles/demers/projectwhere.htm
In that article, Rich demonstrates some of what you were asking about.
Posted by James Robertson at Sat May 10 09:39:37 2003
Posted by James Robertson at Sat May 10 09:39:37 2003
You can subscribe to an RSS feed of the comments for this blog:
Add a comment here:
You can use some HTML tags in the comment text:
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
<a href>
, <em>
, <i>
, <b>
, <blockquote>
, <br/>
, <p>
, <code>
, <pre>
, <cite>
, <sub>
and <sup>
.You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk