you have to declare foo as global otherwise it makes a new generic
function:
julia> function baz(i)
global foo(s::ASCIIString) = print("string")
foo(i)
end
baz (generic function with 1 method)
julia> baz(4)
integer
On Wed, 2015-05-27 at 13:33, andrew cooke <[email protected]> wrote:
> I have a bad feeling I have asked this before, but can't find the thread,
> sorry. How do I make the following work as expected (ie print "integer")
> instead of giving an error?
>
> julia> foo(i::Integer) = print("integer")
> foo (generic function with 1 method)
>
> julia> foo(42)
> integer
> julia> function bar(i)
> foo(i)
> end
> bar (generic function with 1 method)
>
> julia> bar(42)
> integer
> julia> function baz(i)
> foo(s::ASCIIString) = print("string")
> foo(i)
> end
> baz (generic function with 1 method)
>
> julia> baz(42)
> ERROR: `foo` has no method matching foo(::Int64)
> in baz at none:3
>
> Thanks,
> Andrew