Att: Rob - namespace problem
- Posted by Hayden McKay <hmck1 at dodo.com.au> Sep 22, 2005
- 471 views
There seems to be some "namespace" abnormality under some rare circumstances. 1. I'll demonstrate what I was tryeng to do. 2. I'll demonstrate a hack I found to fix it. I found this problem while codeing a new bst class for an application. An extract from the library is something like this...
-- bst.e constant -- bstNdata = 1, bstLeafL = 2, bstLeafR = 3 type node(sequence s) return length(s) = 3 end type sequence bstTree bstTree = {} global function bstLookup(atom n) -- lookup at bstTree global function bstInsert(atom n) -- insert at bstTree -- etc...
Ok. Now I wanted to use multiple Binary Serch Tree's and the easiest way to do this was to exploit Euphoria's namespace qualifier to create two classes.
-- Too make two instaces of "bstTree" (in bst.e) I did the syntax... include bst.e as BinaryTableOne include bst.e as BinaryTableTwo BinaryTableOne:bstInsert(1) -- Insert to 1st bstTree Inctance BinaryTableTwo:bstInsert(2) -- Insert to 2nd bstTree Inctance
This did not work! Only one instace of "bstTree" existed? However a valid work around was to have two copies of the file with two different names ie
include bstOne.e as BinaryTableOne include bstTwo.e as BinaryTableTwo BinaryTableOne:bstInsert(1) -- Insert at 1st bstTree Inctance BinaryTableTwo:bstInsert(2) -- Insert at 2nd bstTree Inctance
And presto... it worked! The drawback is that I need to have multiple copies of the same bst.e file accompany the source. Maybee this issue could be fixed in a future release. Note: The other alterative was to have a function return a handle. And have "bstTree" store multiple trees.