Re: routine_id() is not working
- Posted by mattlewis (admin) Apr 12, 2013
- 1295 views
Please read up on euphoria namespaces. You don't put something into a namespace. You use a namespace to point at a particular file to disambiguate from a symbol in another file. You may declare a default namespace for a file as a convenience, but again, this isn't some sort of sandbox around the symbols in the file. It's just an easy way to tell euphoria to look at that particular file.
Ah, the last two sentences are the crux of my misunderstanding. They should be in the manual, at the very top of the namespace section.
I think you're right. I've inserted this paragraph into the 4.1 manual under namespaces, right at the beginning:
Euphoria namespaces are used to disambiguate between symbols (routines, variables, constants, etc) with the same names in different files. They may be declared as a default namespace in a file for the convenience of the users of that file, or they may be declared at the point where a file is included. Note that unlike namespaces in some other languages, this does not provide a sandbox around the symbols in the file. It is just an easy way to tell euphoria to look for a symbol in a particular file.
However, loading two procedures or function by the same name (and un-namespaced) being legal, but loading variables of the same name (and un-namespaced) isn't, seems wrong, because if the programmer didn't namespace them (include blah.e as blah), one or more of them cannot be used.
That's true. Whenever I write a new file these days, I put a default namespace in. I don't always use them, but when I need to, it's available and easy to put in. The general idea is that you'll get an error as soon as you have a problem, and you can fix it right away.
I don't think that most people (or me, anyways) use routine_id as much as you do. These days, I mainly use it for things like GUI event handlers, or for dispatch in the translator (where a missing routine_id is noticed and an error is thrown). Adding checks when a literal is passed to routine_id would definitely help you (and others).
I don't read all of win32lib.e or it's many includes, so i might write a procedure of the same name as exists in win32lib. Or perhaps something under std/net (which has happened a few times the last few years). I doubt anyone reads all the proc names in every file they might include to see if that name is already taken.
For that reason, i suggest Euphoria "understand" transparently and automagically that all procedures and functions in includes are now addressable like filename:procname, if the programmer has not manually done so. And if i then include os.e and misc.e and then want to use sleep(), being that it's in two files and i didn't specify which one to use, Euphoria toss an error before it runs, letting me know to choose one.
Hmm...that's an interesting idea. It seems like it would have to just be the file name, without any path qualifiers. Maybe even without extension. I suppose that explicit namespaces would override. What to do in the case where a file has a default namespace that clashes with a file name of another file included?
Ugh...I think it seems simpler to say, "just add a namespace to your include directive."
I know you're using 4.1 these days. I think you might be interested in include/euphoria/debug/debug.e. It lets you poke around the symbol table, among other things.
Matt