Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017 Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
<== Date ==> <== Thread ==>

Subject: Re: macro question
From: Andrew Johnson <anj@aps.anl.gov>
To: <tech-talk@aps.anl.gov>
Date: Fri, 27 Jan 2017 17:00:54 -0600
Hi Rolf,

On 01/27/2017 03:31 PM, Rolf Keitel wrote:
> a) A macro instance can also provide a default value that is used when
> no macro with the given name has been defined. The default value can
> itself be defined in terms of other macros if desired, but may not
> contain any unescaped comma characters. The syntax for specifying a
> default value is as follows:
>   $(name=default)
> 
> This seems to be clear: default value is used, if macro "name" is not
> defined.
> 
> b)  Finally macro instances can also contain definitions of other
> macros, which can (temporarily) override any existing values for those
> macros but are in scope only for the duration of the expansion of this
> macro instance. These definitions consist of |name=value| sequences
> separated by commas, for example:
> 
> $(abcd=$(a)$(b)$(c)$(d),a=A,b=B,c=C,d=D)
> 
> 
> Am I correct that  is *not* a default value like in a), but that this
> expansion always happens and overrides a definition of the macro "abcd"?

No, if $(abcd) is already defined then its current value will be used;
if not defined the expanded string after the first '=' sign will be
returned. However if $(abcd) were already set to $(d)$(c)$(b)$(a) then
the expansion above would generate DCBA, not ABCD, irrespective of any
current values of the macros $(a)..$(d).

Thus if any of the $(a)..$(d) macros are already defined their existing
values will be hidden by their newly assigned value for the purposes of
evaluating the macro expression before the first comma, then restored
again when the expression's closing parenthesis is reached.

You can re-use the old macro values if you want to in the assignment of
the same or earlier macros in the list, but by the time it's setting the
value for $(b) your $(a) macro will have already been set to 'A'.

If you want an expression that always expands, omitting the name before
the first = sign usually works although it is actually possible to set a
macro with no name, which would then override the default value of any
such expression...

Running 'msi' with no arguments is a good way to test this stuff out, it
reads from stdin and writes the expanded results to stdout. You can also
use the -Mvar=value option to set predefined macros.

Various examples demonstrating my points above:

> tux% msi -MQ=A,abc=abc,a=a,b=b
> $(Q): $(abc=$(a)$(b)$(c),a=A,b=$(a),c=$(b))
> A: abc
> $(Q): $(=$(a)$(b)$(c),a=A,b=$(a),c=$(b))
> A: AAA
> $(Q): $(=$(a)$(b)$(c),a=$(b),b=$(c),c=C)
> A: bCC
> $(Q): $(=$(a)$(b)$(c),a=$(a),b=$(b),c=C)
> A: abC

> tux% msi '-MQ=A,abc=$(c)$(b)$(a),a=a,b=b,c=c'
> $(Q): $(abc)
> A: cba
> $(Q): $(abc=$(a)$(b)$(c),a=A,b=B,c=C)
> A: CBA
> $(Q): $(=$(a)$(b)$(c),a=A,b=B,c=C)
> A: ABC

> tux% msi -MQ=A,=1234
> $(Q): $(=abcd)
> A: 1234
> $(Q): $(=abcd,=999)
> A: 999

HTH,

- Andrew

-- 
Arguing for surveillance because you have nothing to hide is no
different than making the claim, "I don't care about freedom of
speech because I have nothing to say." -- Edward Snowdon

References:
macro question Rolf Keitel

Navigate by Date:
Prev: macro question Rolf Keitel
Next: Spring EPICS meeting in May at KURRI, Osaka, Japan 上窪田@KEKTokai
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
Navigate by Thread:
Prev: macro question Rolf Keitel
Next: Spring EPICS meeting in May at KURRI, Osaka, Japan 上窪田@KEKTokai
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
ANJ, 14 Feb 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·