Disambiguating Import

Monkey Forums/Monkey Programming/Disambiguating Import

Samah(Posted 2015) [#1]
Mark,
Say we have this situation:
modules\
    foo\
        foo.monkey
    bar\
        bar.monkey
        foo.monkey

If in bar.monkey I use "Import foo", I'm pretty sure it's going to import bar.foo, so (as far as I know) there would be no way to import the top level module.

My suggestion is:
1) Make the Import statement always fully qualified, and
2) Change Import to allow modules prepended with a period to mean "module at the same level/directory".

Example:
Import foo ' imports the top-level module (foo) as if bar\foo.monkey did not exist
Import .foo ' imports the module from the same level/directory as the current file (bar.foo), as if the top-level module did not exist


This also prevents you from having to fully qualify your own modules in certain situations (Import bar.foo). It would break a lot of code, but it would only require developers to put a . at the front of their import to fix it.

Thoughts?

Samah


marksibly(Posted 2015) [#2]
Not a bad idea, but IMO there are quite a few problems with the module system, to the point where I'd strongly recommend not using duplicate 'leaf' module names in the first place (eg: rename one foo to foo2) in which case this isn't a problem!

Not much of an answer I know, but I think the first thing to fix re: modules would be the ability to use full module paths in expressions - currently, you can't - there are some nasty parser issues that need fixing.

I have been giving this some thought recently though and will let you know what I come up with.


Samah(Posted 2015) [#3]
@marksibly: Not much of an answer I know...

Actually that's kind of the answer I was hoping for! :)

Let's make the Module keyword more than just a compile error!


EdzUp(Posted 2015) [#4]
One thing I got from this which is a pain is sometimes when your compiling and it comes up with 'duplicate variable name' and the file its pointing to isnt even imported into the program, surely this could be checked before throwing an error.

In the example I had StarRogueEditWrecks.monkey and had a class in it called WreckClass this wasnt even used just in the directory so I could cut and paste code etc from it, in my game I had WreckClass which was imported and I got a duplicate error about it which I thought was weird.


marksibly(Posted 2015) [#5]
> In the example I had StarRogueEditWrecks.monkey.,..

Hmm...have to see some sample code to make sense of that!


EdzUp(Posted 2015) [#6]
Will find the files and send em over