You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (Jira)" <ji...@apache.org> on 2023/07/10 14:39:00 UTC

[jira] [Created] (JEXL-401) Captured variables should be read-only

Henri Biestro created JEXL-401:
----------------------------------

             Summary: Captured variables should be read-only
                 Key: JEXL-401
                 URL: https://issues.apache.org/jira/browse/JEXL-401
             Project: Commons JEXL
          Issue Type: Improvement
    Affects Versions: 3.3
            Reporter: Henri Biestro
             Fix For: 3.3.1


WHAT:
When a lambda captures local variables, these are copied into the lambda frame and behave as local variables within the lambda's scope. It would be convenient to alter this so that captured variables could be made read-only and reject side-effect operators at parsing time.


WHY:
This is an element of surprise for users with a Java background since captured variables must be final. It is also surprising when users expect dynamic (non lexical) scoping and would expect side effects to be carried thru scopes.
The examples below illustrates the 2 ways this can be surprising.
{code}
let x = -42;
const f = y -> x += y; // x is implicitly declared as a copy in the lambda 'f' frame
f(42);
// x is still -42
{code}


HOW:
By introducing a new feature flag aptly named 'constCapture'. This feature flag determines whether captured variables are const or not (default).




--
This message was sent by Atlassian Jira
(v8.20.10#820010)