Problem with nested function call

99 views
Skip to first unread message

Christoph Sawade

unread,
Jun 26, 2014, 11:15:07 AM6/26/14
to juli...@googlegroups.com

Hey all!

I was playing around and found a strange behaviour which is unclear to me. Can you help me to find out, where my bug is?
Here is the code snippet:

julia> immutable A end

julia> f(::A) = println("function called")
f (generic function with 1 method)

julia> call_f(a::A) = f(a)
call_f (generic function with 1 method)

julia> function call_f_indirect(a::A)
         f() = f(a)
         f()
         end
call_f_indirect (generic function with 1 method)

julia> a = A()
A()

julia> call_f(a)
function called

julia> call_f_indirect(a)
ERROR: no method f(A)
  in f at none:2
  in call_f_indirect at none:3


Thank you in advance, 

Christoph

P.S.: This code is working if A is a primitive numeric type.

Mauro

unread,
Jun 27, 2014, 4:11:22 PM6/27/14
to juli...@googlegroups.com
To extend a generic function you have to import it or fully qualify its
name. This seems to apply to function bodies too.

This worked for me:

function call_f_indirect(a::A)
Main.f() = f(a)
f()
end

and this too

function call_f_ind2(a::A)
global f
f() = f(a)
f()
end


--

Reply all
Reply to author
Forward
0 new messages