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

import/using docs: examples & explanation #27130

Open
StefanKarpinski opened this issue May 17, 2018 · 4 comments
Open

import/using docs: examples & explanation #27130

StefanKarpinski opened this issue May 17, 2018 · 4 comments
Labels
domain:docs This change adds or pertains to documentation modules

Comments

@StefanKarpinski
Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski added domain:docs This change adds or pertains to documentation modules labels May 17, 2018
@mauro3
Copy link
Contributor

mauro3 commented May 17, 2018

For reference, the linked example above is:

julia> module A
           export a, b, c
           a = b = c = 1
       end
Main.A

julia> module B
           export c, d, e
           c = d = e = 2
       end
Main.B

julia> module C
           using ..A
           using ..B
           import ..B: c
           @show a, b, c, d, e
       end
(a, b, c, d, e) = (1, 1, 2, 2, 2)
Main.C

and the text:

A little further explanation. If a name is already ambiguous and you try to use it, then it is simply undefined. If you use a name when it’s unambiguous, that resolves its meaning. We can’t predict that you’re going to later do something that would cause it to become ambiguous, so the best we can do at that point is warn you.

The current design has the property that if you have code that works without warnings or errors and if you reorder the imports and it still works without warnings or errors then it does the exact same thing. That seems like a fairly important property to have. Combined with the requirement that Julia code be evaluated one top-level expression at a time, I don’t think there’s any other design we could have with this property. In older Julia versions the order of usings was significant which is not great because people tend to reorder them.

@mauro3
Copy link
Contributor

mauro3 commented May 17, 2018

I cannot quite reconcile what Stefan said with below examples, in Julia 0.6.2:

   _       _ _(_)_     |  A fresh approach to technical computing                                                                                                         
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org                                                                                                       
   _ _   _| |_  __ _   |  Type "?help" for help.                                                                                               
  | | | | | | |/ _` |  |                                                                                                                                                  
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)                                                                                                            
 _/ |\__'_|_|_|\__'_|  |                                                                                                                                                  
|__/                   |  x86_64-pc-linux-gnu                                                                                                                             
                                                                                                                                                                          
julia> using Distributions                                                                                                                                                
                                                                                                                                                                          
julia> logpdf(Uniform(1,2), 1)                                    
-0.0                                                                                                                                                                      
                                                                                                                                                                          
julia> loglikelihood(x) = 1                                                                                                                                               
ERROR: error in method definition: function StatsBase.loglikelihood must be explicitly imported to be extended

but this works:

julia> using Distributions                                                                                                                                               
                                                                                                                                                                         
julia> loglikelihood(x) = 1                                                                                                                                              
loglikelihood (generic function with 1 method)                                                                                                                           

julia> logpdf(Uniform(1,2), 1)                                                                                                                                           
-0.0                                                                                                                                                                     

Why is loglikelihood being "reserved" in the first case (without me ever using it) and not in the second?

@GunnarFarneback
Copy link
Contributor

I can't reproduce.

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu

julia> using Distributions

julia> logpdf(Uniform(1,2), 1)
-0.0

julia> loglikelihood(x) = 1
loglikelihood (generic function with 1 method)

@mauro3
Copy link
Contributor

mauro3 commented May 17, 2018

I can't reproduce it either anymore, although scrolling up in my terminal shows the edited (now including banner), above output?! Sorry about the noise...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation modules
Projects
None yet
Development

No branches or pull requests

3 participants