Defining a global variable

2020-10-14 Thread Anton Shepelev
Hello, all I tried to define a global variable in a Groovy script. Section 1.1. of the "Semantics" documents says that one way to define a variable is via its type, so I defined one in the global scope of my script: String test void func() { println(test) } test = 'hello'

Re: Defining a global variable

2020-10-14 Thread Jochen Theodorou
On 14.10.20 13:45, Anton Shepelev wrote: [...] String test defienes a string property `test' or a string variable `test', depending on context. the context here is that of a method, so it is a local variable I was now stuck and resorted to an internet search, which brought up the followi

Re: Defining a global variable

2020-10-14 Thread Maarten Boekhold
Hi, I've been caught out by this in the past as well. It's actually quite simple... A Groovy Script like: String test void func(){     println(test) } test = 'hello' func() Gets compiled to a class as: class MyScript extends Script {     def run() {         Str

Re: Defining a global variable

2020-10-14 Thread Anton Shepelev
Jochen Theodorou to Anton Shepelev: > > String test > > > > void func() > > { > >println(test) > > } > > > > test = 'hello' > > func() > > > > Why, then, is `test' inaccessible from the function in > > my script? > > because the method you defined is not nested in another > method, instead it

Re: problem during calling method from closure

2020-10-14 Thread Anton Shepelev
Mariusz W: > class Boo { > def boo() {throw new UnsupportedOperationException("should override")} > def foo() { println "foo"} > } > > def a = [boo : { > foo() > }] as Boo > > a.boo() As far as I can see (which is not a great distance away from my nose), you are trying to construct an

Re: Defining a global variable

2020-10-14 Thread Jochen Theodorou
On 14.10.20 17:01, Anton Shepelev wrote: Jochen Theodorou to Anton Shepelev: [...] Frankly... for years we have been defending this position, but now, with so much distance I actually really wonder why we keep this. Perhaps it would have helped if you had documented not only language features

Re: problem during calling method from closure

2020-10-14 Thread OCsite
Anton, > ...You cannot refer to the method of an object that has not yet been > constructed. As a matter of fact, you can. This darned Java “method-calling” lingo is terribly misleading; we definitely should have sticked with Alan Kay's “message-sending”, and there would be much less misunders