On Tue, Jun 30, 2015 at 5:50 PM, Stefan Karpinski <[email protected]> wrote: > A good approach to that specific issue would be for us to provide hooks into > srand, allowing other packages to register callbacks with the same > signature. As to the original question, while you can pull individual > methods out of generic functions, you can't call them, so there's no way to > do this currently.
Method.func is actually callable but I guess it's a bad idea to do that. > > On Tue, Jun 30, 2015 at 5:35 PM, 'Deniz Yuret' via julia-users > <[email protected]> wrote: >> >> Thanks! I guess my rand() example was not a good example. The actual use >> case was trying to get srand to set the seed for the gpu as well as the cpu. >> I thought if I could override the srand function (so the user does not need >> to remember a new name), and have it call the original srand as well as the >> gpu srand that would be a good solution. As things stand, (1) I can use a >> different name, (2) I can create an srand specific to my module following >> Matt's suggestion (do I then export this or have people call >> MyModule.srand()?), (3) I can look at what the original srand does and copy >> it into the new function. >> >> However more generally, if I understand correctly, once a function in a >> module is imported and redefined, there is no way to access the original >> definition. Please correct me if I am wrong. >> >> best, >> deniz >> >> >> On Tue, Jun 30, 2015 at 2:17 PM Stefan Karpinski <[email protected]> >> wrote: >>> >>> Overwriting methods in Base is a bad idea. This will affect all usages of >>> the function, not just the ones in your module. You can have your own >>> function called rand() instead. >>> >>> On Tue, Jun 30, 2015 at 3:43 PM, Matt Bauman <[email protected]> wrote: >>>> >>>> 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) >>>>> >>> >
