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

Paul King edited comment on GROOVY-11714 at 7/15/25 10:58 AM:
--------------------------------------------------------------

It looks like you are expecting interpreter mode:
{noformat}
groovy:000> :set interpreterMode true
groovy:000> def x = 4
===> 4
groovy:000> x
===> 4
groovy:000>
{noformat}
Otherwise, variables come from the binding. Leaving off the def is how you save 
them to the binding. So, the "def f" in your second example, doesn't do 
anything.

Without interpreter mode, think of "def f = 1" as a code snippet that is 
executed but no longer part of the execution environment once complete.


was (Author: paulk):
It looks like you are expecting interpreter mode:
{noformat}
groovy:000> :set interpreterMode true
groovy:000> def x = 4
===> 4
groovy:000> x
===> 4
groovy:000>
{noformat}
Otherwise, variables come from the binding. Leaving off the def is how you save 
them to the binding. So, the "def f" in your second example, doesn't do 
anything.

> groovysh failed to store variable for grammar like 'def e = 1' for groovy 5
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-11714
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11714
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Jin Xu
>            Priority: Major
>         Attachments: screenshot-1.png, screenshot-2.png
>
>
>  !screenshot-1.png! 
> however, define first then give value can work.
>  !screenshot-2.png! 
> xenoamess@xenoamessum890pro:~/groovy-5.0.0-beta-1/bin$ ./groovy -v
> Groovy Version: 5.0.0-beta-1 JVM: 24 Vendor: GraalVM Community OS: Linux



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

Reply via email to