Nice. So I can do this:

julia> f = Module()
anonymous

julia> g = Module()
anonymous

julia> is(f, g)
false

as output of initial macro I can do:
julia> let 
         eval(f, quote
              function myfunc end
         end)
         end

and in subsequent macros I can do:
julia> let
         f.myfunc(x::Int) = x* 2
         end

the only thing is I need a reference to this anonymous module.

Thanks for the help!

 
On Friday, July 24, 2015 at 2:21:50 AM UTC+5:30, Mauro wrote:
>
> > I mean there are functions like "methods", "methodswith" for reading 
> from 
> > any function. And in general there are getfield, setfield functions to 
> set, 
> > get from a type field. Curious as to why a function to add methods to a 
> >  function in similar manner has not been provided. I'm thinking there is 
> > something I'm missing conceptually. 
>
> Also, have you seen this: 
> https://github.com/davidagold/MetaMerge.jl 
>
> > On Friday, July 24, 2015 at 1:55:06 AM UTC+5:30, Vinuth Madinur wrote: 
> >> 
> >> However, is there a reason why a simpler way to extend methods isn't 
> >> provided? While one can "read" methods from a function, lack of "write" 
> >> support to modify / add / delete methods from a generic function makes 
> me 
> >> curious. 
> >> 
> >> 
> >> On Friday, July 24, 2015 at 1:49:42 AM UTC+5:30, Vinuth Madinur wrote: 
> >>> 
> >>> Cool. Had missed the module part. So they give an accessible isolated 
> >>> scope. 
> >>> This should do it. 
> >>> 
> >>> Thanks for the help! 
> >>> 
> >>> 
> >>> On Friday, July 24, 2015 at 1:43:16 AM UTC+5:30, Tom Breloff wrote: 
> >>>> 
> >>>> So... you want a method name globally accessible, but you don't want 
> to 
> >>>> put in global scope?  Maybe you should use a Module instead of a let 
> >>>> block.  Your first method definition goes in the scope of "MyModule", 
> and 
> >>>> then later on you can add to that method definition by defining a 
> function: 
> >>>> "MyModule.myFunction(x::MyType) = ..." 
> >>>> 
> >>>> See: http://julia.readthedocs.org/en/latest/manual/modules/ 
> >>>> 
> >>>> On Thursday, July 23, 2015 at 4:08:45 PM UTC-4, Vinuth Madinur wrote: 
> >>>>> 
> >>>>> Please ignore the "anonymous function" part above. 
> >>>>> 
> >>>>> I'm creating a function in my macro inside a let block so that it 
> >>>>> doesn't pollute the surrounding scope. Later on, when the same macro 
> is 
> >>>>> used on a different expression, I wont be able to access this same 
> function 
> >>>>> to extend it inside another let block. I was looking for a way to do 
> this. 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> On Friday, July 24, 2015 at 1:12:36 AM UTC+5:30, Vinuth Madinur 
> wrote: 
> >>>>>> 
> >>>>>> It's a little complicated scenario to explain. It's like this: 
> >>>>>> 
> >>>>>> I have a macro that replaces an expression with a function whose 
> name 
> >>>>>> isn't fixed / known / is anonymous / created inside a closured 
> scope. Later 
> >>>>>> on I want the ability to add methods to this. 
> >>>>>> 
> >>>>>> 
> >>>>>> 
> >>>>>> On Friday, July 24, 2015 at 12:57:01 AM UTC+5:30, Tom Breloff 
> wrote: 
> >>>>>>> 
> >>>>>>> Can you tell us more about your end-goal?  I have a feeling that 
> >>>>>>> you're not thinking about this in a Julian way, but I'm not 
> entirely sure 
> >>>>>>> what you want to be able to do. 
> >>>>>>> 
> >>>>>>> On Thu, Jul 23, 2015 at 3:21 PM, Vinuth Madinur <
> [email protected] 
> >>>>>>> > wrote: 
> >>>>>>> 
> >>>>>>>> Hi, 
> >>>>>>>> 
> >>>>>>>> Is there a way to add a method to a generic function during 
> runtime? 
> >>>>>>>> Or to merge two generic functions? For example: 
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>>> function abc end 
> >>>>>>>> function xyz end 
> >>>>>>>> 
> >>>>>>>> function add_method(method, func) 
> >>>>>>>>       #Add method to func 
> >>>>>>>> end 
> >>>>>>>> 
> >>>>>>>> add_method(xyz) do x::Int 
> >>>>>>>>    x*2 
> >>>>>>>> end 
> >>>>>>>> 
> >>>>>>>> or 
> >>>>>>>> 
> >>>>>>>> add_method(x -> x * 4, abc) 
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>>> Thanks, 
> >>>>>>>> Vinuth. 
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>> 
>
>

Reply via email to