[ 
https://issues.apache.org/jira/browse/FREEMARKER-77?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16198539#comment-16198539
 ] 

Daniel Dekany edited comment on FREEMARKER-77 at 10/10/17 4:17 PM:
-------------------------------------------------------------------

Or rather, first I want a concrete working solution in FM3, and then see how to 
port ideas back with causing the least confusion. Though for may of the changes 
back porting just wont be feasible...

The problem with {{(...)!default}} in FM2 is that parentheses already have a 
commonly understood meaning. In particular, if the evaluation order with and 
without the parenthesis is the same, like in the case of {{(a * b) + c}}, t can 
be removed. {{(...)!default}} works differently, which is confusing. Can you 
show me an example where you suspect the FM3 approach won't work well?

(Though you don't really know how FM3 meant to do it. The relevant discussion 
is [here in the mail 
archive|https://lists.apache.org/thread.html/2715ecc7a47fbacf18996169dfd4ed4b82bc38c567f114cec86e0db1@<dev.freemarker.apache.org>],
 but it's admittedly very long and not easy to follow.)


was (Author: ddekany):
Or rather, first I want a concrete working solution in FM3, and then see how to 
port ideas back with causing the least confusion...

The problem with {{(...)!default}} in FM2 is that parentheses already have a 
commonly understood meaning. In particular, if the evaluation order with and 
without the parenthesis is the same, like in the case of {{(a * b) + c}}, t can 
be removed. {{(...)!default}} works differently, which is confusing. Can you 
show me an example where you suspect the FM3 approach won't work well?

(Though you don't really know how FM3 meant to do it. There relevant discussion 
is [here in the mail 
archive|https://lists.apache.org/thread.html/2715ecc7a47fbacf18996169dfd4ed4b82bc38c567f114cec86e0db1@<dev.freemarker.apache.org>],
 but it's admittedly very long and not easy to follow.)

> expr!! as a shorthand for (expr)!
> ---------------------------------
>
>                 Key: FREEMARKER-77
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-77
>             Project: Apache Freemarker
>          Issue Type: New Feature
>            Reporter: Ondra Žižka
>            Priority: Minor
>
> a.very.long.expr!! could be a shorthand for {{(a.very.long.expr)!}}.
> The effect of !! would go back to the "root" of the expression, i.e. at the 
> start of the part ending with !! . Not sure if that would have clear enough 
> rules, though.
> The use case is, that often there is a long expression, (again, getting 
> something from a deep graph), and anywhere on the path something can be 
> missing. The only relevant thing is at the end. And the parentheses make the 
> expression less readable.
> Example made-up situatuon:
> {code}
> (foo.bar.baz[(foo.transform((a.very.long.expression())!"defaultResult"))!fallbackKey(context)])!"-"
> {code}
> 1) The long expression can be missing at any point, so the transform would 
> get some default value.
> 2) The transform may return null if the argument is somehow improper. For 
> that case, the {{fallbackKey()}} would return a key as per the {{context}}.
> 3) If the map doesn't contain the entry or any of {{foo.bar.baz}} is missing, 
> the whole expression would turn into {{"-"}}.
> {code}
> foo.bar.baz[foo.transform(a.very.long.expression()!!"defaultResult")!!fallbackKey(context)]!!"-"
> {code}
> Ok, this one is perhaps a candidate for splitting into few steps. But it's 
> just for illustration.
> Does it make sense? Is it doable?
> Marking it as minor as it's not really too much pain, just would be nice to 
> have.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to