(no subject)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

calathus
Hi,
Basic question.
I want to access function defined in another groovy file.
how can I access to it.

example:
simle.groovy:

public def foo = {x| x+x}
-----
in test.grrovy:
foo(5)  // =>copilaer reject this.

Are there any include like syntax in groovy?
Or only through calss, we can import features in another groovy file?

Thanks,
Calathus


Reply | Threaded
Open this post in threaded view
|

Re:

Guillaume Laforge
Administrator
import simle

def s = new simle()
s.foo()

but in your example, foo is a local variable, not a method, so you
won't be able to call it if you don't change your simle.groovy file.


On 4/2/06, calathus <[hidden email]> wrote:

> Hi,
> Basic question.
> I want to access function defined in another groovy file.
> how can I access to it.
>
> example:
> simle.groovy:
>
> public def foo = {x| x+x}
> -----
> in test.grrovy:
> foo(5)  // =>copilaer reject this.
>
> Are there any include like syntax in groovy?
> Or only through calss, we can import features in another groovy file?
>
> Thanks,
> Calathus
>
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re:

calathus


On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
import simle

def s = new simle()
s.foo()

but in your example, foo is a local variable, not a method, so you
won't be able to call it if you don't change your simle.groovy file.

'def' is not for declaring property of a class? should I use '@Property' instead?
I was thinking def is for property declaration as well as local declaration.


On 4/2/06, calathus <[hidden email]> wrote:

> Hi,
> Basic question.
> I want to access function defined in another groovy file.
> how can I access to it.
>
> example:
> simle.groovy:
>
> public def foo = {x| x+x}
> -----
> in test.grrovy:
> foo(5)  // =>copilaer reject this.
>
> Are there any include like syntax in groovy?
> Or only through calss, we can import features in another groovy file?
>
> Thanks,
> Calathus
>
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy



--
Calathus
Reply | Threaded
Open this post in threaded view
|

Re:

Guillaume Laforge
Administrator
In scripts, def creates local variables.

On 4/3/06, calathus <[hidden email]> wrote:

>
>
>
> On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
> > import simle
> >
> > def s = new simle()
> > s.foo()
> >
> > but in your example, foo is a local variable, not a method, so you
> > won't be able to call it if you don't change your simle.groovy file.
>
>
> 'def' is not for declaring property of a class? should I use '@Property'
> instead?
> I was thinking def is for property declaration as well as local declaration.
>
>
> > On 4/2/06, calathus <[hidden email]> wrote:
> > > Hi,
> > > Basic question.
> > > I want to access function defined in another groovy file.
> > > how can I access to it.
> > >
> > > example:
> > > simle.groovy:
> > >
> > > public def foo = {x| x+x}
> > > -----
> > > in test.grrovy:
> > > foo(5)  // =>copilaer reject this.
> > >
> > > Are there any include like syntax in groovy?
> > > Or only through calss, we can import features in another groovy file?
> > >
> > > Thanks,
> > > Calathus
> > >
> > >
> > >
> >
> >
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > http://glaforge.free.fr/blog/groovy
> >
>
>
>
> --
> Calathus


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re:

calathus
On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
In scripts, def creates local variables.

So in the following scrips,  gsoo0(gfoo0) is handled as property declaration, while gsoo1(gfoo1 ) is treated as local declaration? as long as they are using the same 'def' declaration, this seems confusing..

C

-----
simple.groovy:

public static def gsoo0(x) {x+x}
public static def gsoo1 = {x| x+x}

public def gfoo0(x) {x+x}
public def gfoo1 = {x| x+x}

public class Simple {

    public static def soo0(x) {x+x}
    public static def soo1 ={x|x+x}
    def foo0(x) {x+x}
    def foo1 = {x| x+x}
}
-----
test3.groovy:

println(">> new simple().gfoo0(5):"+new simple().gfoo0(5)) // works
//println(">> new simple().gfoo1(5):"+new simple().gfoo1(5)) // fails

println(">> simple1.gsoo0(5): "+simple.gsoo0(5)) // works
//println(">> simple1.sgoo1(5):"+simple.gsoo1(5)) // fails

 

On 4/3/06, calathus < [hidden email]> wrote:

>
>
>
> On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
> > import simle
> >
> > def s = new simle()
> > s.foo()
> >
> > but in your example, foo is a local variable, not a method, so you
> > won't be able to call it if you don't change your simle.groovy file.
>
>
> 'def' is not for declaring property of a class? should I use '@Property'
> instead?
> I was thinking def is for property declaration as well as local declaration.
>

>
> > On 4/2/06, calathus <[hidden email]> wrote:
> > > Hi,
> > > Basic question.
> > > I want to access function defined in another groovy file.
> > > how can I access to it.
> > >
> > > example:
> > > simle.groovy:
> > >
> > > public def foo = {x| x+x}
> > > -----
> > > in test.grrovy:
> > > foo(5)  // =>copilaer reject this.
> > >
> > > Are there any include like syntax in groovy?
> > > Or only through calss, we can import features in another groovy file?
> > >
> > > Thanks,
> > > Calathus
> > >
> > >
> > >
> >
> >
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > http://glaforge.free.fr/blog/groovy
> >
>
>
>
> --
> Calathus


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy



--
Calathus