You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Ondra Žižka (JIRA)" <ji...@apache.org> on 2017/09/30 03:41:00 UTC

[jira] [Updated] (FREEMARKER-77) expr!! as a shorthand for (expr)!

     [ https://issues.apache.org/jira/browse/FREEMARKER-77?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ondra Žižka updated FREEMARKER-77:
----------------------------------
    Description: 
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.

  was:

Also, before I open an issue, what would be your view on a.very.long.expr!! being 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.


> 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)