Namespaces
- Posted by kbochert at ix.netcom.com Jun 24, 2001
- 687 views
-------Phoenix-Boundary-07081998- My vote goes for the simple "include file as F" syntax which is simple to use and backward -compatible. However there are 2 fine points which don't seem to have been mentioned yet. 1) Namespaces should not be referenced with the dot operator! The dot operator is more or less standardized across languages to reference members of objects, structures and sometimes arrays. It is not necessary or desirable for Euphoria to buck this trend. In a similar way, the colon operator generally refers to namespaces (as in C++ or XML). EX ------------ include file.e as F ... F:x =3D 1 -- set the x defined in file.e to 1 --------------- Euphoria may wish, someday, to use '.' for objects! 2) Even when a file has been included 'as X', it should still be possible to reference its globals without decoration, as long as the reference does not conflict with another global. EX 1------------ include stack.e as ST .. a =3D ST:pop () -- call the pop function in stack.e b =3D pop () -- the only 'pop' is in stack.e, so it is called EX 2-------- include stack.e as ST function pop () -- local function b =3D pop() -- local a =3D ST:pop() -- must use 'ST:' to get to stack's version ------------ The basic rule is that ':' is a scope resolution operator. Its use is only necessary where scope must be resolved. When it is not used, normal scope resolution takes place, (local, file, then global) and normal error messages are generated. Karl Bochert -------Phoenix-Boundary-07081998---