relative importing #1342

Closed
JeffBezanson opened this Issue Oct 6, 2012 · 6 comments

Comments

Projects
None yet
4 participants
Owner

JeffBezanson commented Oct 6, 2012

Quoting Stefan:

    module Foo
      module Bar
        export baz
      end
      import Foo.Bar.*
    end

If feels really weird to have to write import Foo.Bar.* inside of Foo to import from the inner module Bar. One thing I can think of is to look for imports relative to the current module first and then fall back to searching relative to Main. Another possibility would be to have a syntax for relative import, e.g. import .Bar.* or something like that.

JeffBezanson was assigned Oct 6, 2012

Owner

StefanKarpinski commented Oct 6, 2012

I think the least cognitive load for the programmer is the former option — i.e. looking for relative imports before absolute ones. The down side is that it is a more complex mechanism. Whether each import is static or absolute can, however, always be determined statically, as far as I can tell, so that's probably not a huge issue.

Owner

staticfloat commented Oct 6, 2012

This seems similar in spirit to issues of "scope", where the default rules are to search local scope for a name/binding before searching global scope. I think the same behavior in this case would give the least surprising result.

Owner

StefanKarpinski commented Oct 6, 2012

That's actually a nice way to look at it. It seems like this view would imply that these should all work:

module A
  export a
  module B
    export b
  end
  module C
    export c
    module D
      export d
    end
    import A.*
    import B.*
    import C.*
    import D.*
  end
  import A.*
  import B.*
  import C.*
  #import D.* <= wouldn't work
  import C.D.*
end  
import A.*
#import B.* <= wouldn't work
import A.B.*
#import C.* <= wouldn't work
import A.C.*
#import D.* <= wouldn't work
#import C.D.* <= wouldn't work
import A.C.D.*
Owner

staticfloat commented Oct 6, 2012

Precisely, and we'd also get some namespace-like stuff for free:

module A
  ...
  module inner
    #Does something
    export innerFunc
  end
  import inner.*
end

module B
  ...
  module inner
     #Does something completely different
     export innerFunc
  end
  #Imports B.inner, not A.inner!
  import inner.*
end
Contributor

JeffreySarnoff commented Oct 12, 2012

+1

Owner

JeffBezanson commented Nov 5, 2012

Branch merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment