freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondra Žižka (JIRA) <>
Subject [jira] [Commented] (FREEMARKER-77) expr!! as a shorthand for (expr)!
Date Mon, 09 Oct 2017 23:39:00 GMT


Ondra Žižka commented on FREEMARKER-77:

Ok, it seems that you have a clear big picture for FM3, I hope it will happen. I don't have
a strong opinion on this. But while working with missing values, getting it right is quite
tricky, esp. when employing different built-ins... 
Regarding leaving out the parentheses, I am not sure. Sometimes one might need a different
default through the expression, since it changes the logic of the expression. I'm not sure
how that would be addressed?

> expr!! as a shorthand for (expr)!
> ---------------------------------
>                 Key: FREEMARKER-77
>                 URL:
>             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.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
> 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 {{}} is missing, the whole
expression would turn into {{"-"}}.
> {code}
> {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

View raw message