Parameters defaulting to another [Was: Re: fmdoc - JavaDoc-like comments for FreeMarker]

Felix Gnass <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
On May 17, 2008, at 0:40 , Denis wrote:

>
>> Hi Denis,
>>
>> I suppose you talking about the second parameter's default being the
>> value of the first one?
>
> Yes, but not for the reason you state.
>
> According to Jonathan
> "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."
>
> I went and checked you code, and sure enough you have:
>
> <#macro label for field=for errorClass="error" code="" attributes...>
>
> Try renaming field to for, for to field...
> It may even be VM dependent unless Sun standardized string hashes for
> some reason.
>
> -- Denis.


I see. I assumed that parameter defaults would be evaluated in the  
order of declaration, as this (coincidently) matched my observations.  
So for now the only sane workaround I can think of would be:

<#macro foo bar baz="">
   <#if !baz?has_content>
     <#local baz = bar />
   </#if>
   ...
</#macro>


Is there any chance that we'll see support for that feature in a  
future release? I think it would be a valuable addition to the  
FreeMarker language.

-Felix

>
>
>> By unreliable you mean that this will lead to
>> unexpected results when there is a variable called "bar" in the same
>> (or global) namespace? If this is the case, is there a more reliable
>> way to do it?
>>
>> Thanks for pointing this out,
>> -Felix
>>
>>
>> On May 16, 2008, at 3:33 , Denis wrote:
>>
>>> Hi Felix
>>>
>>> Does your library rely on the undocumented, unreliable
>>>
>>> <#macro foo bar baz=bar>
>>> ?
>>>
>>> -- Denis. 
>>>
>>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.