www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Macros: a visual aid.

reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
While I'm looking forward to 2.0 macros, I've already noted one thing: 
they look an awful lot like a CTF call.  Given:

macro Foo () { ... }
char[] Bar () { ... }

Foo();
Bar();

Can you tell a difference?  No?  Then we're on the same page.  :)

So I had an idea: why not decorate the macro invocation in some way to 
make it stand out, such as how template instantiation uses '!()' rather 
than '()'.  I don't think re-using '!()' would be a good idea at all, so 
I pondered alternatives and arrived at something that might be familiar 
to some... the ' ' sign.

macro Foo () { ... }
char[] Bar () { ... }

 Foo();
Bar();

Now that stands out!  So Walter, please consider some sort of decoration 
(such as the ' ') for macro invocations.  I think it may save some 
future headaches, /and/ give the parser something to latch on to.

-- Chris Nicholson-Sauls
Jul 08 2007
next sibling parent dennis luehring <dl.soluz gmx.net> writes:
Chris Nicholson-Sauls schrieb:
 While I'm looking forward to 2.0 macros, I've already noted one thing: 
 they look an awful lot like a CTF call.  Given:
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
 Foo();
 Bar();
 
 Can you tell a difference?  No?  Then we're on the same page.  :)
 
 So I had an idea: why not decorate the macro invocation in some way to 
 make it stand out, such as how template instantiation uses '!()' rather 
 than '()'.  I don't think re-using '!()' would be a good idea at all, so 
 I pondered alternatives and arrived at something that might be familiar 
 to some... the ' ' sign.
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
  Foo();
 Bar();
 
 Now that stands out!  So Walter, please consider some sort of decoration 
 (such as the ' ') for macro invocations.  I think it may save some 
 future headaches, /and/ give the parser something to latch on to.
 
 -- Chris Nicholson-Sauls

better Foo ()
Jul 08 2007
prev sibling next sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Chris Nicholson-Sauls wrote:
 Now that stands out!  So Walter, please consider some sort of decoration 
 (such as the ' ') for macro invocations.  I think it may save some 
 future headaches, /and/ give the parser something to latch on to.

Part of the intent of macros is to make them look just like functions! (There also isn't any parsing issue, like there is for template invocations.)
Jul 08 2007
next sibling parent reply "Kristian Kilpi" <kjkilpi gmail.com> writes:
On Sun, 08 Jul 2007 10:35:49 +0300, Walter Bright  
<newshound1 digitalmars.com> wrote:

 Chris Nicholson-Sauls wrote:
 Now that stands out!  So Walter, please consider some sort of  
 decoration (such as the ' ') for macro invocations.  I think it may  
 save some future headaches, /and/ give the parser something to latch on  
 to.

Part of the intent of macros is to make them look just like functions! (There also isn't any parsing issue, like there is for template invocations.)

That's right. Well, one option could be allowing macro names to contain some special char(s)? E.g. macro foo() {} macro bar () {} foo(); bar ();
Jul 08 2007
parent Walter Bright <newshound1 digitalmars.com> writes:
Kristian Kilpi wrote:
 On Sun, 08 Jul 2007 10:35:49 +0300, Walter Bright 
 Part of the intent of macros is to make them look just like functions! 
 (There also isn't any parsing issue, like there is for template 
 invocations.)

That's right. Well, one option could be allowing macro names to contain some special char(s)? E.g. macro foo() {} macro bar () {} foo(); bar ();

I suggest using the C convention of uppercasing the macro names. Seems to work fine.
Jul 08 2007
prev sibling parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Walter Bright wrote:
 Chris Nicholson-Sauls wrote:
 Now that stands out!  So Walter, please consider some sort of 
 decoration (such as the ' ') for macro invocations.  I think it may 
 save some future headaches, /and/ give the parser something to latch 
 on to.

Part of the intent of macros is to make them look just like functions! (There also isn't any parsing issue, like there is for template invocations.)

I'll take your word for it that there's no parser issue. You would know, after all. But... while I'm clearly an odd stand-out minority, I really just feel uncomfortable with macros as function look-alikes. I guess i'll just have to adopt some naming scheme to suffice... but that leaves me powerless if using a library's macros. Alas. -- Chris Nicholson-Sauls
Jul 08 2007
parent 0ffh <spam frankhirsch.net> writes:
Chris Nicholson-Sauls wrote:
 guess i'll just have to adopt some naming scheme to suffice... but that 
 leaves me powerless if using a library's macros.

I'm not quite sure if D2 will support this, but I suppose you'll be able to alias foreign macros with names that fit your personal gusto... :) Regards, Frank
Jul 08 2007
prev sibling next sibling parent Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Chris Nicholson-Sauls wrote:

 While I'm looking forward to 2.0 macros, I've already noted one thing:
 they look an awful lot like a CTF call.  Given:
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
 Foo();
 Bar();
 
 Can you tell a difference?  No?  Then we're on the same page.  :)
 
 So I had an idea: why not decorate the macro invocation in some way to
 make it stand out, such as how template instantiation uses '!()' rather
 than '()'.  I don't think re-using '!()' would be a good idea at all, so
 I pondered alternatives and arrived at something that might be familiar
 to some... the ' ' sign.
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
  Foo();
 Bar();
 
 Now that stands out!  So Walter, please consider some sort of decoration
 (such as the ' ') for macro invocations.  I think it may save some
 future headaches, /and/ give the parser something to latch on to.

I had an impression that one should be able to (more or less) transparently replace many builtin constructs like 'foreach' with macros eventually.
Jul 08 2007
prev sibling next sibling parent reply mwarning <foo bar.com> writes:
macro is a keyword, so it's highlighted in most D supporting editors.
That should tell the eyes the difference even faster then a special char.
Jul 08 2007
next sibling parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
mwarning wrote:
 macro is a keyword, so it's highlighted in most D supporting editors.
 That should tell the eyes the difference even faster then a special char.

You can't tell the difference at the call site. foo(); Is the above a macro or a function? -- Remove ".doesnotlike.spam" from the mail address.
Jul 08 2007
parent "Bent Rasmussen" <incredibleshrinkingsphere gmail.com> writes:
I really don't want to tell the difference there. Although it may be 
necessary to know at times. This problem falls under the domain of 
intelligent environments.


"Deewiant" <deewiant.doesnotlike.spam gmail.com> wrote in message 
news:f6qduv$12pn$1 digitalmars.com...
 mwarning wrote:
 macro is a keyword, so it's highlighted in most D supporting editors.
 That should tell the eyes the difference even faster then a special char.

You can't tell the difference at the call site. foo(); Is the above a macro or a function? -- Remove ".doesnotlike.spam" from the mail address.

Jul 09 2007
prev sibling parent reply 0ffh <spam frankhirsch.net> writes:
mwarning wrote:
 macro is a keyword, so it's highlighted in most D supporting editors.
 That should tell the eyes the difference even faster then a special char.

I think it was more about recognising the /invocation/ of the macro, not the definition: You see something that looks like a function call in a source file, later find it was a macro invocation. As for myself, I like my macros without a syntactic mark of cain. :) Regards, Frank
Jul 08 2007
parent reply Walter Bright <newshound1 digitalmars.com> writes:
0ffh wrote:
 As for myself, I like my macros without a syntactic mark of cain. :)

I'm going to steal that witticism! Thanks for the chuckle with my morning coffee.
Jul 08 2007
next sibling parent BCS <ao pathlink.com> writes:
Reply to Walter,

 0ffh wrote:
 
 As for myself, I like my macros without a syntactic mark of cain. :)
 

morning coffee.

MORNING coffee!?!?! You posted that after NOON! <G>
Jul 08 2007
prev sibling next sibling parent 0ffh <spam frankhirsch.net> writes:
Walter Bright wrote:
 0ffh wrote:
 As for myself, I like my macros without a syntactic mark of cain. :)

I'm going to steal that witticism! Thanks for the chuckle with my morning coffee.

Welcome! It is so good to be appreciated! :) Regards, Frank
Jul 09 2007
prev sibling parent "Bent Rasmussen" <incredibleshrinkingsphere gmail.com> writes:
Put it in the spec. ;-)

"Walter Bright" <newshound1 digitalmars.com> wrote in message 
news:f6rek7$a8g$2 digitalmars.com...
 0ffh wrote:
 As for myself, I like my macros without a syntactic mark of cain. :)

I'm going to steal that witticism! Thanks for the chuckle with my morning coffee.

Jul 09 2007
prev sibling parent reply janderson <askme me.com> writes:
Chris Nicholson-Sauls wrote:
 While I'm looking forward to 2.0 macros, I've already noted one thing: 
 they look an awful lot like a CTF call.  Given:
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
 Foo();
 Bar();
 
 Can you tell a difference?  No?  Then we're on the same page.  :)
 
 So I had an idea: why not decorate the macro invocation in some way to 
 make it stand out, such as how template instantiation uses '!()' rather 
 than '()'.  I don't think re-using '!()' would be a good idea at all, so 
 I pondered alternatives and arrived at something that might be familiar 
 to some... the ' ' sign.
 
 macro Foo () { ... }
 char[] Bar () { ... }
 
  Foo();
 Bar();
 
 Now that stands out!  So Walter, please consider some sort of decoration 
 (such as the ' ') for macro invocations.  I think it may save some 
 future headaches, /and/ give the parser something to latch on to.
 
 -- Chris Nicholson-Sauls

I like the fact that they look exactly like normal functions. It means you can change an interface to a function or macro without the user knowing. The only problem here of course is if macros work significantly different from their function counter part that it causes problems. -Joel
Jul 08 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
janderson wrote:
 Chris Nicholson-Sauls wrote:
 While I'm looking forward to 2.0 macros, I've already noted one thing: 
 they look an awful lot like a CTF call.  Given:

 macro Foo () { ... }
 char[] Bar () { ... }

 Foo();
 Bar();

 Can you tell a difference?  No?  Then we're on the same page.  :)

 So I had an idea: why not decorate the macro invocation in some way to 
 make it stand out, such as how template instantiation uses '!()' 
 rather than '()'.  I don't think re-using '!()' would be a good idea 
 at all, so I pondered alternatives and arrived at something that might 
 be familiar to some... the ' ' sign.

 macro Foo () { ... }
 char[] Bar () { ... }

  Foo();
 Bar();

 Now that stands out!  So Walter, please consider some sort of 
 decoration (such as the ' ') for macro invocations.  I think it may 
 save some future headaches, /and/ give the parser something to latch 
 on to.

 -- Chris Nicholson-Sauls

I like the fact that they look exactly like normal functions. It means you can change an interface to a function or macro without the user knowing. The only problem here of course is if macros work significantly different from their function counter part that it causes problems. -Joel

I like 'em to look like normal functions too. But I assume taking the address of a macro will fail. So "fptr = &foo;" will work on a function but not a macro. There are probably other way in which they will differ, but that seems to be the biggie to me. --bb
Jul 08 2007