Io namespaces are created using regular objects. However, there’s no such thing as “lexical context” In Io, so the
Foo will not be able to access
Bar in the following example:
MyApp := Object clone do(
Foo := Object clone do(
bar := method(Bar) # Bar is not accessible from here!
)
Bar := Object clone do(
foo := method(Foo) # Foo is not accessible from here!
)
)
How can we improve that? First, lets define
MyApp with
Module clone rather than
Object clone:
MyApp := Object Module clone do(
Foo := Object clone do(
bar := method(Bar)
)
Bar := Object clone do(
foo := method(Foo)
)
)
All we need now is to have all inner objects to have MyApp in the list of prototypes. Therefore, lets override
Object slot to refer to MyApp rather than the standard Object:
Module := Object clone do(
Object := method(self)
)
See
Module.io on GitHub.