Re: Question on scope

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu