Re: exp?[whenTrue, whenFalse] instead of exp?choose(whenTrue, whenFalse)
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <[email protected]> |
Monday, December 24, 2012, 7:43:47 PM, Denis Bredelet wrote:
> Hi Daniel,
>
>> I had a proposal to add exp?choose(whenTrue, whenFalse) in some of the
>> next 2.3.x releases earlier. This is a substitute for the Java ternary
>> operator, so it only evaluates one of its parameter expressions.
>>
>> I think it should just become exp?[whenTrue, whenFalse] instead. Some
>> may accuse me of perlism for that... But I think this is a frequent
>> enough operation to warrant a dedicated operator.
>
> Is this backward compatible?
Yes.
> What happens when you write it in a template with current version?
It's a parsing error, as only <ID> can come after `?`.
--
Best regards,
Daniel Dekany
> -- Denis.
>
>> If you disagree, you might have to consider something about the 2.4
>> series. My opinion is that ?string(...) is lame, because it's a
>> template language, so its all about generating text. So you should
>> able just write x?'0.00' instead of x?string('0.00'). That's maybe
>> something for the 2.4 series. But how will you format booleans? Right
>> now, with foo?string(whenTrue, whenFalse). After adding ?choose, you
>> might as well write foo?choose(whenTrue, whenFalse), which is as
>> verbose as with ?string, but somewhat smarter (lazy evaluation,
>> non-string return values). Actually, you don't need anything for
>> boolean formatting, if you have a ternary operator anyway. But since
>> formatting a boolean is a typical task in templates, ?choose(t, f) is
>> too verbose, just like ?string(...). So that's where ?[t, f] comes
>> from; it's not only terser, but follows the logic of ?'0.00', that is,
>> if you have a non-id token after `?`, it's formatting.
>>
>> You may also wonder why exp?[t, f] instead of exp?(t, f). I don't want
>> to waste ?(...) on this. In JavaScript, { foo: bar } is the same as
>> { 'foo': bar }, so how do you specify a key that's the value of the
>> variable foo instead? Like { (foo): bar }. Now that trick, i.e. making
>> and identifier dynamic with parentheses is something I want to reserve
>> for the future. Like if you have variable `f` holding a method, and
>> you want to "apply" that on a value, you could write `x?(f)`. I think
>> that's
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> FreeMarker-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d