HTCondor Project List Archives



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

Re: [Condor-devel] [classad-users] RFC: an implementation of classads enhanced with macro evaluation



On Mon, 2012-03-12 at 14:26 -0500, Alain Roy wrote:
> OK, I understand your goal, thanks. 
> 
> Two things strike me. 
> 
> First, there's a tradeoff between doing this in ClassAds and as a pre-processing step before it gets to ClassAds. Clearly you get more power if you can use ClassAd evaluation. But it's worth considering the tradeoff because it's also an extra complexity to the language.

The way it's done, you get both full evaluation power and
simplicity/clarity.  If you look at what's happening in the grammar, it
calls exactly the same evaluation routine that would be called by a user
to evaluate any expression.  The implementation in the parser is
actually very lean and easy to understand.

Order of evaluation is lexical, as you'd expect.  So when a macro
evaluates, it is evaluated with the values of variables as defined so
far in the parsing.  That includes scoping.  If you are inside some
nested classad, you get the innermost definition of any variable. (If a
variable hasn't yet been defined, then the macro will of course eval to
undefined.  If there is an error somewhere in an expr, it will evaluate
to error, etc)


> [
>   x = 5;
>   y = [ x = 6; y = $(x + 1); ];
>   z = [ y = $parent.x ]
> ]

So the innermost y gets = 7.  Then the outer y gets [ x=6; y=7 ].   Then
z = [ y = 5 ], although in that case you need $(parent.x), since
"parent" is not a variable name, it is a reserved word with a special
semantic that is different than a variable.


> x = $time()

For the above, you would do this:  $(time()).  You can do $var, or
$(expr).  They both really mean the same thing: evaluate an expression.
The variation $var is just shorthand for $(var).  If you leave off the
parentheses, the thing to the right of '$' must be a variable.


> 
> can I do this?
> 
> [
>   x = 3;
>   y = [ x = 4 ];
>   z = $x + $y.x; # should evaluate to 7? 

In this case, z will be assigned this expression:

z = 3 + [x=4].x

In other words, $x is expanded and $y is expanded.  So, further eval is
deferred, but if you later eval or lookup z, it will evaluate to 7.