1. Question on scope
- Posted by jzeitlin at cyburban.com Dec 18, 2001
- 456 views
I'm working on outlining a project that is clearly made easier with the advent of namespacing; however, I do need clarification on the behavior of include files both with and without namespacing: If I have include foo.e include bar.e include baz.e in a Euphoria source file, the public routines of foo.e are _not_ available to routines in bar.e or baz.e _unless_ those files include foo.e, correct? Does this still hold if they are included into a namespace? -- Jeff Zeitlin jzeitlin at cyburban.com (ILink: news without the abuse. Ask via email.)
2. Re: Question on scope
- Posted by Kat <gertie at PELL.NET> Dec 18, 2001
- 449 views
On 18 Dec 2001, at 7:12, jzeitlin at cyburban.com wrote: > > I'm working on outlining a project that is clearly made easier with the > advent of namespacing; however, I do need clarification on the behavior of > include files both with and without namespacing: > > If I have > > include foo.e > include bar.e > include baz.e > > in a Euphoria source file, the public routines of foo.e are _not_ available to > routines in bar.e or baz.e _unless_ those files include foo.e, correct? All globals in foo are accessable to bar and baz. If you include foo more than once, or in a nested include, you get an error. >Does > this still hold if they are included into a namespace? I don't know, but it should. Kat
3. Re: Question on scope
- Posted by Robert Craig <rds at RapidEuphoria.com> Dec 18, 2001
- 439 views
Jeff Zeitlin writes: > If I have > > include foo.e > include bar.e > include baz.e > > in a Euphoria source file, the public routines of foo.e are _not_ available > to routines in bar.e or baz.e _unless_ those files include foo.e, correct? You could make a good case for that behavior, but in fact, the globals of foo.e are available automatically to bar.e and baz.e, whether namespaces are defined or not. Kat writes: > If you include foo more than > once, or in a nested include, you get an error. You can include foo.e again if you want. All subsequent includes of foo.e will be ignored (no error), except that you can specify a namespace identifier on any include statement, and even have multiple identifiers refering to the same include file. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
4. Re: Question on scope
- Posted by jzeitlin at cyburban.com Dec 18, 2001
- 427 views
On Tue, 18 Dec 2001 12:40:11 -0800, Robert Craig <rds at RapidEuphoria.com> wrote: >Jeff Zeitlin writes: >> If I have >> include foo.e >> include bar.e >> include baz.e >> in a Euphoria source file, the public routines of foo.e are _not_ available >> to routines in bar.e or baz.e _unless_ those files include foo.e, correct? >You could make a good case for that behavior, but in fact, >the globals of foo.e are available automatically to bar.e and baz.e, >whether namespaces are defined or not. This is good to know; it just made part of the project even simpler. I was prepared to write the project assuming the behavior in my question, but it would have been more complicated. >Kat writes: >> If you include foo more than >> once, or in a nested include, you get an error. >You can include foo.e again if you want. >All subsequent includes of foo.e will be ignored (no error), >except that you can specify a namespace identifier on >any include statement, and even have multiple identifiers >refering to the same include file. Good to know. Leads to a new question: Suppose I have included foo.e as bar and as baz. Is it possible to write a procedure that overrides one of the publics in one of the namespaces? IOW, can I define namespaces other than by includes? If this is answered in the docs, tell me so - I haven't had the chance to read them thoroughly, only glanced through them. -- Jeff Zeitlin jzeitlin at cyburban.com (ILink: news without the abuse. Ask via email.)
5. Re: Question on scope
- Posted by Derek Parnell <ddparnell at bigpond.com> Dec 18, 2001
- 413 views
19/12/2001 12:07:25 PM, jzeitlin at cyburban.com wrote: > >>You can include foo.e again if you want. >>All subsequent includes of foo.e will be ignored (no error), >>except that you can specify a namespace identifier on >>any include statement, and even have multiple identifiers >>refering to the same include file. > >Good to know. Leads to a new question: Suppose I have included foo.e as >bar and as baz. Is it possible to write a procedure that overrides one of >the publics in one of the namespaces? IOW, can I define namespaces other >than by includes? If this is answered in the docs, tell me so - I haven't >had the chance to read them thoroughly, only glanced through them. > Unfortunately, no. Namespaces can only be declared via the include statement. If a file is included multiple times, each with a different namespace identifier, then all that happens is that the globals in the include file are only instantiated once but have multiple aliases. Thus is foo.e has a global called "XYZ" then include foo.e as n1 include foo.e as n2 means that there is only one "XYZ" in memory but it can be referenced as ... n1:XYZ or n2:XYZ or just XYZ if there are no other global XYZ defined in *other* included files or the current file. With the example above, the following code ... n1:XYZ = 0 n2:XYZ = 1 ? n1:XYZ will print out the value 1, because there is one a single XYZ in memory that both namespaces, n1 and n2, refer to. On a personal note, I am very disappointed that RDS chose to implement it this way. I was looking forward to having multiple includes instantiate multiple "objects" in memory. Oh well, may be later. --------- Derek.