Note the warning message you get upon trying to define Base.rand(): 
 Warning: Method definition rand() in module Random at random.jl:195 
overwritten in module Main at none:1

You're not shadowing rand; you're totally overwriting one of its main 
methods.  I agree with Tom that you should probably use a different name, 
but if you really wanted to, you could actually shadow the name:

julia> rand() = Base.rand() + 1 # Note that this will only work if you 
haven't used Base.rand in your module or session yet.
rand (generic function with 1 method)

julia> rand()
1.9306557841053391

julia> Base.rand()
0.8691479006333791


On Tuesday, June 30, 2015 at 3:07:30 PM UTC-4, Deniz Yuret wrote:
>
> Say we import and redefine a function from Base.  Is it possible to access 
> the form of the function before the redefinition?
>
> Here is an example of what I am trying to do (which doesn't work):
>
> rand_orig = rand
> Base.rand()=(rand_orig() + 1)
>
>

Reply via email to