My feeling is that am missing something very basic here or that this has 
been asked/misunderstood many times before. ;) But since I could find an 
answer in my searches here goes:

How can I reuse some parts of another module while re-implementing some of 
it's lower-level functions (it uses internally)? In the example code below 
I want to create a new module M2 which reuses (via import and then export) 
a macro from another module M1 but re-implements a lower level f1 function 
that is used in the implementation of m1.

module M1
  export @m1
  macro m1(ex)
    @show(ex)
    @show f1(ex)
  end
  function f1(ex)
    "M1.f1: $ex"
  end
end

a = 1
M1.@m1 a + 1   # prints: f1(ex) = "M1.f1: a + 1"

# I want to reuse @m1 but redefine the f1 it uses.
module M2
  import M1: @m1
  function f1(ex)
    "M2.f1: $ex"
  end
end

M2.@m1 a + 1 # Not what I want, it still uses M1.f1

module M3
  import M1: @m1, f1
  function f1(ex)
    "M3.f1: $ex"
  end
end

M3.@m1 a + 1 # What I want but gives warning that f1 in module M1 
overwritten
M1.@m1 a + 1 # and M1.@m1 is affected which can affect others...

Is there a way I can import @m1 from M1 into my new module but force it to 
call my newly defined f1?
Am I totally on the wrong track here and another "design" is better?

I'd rather not fall back to copy-paste solutions here...

Thanks, Robert

Reply via email to