To see the difference between `foo` and `bar`, try

`foo((2,3), (4,5))`

and

`bar((2,3), (4,5))`.

Then try `foo((2,3), (4,5,6))`.

On Sunday, July 19, 2015 at 5:43:30 PM UTC-4, Tomas Lycken wrote:
>
> Hi everybody,
>
> I created the function
>
>     foo{N}(bar::NTuple{N}...) = N
>
> under the impression that I'd be able to do
>
>     julia> foo(2, 3)
>     2
>     julia> foo(1, 2, 3, 4, 5, 6, 7)
>     7
>     julia foo("bar", "qux", 3, rand(10))
>     4
>
> but all the above yield no-method errors, since the `NTuple` isn't 
> splatted in the signature. The following works, though:
>
>     julia> foo((2,3))
>     2
>
> so if I actually pass a tuple, it works. However, 
>
>     julia> methods(foo)
>     # 1 method for generic function "foo":
>     foo{N}(bar::NTuple...) at none:1
>
> does show the splatting `...`. so I assume there's some difference between 
> the definition of `foo` and a similar function
>
>     bar{N}(foo::NTuple{N}) = N
>
> which doesn't splat. The behavior of `foo` above is what I would expect 
> (and what I get) from `bar`.
>
> I realize I'm probably trying to do something semi-pathological here, but 
> it'd be really nice if it was possible to make `foo` work the way I want it 
> too (and without `@ngenerate`, if I get to choose...). I seem to recall 
> some discussion that mentioned a way to do this, but I can't remember where 
> (or even if it was mentioned as a solution or as a suggestion for future 
> language features...).
>
> What is the actual difference between `foo` and `bar` above? How can I get 
> the behavior I want from `foo`?
>
> Regards,
>
> // T
>

Reply via email to