Re: Ternary operator?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
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