DIP 50 - AST macros

Zsombor Barna belzurix at sch.bme.hu
Thu Nov 14 13:40:42 PST 2013


On Thursday, 14 November 2013 at 21:12:11 UTC, Walter Bright 
wrote:
> On 11/14/2013 11:40 AM, deadalnix wrote:
>> This is not proposing to configure syntax.
>
> Right, it is about inserting arbitrarily different meaning into 
> existing syntax.
>
> For example, I have a friend from the middle east who worked at 
> Microsoft. His english was excellent. But sometimes he'd get 
> tripped up - for example, he'd take his idea to his boss, who'd 
> discuss it, and then say:
>
>     "fine"
>
> He took that to mean "my boss approves of my great idea!" 
> Unfortunately, "fine" has undergone a meaning reversal 
> colloquially, and actually means "your idea sux". This wound up 
> getting him into trouble. There were a few other phrases like 
> this with unintentionally hilarious misunderstandings.
>
> (Also, a popular way of encrypting communications is to have 
> private meanings for phrases like "my cat ate my homework" 
> meaning "initiate Operation X".)
>
> Now, let's take the AST macros, and pass it "4+3". Apparently 
> is a feature that the macro can transform this to produce 
> "hello" as the result. The result is that although the language 
> looks the same, there is no "anchor" a person can rely on to 
> indicate the meaning. The meaning of "fine" is reversed, so to 
> speak.
>
> The riposte is, of course, every feature can be abused and good 
> programmers won't do that. Unfortunately, it's IN THE VERY 
> NATURE of macros to be abusive, and even the very best 
> programmers can and will take it to the limit. They will see 
> and decry the abuse in everyone else's code but their own, 
> which they will justify. As I said, I see this over and over 
> again.
>
> On the other hand, with string mixins, it is immediately 
> obvious that one is dealing with different syntax, and so 
> expect something different to happen.

You have a point with the example, but just as with templates ( 
the distinctive binary ! operator), making macros not to look 
first class language elements when called does great job with 
readability. #-s or ×-s are just good for this, even if it look 
very foreign.

#loop ( ) {
   -- code --
}

Maybe for macros that return macros it would be ugly:
#(#macro1(params1))(params2);

But just as in C where the -> operator automatically dereferences 
pointers, it could be solved.
# macro1(params1) =#= (params2);
(Just for fun)


More information about the Digitalmars-d mailing list