On Sun, Oct 12, 2008 at 8:31 PM, Byron Foster <[EMAIL PROTECTED]> wrote:
> From my perusal the way the macro implementation works is that all
> parameters passed to a macros are AST, even if they are in quotes.  This is
> consistent with pass by name.  And anyway, if the string was evaluated
> before being passed then that doesn't explain the behavior of the second
> macro where $i is modified with #set directives instead of #foreach.
>  Shouldn't the results be the same?
>
> I could simplify the call with no quotes:
>
> #test( [1, 2, 3] #if($i=2)yes#end)
>
> Which with the first macro returns nothing and with the second macro returns
> "yes"
>
> But, even without using directives (Which is probably what I should have
> done):
>
> #macro(test $x)#foreach($i in [1, 2])$x#end#end
> #test($i)
>
> returns: $i$i
>
> #macro(test $x)#set($i = 1)$x #set($i = 2)$x#end
> #test($i)
>
> returns: 1 2
>
> On a side note... the following generates a parse error.. Is this correct?
>
> #macro(test $x)#set($i = 1)$x#set($i = 2)$x#end
>
> Encountered "=" at line 6, column 38 of /foo.vm
> Was expecting:
>    <RPAREN> ...

no that's not correct.  looks like a parser bug. ugh.

> On Oct 12, 2008, at 19:08 , Will Glass-Husain wrote:
>
>> I would have assumed the quoted string would be evaluated before being
>> passed in to the macro.  Hence $i is invalid reference when it is
>> evaluated,
>> and we'd always see "no no no".
>>
>> WILL
>>
>> On Sun, Oct 12, 2008 at 5:17 PM, Byron Foster <[EMAIL PROTECTED]> wrote:
>>
>>> I went back and pulled the velocity source to the revision (471881)
>>> before
>>> the changes to bug 285 and found that the behavior is as expected, so I
>>> conclude this is a bug :) which has been created here:
>>>
>>> https://issues.apache.org/jira/browse/VELOCITY-630
>>>
>>>
>>> On Oct 10, 2008, at 17:04 , Byron Foster wrote:
>>>
>>> Given the following:
>>>>
>>>> #macro(test $a $b)
>>>> #foreach($i in $a) $b #end
>>>> #end
>>>> #test( [1, 2, 3] "#if($i == 2) yes #else no #end")
>>>>
>>>> I would expect the output:
>>>>
>>>> no  yes  no
>>>>
>>>> Instead, I get
>>>>
>>>> no  no  no
>>>>
>>>> However, if I have
>>>>
>>>> #macro(test $a $b)
>>>> #set($i = 1) $b #set($i = 2) $b #set($i = 3) $b
>>>> #end
>>>> #test( [1, 2, 3] "#if($i == 2) yes #else no #end")
>>>>
>>>> then I get:
>>>> no  yes  no
>>>> as expected.
>>>>
>>>> I would say there is a bug here.  The Foreach directive explicitly sets
>>>> $i
>>>> in the localscope.  If I replace the explicit put to the localscope with
>>>> a
>>>> regular put, the first macro case works.  I was looking at the following
>>>> issues where the modification to Foreach was mode.
>>>>
>>>> https://issues.apache.org/jira/browse/VELOCITY-285
>>>>
>>>> Now, my test change to Foreach breaks issue 285, but I'm not convinced
>>>> that the resolution to 285 is complete.  Thoughts?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to