Re: Ternary operator?

"Newman, John W" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <EE3D0D387D01C8498EC1CED489DEAB253815873346@msxmbxnsprd01.acct.upmchs.net>
Ok, somewhat on subject what about short circuit evaluation?

[#if true || false ]
[#if false && true]

not until 2.4 also?


________________________________________
From: [email protected] [[email protected]] On Behalf Of Daniel Dekany [[email protected]]
Sent: Wednesday, May 07, 2008 7:52 PM
To: FreeMarker-user
Subject: Re: [FreeMarker-user] Ternary operator?

Wednesday, May 7, 2008, 10:04:21 PM, Newman, John W wrote:

> Hi,
>
> Just wondering what, if any, plans to support or existing support
> we have for the useful Boolean ? expr : expr construct…
>
> Currently I’m stuck with this 5 liner
>
> [#if pageNumber - numPagesToShow > 0]
>       [#assign firstPage = pageNumber – numPagesToShow /]
> [#else]
>       [#assign firstPage = 1 /]
> [/#if]
>
> Could be written as
>
> [#assign firstPage = pageNumber - numPagesToShow > 0 ? pageNumber - numPagesToShow : 1 /]
>
>
> Any plans to support this type of thing in the future?  Can I
> achieve this using something else now?  No big deal, just a bit more terse which is generally good.

The C/Java ternary operator is not really compatible with the FTL
syntax. However, starting from 2.4 we have LazilyEvaluatableArguments
feature, which would allow the implementation of the ternary operator
as a built-in, like: theCondition?iif(whenTrue, whenFalse).

> And the ++ and -- operators would be nice if supported also.

I would allow those only with #set. Like [#set x = x + 1] would be
equivalent with [#set x += 1] and [#set x++], where the += or ++ must
be the top-level (root) operator in the parse tree.

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