Namespace idea

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

Rob,

One suggestion for the namespace problem (borrowed from C++ with
modifications):

The following would be added to the language
1. Dot notation (or any prefered eqivalent alternative)
2.  namespace / end namespace
3.  using/ stop_using

The namespace keyword would define a namespace which would be in effect
until the next end namespace.  Namespaces could be nested, and a given
namespace could be closed and reopened later.

If this were part of Euphoria, Win32Lib would need no alteration ecept for
its first line to be namespace Win32Lib and its last line to be end
namespace.  In the case I needed a namespace for say graphics.e (which I
wouldn't modify and lose its stamped status)

namespace Graphics_e
include graphics.e
end namespace

would accomplish the same thing as putting namespace/end namespace in the
file itself.

The using keyword allows us to dispense with dot notation in many cases.
Let's say were using Win32lib and it didn't have any name clashes.  Then

using Win32lib

would allow Win32lib routines/constants to be referenced without the dot.

Using would allow multiple namespaces:

using foo, bar, blech

and would be cumulative:

using foo
using bar
using blech

would be equivalent to the above example.

The keyword stop_using would remove one or more namespaces form the using
list.

stop_using bar

would prevent using bar routines/data without the dot, but continue to allow
it for foo and blech.

stop_using ALL  would clear the entire using list.

The seach order for a routine or data:

1. If the reference is in a namespace, that namespace.
2. If that namespace is nested in another namespace, the enclosing
namespace.
3. Rule 2 is applied recursively.
4. The global namespace.
5. The namespaces in the using list, in the order they were declared.

Thus an example

using foo,bar,blech

namespace ugly
    namespace mug

            yuck(17,"ABC")

the interpreter would try in order:

    ugly.mug.yuck
    ugly.yuck
    yuck
    foo.yuck
    bar.yuck
    blech.yuck

Just some food for thought--this concept is very powerfull but might be to
complex for users.  It's not hard to implement, I've already done so for OOP
code in Object Euphoria.  (Except stop_using(), this is original for this
proposal.)

-- Mike Nelson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu