[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macros vs. blocks

On Friday, November 22, 2002, at 02:26  AM, Trevor Blackwell wrote:

> John Clements <clements@brinckerhoff.org> writes:
>> Hmm.  If you consider the three largest categories of macros [*] to be
>> 1) those that affect evaluation order (if),
>> 2) those that introduce literal data (quote), and
>> 3) those that introduce bindings (let),
>> I don't see how block notation solves any other than category (1).
> I would refine my macros-are-useless claim a bit: languages that 
> already
> have syntax for things such as assignment, variable declaration, and
> quoted data (Python, Perl, Smalltalk, ...) don't benefit much from
> macros.
> Using macros for #2 is probably a bad idea. I think it's generally
> clearer to include the ' symbol (or whatever your favorite language
> uses) than to have some arguments be magically quoted.

Your use of ' indicates to me that you're speaking of Scheme here.  You 
may be surprised to discover that ' is (in some scheme systems) 
translated into (quote ...).  That is, the ' _becomes_ an instance of 
the thing you're protesting.

> Using macros for #3 is also usually a bad idea. Having macros like CL
> (do) or (while), which magically introduce a variable with non-obvious
> scoping, is hazardous. I'd rather just have one way of declaring
> control-structure variables, like Smalltalk:
>   list do: [:x |
>       x print.
>   ].
> where it's totally obvious what the scope of the variable is. Scheme
> succeeds here too, because it uses lambda semantics everywhere.

Again, you like what Scheme does, but the typical implementation for 
'let' is in fact exactly the sort of macro form I mention.

The difference between 'let' and CL's 'while' seems to be one of 
hygiene.  I agree that macros should be hygienic.

Ultimately, what you seem to be saying (if I can put words in your 
mouth) is that macros are okay, but only if they're part of the 
language definition.

john clements