I don't want to define a global method. I want this to be local to the
scope where it's defined.
Is that not possible? It seems kind of odd that the main dispatch tool in
the language isn't scoped. :o(
Andrew
On Wednesday, 27 May 2015 08:44:57 UTC-3, Mauro wrote:
>
> 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] <javascript:>>
> 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
>
>