Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative importing #1342

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

relative importing #1342

JeffBezanson opened this issue Oct 6, 2012 · 6 comments
Assignees
Labels
breaking This change will break code needs decision A decision on this change is needed
Milestone

Comments

@JeffBezanson
Copy link
Member

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.

@ghost ghost assigned JeffBezanson Oct 6, 2012
@StefanKarpinski
Copy link
Member

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.

@staticfloat
Copy link
Member

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.

@StefanKarpinski
Copy link
Member

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.*

@staticfloat
Copy link
Member

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

@JeffreySarnoff
Copy link
Contributor

+1

@JeffBezanson
Copy link
Member Author

Branch merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

4 participants