Re: weird macro params issue

Attila Szegedi <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
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?

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


-------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.