Date: Fri, 19 Oct 2007 17:35:40 +0000
Reply-To: Paul Dorfman <sashole@BELLSOUTH.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <sashole@BELLSOUTH.NET>
Subject: Re: positional macro parameter as keyword
It *is* useful, if only to bring to attention the often missed fact that in a macro call, a positional parameter can be used keyword-style (and not the other way around, of course). Thus to those maintaining that keyword parms are superior from the standpoint of code clarity, one could say that if a macro with positional parms is invoked keyword-style, there is no harm defining the parms as positional: since when one is trying to discern what the macro is doing, the macro call is viewed before the definition.
There are a few things in programming falling under the category always/never - for example, ubiquitous hard coding - because they make huge sense from the standpoint of defensive programming and help avoid lots of potential grief. Then there are things deemed to fall into this category just because some folks fail to fully understand how they work and, having been burned once or twice, resort to the always/never modus operandi masked behind the cover of defensive programming.
A typical representatives of this latter class are "never GOTO", "never couple LAG with IF", and, yes, "always use keyword parameters". Whilst it is generally a sound advice, there are still situations when positional parms may be personally preferable (even if only aesthetically) and work just as well.
-------------- Original message ----------------------
From: Guido T <cymraegerict@GMAIL.COM>
> Something similar used to be in the "gotcha" test we did for SAS programmer
> Given the following code ...
> %macro m(x);
> %put &x.;
> What would you expect to see in the log ...
> 1 %macro m(x);
> 2 %put &x.;
> 3 %mend;
> 5 %m(a);
> *6 %m(x=b);
> *7 %m(x=b=c);
> Not a very useful test :)
> ++ Guido
> On 19/10/2007, firstname.lastname@example.org <email@example.com> wrote:
> > It's more than 20 years ago since I wrote my first macro. But today I
> > (inadvertently) discovered that you can refer to a positional
> > parameter as a keyword, provided you use the right name. For example:
> > %macro test(data);
> > %put data=&data;
> > %mend;
> > %test(demo);
> > %test(data=demo);
> > This prints 'demo' to the log in both cases. Could be a useful feature
> > sometimes. Am I the only one in the dark about this feature?
> > John Hendrickx