Re: Pass through of optional parameters

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, May 14, 2008, 10:01:00 AM, Attila Szegedi wrote:

> *Sigh*. No, you can't do it, as FreeMarker mandates that all  
> expressions used as arguments to a macro invocation resolve to a  
> defined value. I wish we'd change that, at least for optional arguments.
>
> Jonathan, Daniel - opinions?

I my un-implemented language there is, shown with FTL syntax:

  <@theMacro theParam!noarg>

So, there was special value (special like null is) that means that the
parameter (or list/map item!) is omitted. Overly smart, one could
say... but also quite useful. But it still doesn't solve that the user
has requested in this thread. The thing is, if you do know that a
variable potentially missing, you have to indicate that in the source
code every thing you refer to that variable; it has trivial
maintainability related reasons, so I'm reluctant to give it up. I
don't see how could it be a reason to relieve this rule that the
variable reference happens to be used as a parameter. Now, in the case
of FreeMarker 2.3, the problem is, that even if the user accepts this
philosophy of strictness, he simply can't indicate that "I know this
variable is possibly missing, and in that case please consider the
whole parameter being omitted". But starting from FreeMarker 2.4, you
can write theParam?null. It's a dirty solution, as it doesn't exactly
behave as if the parameter were omitted, but practically it will be OK
on the quality standard where FreeMarker lives.

> Attila.
>
> On 2008.05.13., at 20:53, Troy Daniels wrote:
>
>>>
>>> I have a macro with an optional parameter:
>>>
>>> <#macro term source result op context optional...>
>>>    do stuff, possibly using ${optional.root} </#macro>
>>>
>>> This is called indirectly by another macro.
>>>
>>> <@indirectCall root=someValue />
>>>
>>> <#macro indirectCall optional... > stuff <@term source=s result=r  
>>> op=o
>>> context=c ???/> </#macro>
>>>
>>> I'd like to pass through the optional parameter when it's given to
>>> indirect.  At the moment, the best way that I can see to do that is
>>>
>>> <#macro indirectCall optional... >
>>>  stuff
>>>  <#if optional.root??>
>>>     <@term source=s result=r op=o context=c root=optional.root />
>>>  <#else
>>>     <@term source=s result=r op=o context=c  />
>>>  </#if>
>>> </#macro
>>>
>>> Is there a more concise way of doing this?  I tried <@term {other
>>> args} optional=optional>, but that just meant that the optional map  
>>> in
>>> @term had a key called optional, pointing to the map I wanted it to
>>> be.
>>>
>>> I can write it like this, but it rather clutters macros that aren't
>>> trying to do anything except convey the optional parameters down.
>>> It'll get even more cluttered if I add a second optional parameter.
>>>
>>> Troy
>>
>>
>> Also, does anyone know if the
>> [email protected] address is active?  I  
>> tried
>> posting this from my work account (which receives messages just fine)
>> but I got a bounce message like I wasn't subscribed.  I sent mail  
>> there
>> asking about the problem, but I haven't heard back from it.

-- 
Best regards,
 Daniel Dekany


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