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

Dmitri Blinov commented on JEXL-307:
------------------------------------

My understanding on globals with regard to this task is to keep things simple - 
we now have global variables and local variables. I think we are now discussing 
about visibility and declaration rules of *local* variables, as a result of new 
feature. So, any changes to global variables are off the table at the moment. 
In essence, if a symbol is used as a parameter or local variable in a script, 
it *shadows* a global, if such exists. This is what current implementation is 
look like, and this is how new feature IMO should work. With new feature, if a 
local comes out of its visibility scope, it simply no longer *shadows* a 
global. In my head, this is in strict analogy with java instance variables and 
local variables. Our globals are like java instance variables, and our locals 
are java local variables. Note that this is a little different from javascript 
block variable scope, where one can redeclare local variables within nested 
scope with `let` as much as he wants.

{code}
var  x = 10;
// Here x is 10
{  
  let x = 2;
  // Here x is 2
  { 
     let x = 3;
     // Here x is 3
  }
  // Here x is 2 once again
}
// Here x is 10
{code}

Since we think that 
{code}
var  x = 10;
// Here x is 10
{  
  // Error - local variable redeclaration is not allowed
  var x = 2;
}
{code}

I do not say that there is nothing good to be done with globals with respect to 
other needs, but for the sake of simplicity and understanding it is good to 
have variable model that has analogy with well-known implementation.

PS. About pragmas - what do you mean by point of impact of pragma?

> Variable redeclaration option
> -----------------------------
>
>                 Key: JEXL-307
>                 URL: https://issues.apache.org/jira/browse/JEXL-307
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
>
>
> As of now, JEXL allows a script writer to redeclare a local variable during 
> script evaluation.
> {code:java}
> var a = 1; var a = 2;{code}
> This may lead to potential errors with misspelled names and clashed 
> variables. Checking for already defined variable is a common feature of many 
> languages. This feature can be implemented in JEXL as an additional option of 
> JexlFeatures class, enabled by default, thus allowing compatibility with 
> existing code.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to