Re: weird macro params issue

Jonathan Revusky <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Jonathan Revusky wrote:
> On Fri, May 2, 2008 at 7:18 PM, Attila Szegedi <[email protected]> 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?
> 
> Just offhand, I wouldn't encourage anybody to do something like that.
> It surprised me that it worked at all, actually. I would have to look
> at the implementation. It seems to me that the default parameters
> should be evaluated in the scope of the enclosing namespace and thus,
> what Ioannis was doing should fail.
> 
> Now, of course, the current situation, that it works sometimes and
> other times doesn't work, that's extremely undesirable. But to be
> honest, it seems like such an overly intricate, excessively clever way
> of doing things, that I would prefer for it just to always fail. :-)
> 
> I mean, seriously, is this coding pattern actually useful?
> 
> Of course, it would be better if it always worked than if it always
> failed, 

I misspoke above. I meant, here, that it would be better if it always 
worked than if it worked some of the time and failed other times. I 
mean, it should always work or always fail... :-)

JR
but I think I would just tend towards it always failing.
> 
> JR
> 
> 
> 
>>
>>  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
>>  _______________________________________________
>>  FreeMarker-user mailing list
>>  [email protected]
>>  https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>
> 


-------------------------------------------------------------------------
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.