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

Anyone who is trying Dave Cuny's Py will want to make a small change to the
file py.e to enable namespacing.  See the  routine in question at the bottom of
this e-mail.
Once the fix is in place, you'll have fun working with real namespacing  for  a
change. Here's an example:

--file a.pi
    food = "APPLE"
    def foo(x)
        return x * x
    end def

--file b.pi
    food = "BANNANA" -- note the conflicting names
    def foo(x)
       return x + 100
    end def

--file main.py
import "a.pi" as A
import "b.pi" as B

printf(1,"A food that starts with A is %s\n", A.food)
printf(1,"A food that begins with B is %s\n", B.food)
printf(1,"A.foo(5) returns %d\n", A.foo(5))
printf(1,"B.foo(5) returns %d\n", B.foo(5))

And here's the output:
+==========================================+
| Py version 2.2a                          |
| Built: October 20, 2000                  |
|==========================================|
| Py (c) David Cuny                        |
| Euphoria (c) Rapid Development Software  |
| Dictionary code (c) Jiri Babor           |
+==========================================+

type 'bye' to exit
A food that starts with A is APPLE
A food that begins with B is BANNANA
A.foo(5) returns 25
B.foo(5) returns 105


Press Enter...
-------------------------------------------
The fix is to comment out the following lines
marked with --IGM

global procedure pyNewDef( sequence name )
-- create an new definition
-- if one already exists, allow redefinition

integer at

-- check for error
if theStruct then
oxParseError( "Can't nest def", {} )
return
end if

if find( name, builtin ) then
oxParseError( "%s is a builtin", {name} )
return
end if

at = find( name, defName )

--IGM if at then
-- allow redefinition
--IGM     theDef = at

--IGM  else
-- allocate storage
defName &= {name}
defSpace &= {theNamespace}
defArgs &= {0}
defVars &= {{}}
defCode &= {{}}
defReal &= {0}

-- set in definition
theDef = length( defName )
--IGM  end if

end procedure

Regards,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu