Re: weird macro params issue
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, May 2, 2008, 7:18:44 PM, Attila Szegedi wrote:
> The order of populating defaulted variables is undefined -- they're
> being pulled out by an iterator out of a hash map. So if this worked
> for you, then you just had blind luck so far, I'm afraid.
>
> We could ensure the order going forward, or -- since with named-
> argument invocations there's not really any specific order -- even
> code it so that it fills out default expressions iteratively: go over
> them once, resolving what it can; then repeat until it gets an
> iteration where either (a) all default expressions got resolved or (b)
> it got something other than an InvalidReferenceExcepion or (c) it
> could not resolve any additional default expressions (and in this
> case, rethrow the InvalidReferenceException for one arbitrarily chosen
> unresolved default expression). That'd support any weird defaulting
> dependency order as long as there are no circular references, and
> circular references would also fall out with an
> InvalidReferenceException.
>
> Anyone object to having this logic in a subsequent FreeMarker release?
You mean, in 2.3.13, right? No objection on my side, and of course
only the iterative filling of the defaults will be good. The other
solution would be non-BC anyway.
I plan to wait with 2.3.13 until this and maybe ?round/?floor/?ceil
are added.
> Attila.
>
> On 2008.05.02., at 10:58, John Cherouvim wrote:
>
>> Hello
>>
>> I have this macro:
>> <#macro test a b=a c=b>
>> ${a} - ${b} - ${c}
>> </#macro>
>>
>> And this client code:
>> <@test 1 /><br/>
>> <@test 1 2 /><br/>
>> <@test 1 2 3 /><br/>
>>
>> Which produces:
>> 1 - 1 - 1
>> 1 - 2 - 2
>> 1 - 2 - 3
>>
>> Now if I just change the param names of the macro:
>> <#macro test foo bar=foo baz=bar>
>> ${foo} - ${bar} - ${baz}
>> </#macro>
>>
>> And keep the same client code, then the output produced is:
>> InvalidReferenceException: Expression bar is undefined on line 20,
>> column 31 in index.ftl.
>> 1 - 2 - 2
>> 1 - 2 - 3
>>
>> The first call fails when it tries to evaluate the baz=bar. Why is
>> that?
>>
>> Also, is this usage valid in freemarker? To have parameters default to
>> the value of other parameters. I find it very useful for some use
>> cases.
>>
>> thanks,
>> Ioannis
--
Best regards,
Daniel Dekany
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone