1. Scope of Type

An observation on scope.

Create a library file with extension .e.
Declare a non global type used by a global
function in this file.

Create a test .ex file which exercises this
function by including the file and using
the function.

I found that if the argument to the function
violates the type defined in the .e file,
I get an appropriate error, even though the
type is not global.  Is this by design?

However, if I try to create a variable in the
.ex test file, of the type defined in the .e
file, it fails, as the type is not defined.

I find it interesting that a non global type
is usable indirectly by a global function,
but not to define a variable.

--------------------- example .e ----
-- testtype.e

type nonneg(object n)
   if not integer(n) then
      return 0
   else
      return n >= 0
   end if
end type

global function usenonneg(nonneg x)
   return x
end function

--------------------- example .ex ----
--  testtype.ex

include testtype.e

? usenonneg(1)      --  this will work

nonneg x            --  this will fail
x = 1

--------
-- Larry Gregg

new topic     » topic index » view message » categorize

2. Re: Scope of Type

Larry Gregg writes:
> An observation on scope.
> Create a library file with extension .e.
> Declare a non global type used by a global
> function in this file.
> Create a test .ex file which exercises this
> function by including the file and using
> the function.
> I found that if the argument to the function
> violates the type defined in the .e file,
> I get an appropriate error, even though the
> type is not global.  Is this by design?

Yes it is.

This applies to more than just types.
The global function in the .e file can also use local
variables/procedures/functions that are not
(directly) accessible outside of the .e file.

Regards,
     Rob Craig
     Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu