The `getindex` explanation is not quite correct. Note, for instance, that 
Avik's example returns a 1-element array containing the tuple (1, 2, 3), 
not the 3-element array [1, 2, 3].  

As far as *callable* objects are concerned, I think you probably want 
`vcat` (or 'hcat', depending on your case):

*julia> **apply(vcat, 1, 2, 3)*

*WARNING: apply(f, x) is deprecated, use `f(x...)` instead*

 in depwarn at ./deprecated.jl:62

 in apply at deprecated.jl:115

while loading no file, in expression starting on line 0

*3-element Array{Int64,1}:*

* 1*

* 2*

* 3*

HOWEVER, it's worth noting that most array construction actually does not 
go through a callable object, but rather is the result of parsing an 
expression with a special head. Dumping expressions containing common array 
construction patterns will be more revealing here than looking at methods:

*julia> **dump( :( [1, 2, 3, 4] ))*

Expr 

  head: Symbol vect

  args: Array(Any,(4,))

    1: Int64 1

    2: Int64 2

    3: Int64 3

    4: Int64 4

  typ: Any


*julia> **dump( :( [1 2 3 4] ))*

Expr 

  head: Symbol hcat

  args: Array(Any,(4,))

    1: Int64 1

    2: Int64 2

    3: Int64 3

    4: Int64 4

  typ: Any


*julia> **dump( :( Int[1; 2; 3; 4] ))*

Expr 

  head: Symbol typed_vcat

  args: Array(Any,(5,))

    1: Symbol Int

    2: Int64 1

    3: Int64 2

    4: Int64 3

    5: Int64 4

  typ: Any


*julia> **eval(Expr(:vcat, 1, 2, 3, 4))*

*4-element Array{Int64,1}:*

* 1*

* 2*

* 3*

* 4*

On Wednesday, June 17, 2015 at 8:54:11 AM UTC-4, Mauro wrote:
>
> I think it just uses getindex (a bit of a hack...): 
>
> julia> @which Int[3] 
> getindex(T::Union(DataType,UnionType,TypeConstructor),vals...) at 
> array.jl:119 
>
>
> On Wed, 2015-06-17 at 14:50, andrew cooke <[email protected] <javascript:>> 
> wrote: 
> > Oh, I think the call() thing is just me being confused.  That's *only* a 
> > mechanism to allow non-functions to look like functions?  I guess my 
> > misunderstanding is more about how apply is defined (it mentions call), 
> > which really isn't important to me right now, so feel free to ignore 
> that 
> > part of my question.  Sorry. 
> > 
> > 
> > On Wednesday, 17 June 2015 09:45:46 UTC-3, andrew cooke wrote: 
> >> 
> >> 
> >> If I want to pass the function that constructs an array of Any, given 
> some 
> >> values, to another function, what do I use? 
> >> 
> >> Here's an example that might make things clearer: 
> >> 
> >> julia> f(x...) = Any[x...] 
> >> f (generic function with 1 method) 
> >> 
> >> julia> apply(f, 1,2,3) 
> >> 3-element Array{Any,1}: 
> >>  1 
> >>  2 
> >>  3 
> >> 
> >> julia> apply(Any[], 1,2,3) 
> >> ERROR: MethodError: `call` has no method matching call(::Array{Any,1}, 
> :: 
> >> Int64, ::Int64, ::Int64) 
> >> Closest candidates are: 
> >>   BoundsError(::Any...) 
> >>   TypeVar(::Any...) 
> >>   TypeConstructor(::Any...) 
> >>   ... 
> >>  in apply at deprecated.jl:116 
> >> 
> >> where I am looking for what the built-in equivalent of f() is. 
> >> 
> >> I may be even more confused, because I also don't understand why this 
> >> fails: 
> >> 
> >> julia> call(f, 1, 2) 
> >> ERROR: MethodError: `call` has no method matching call(::Function, 
> ::Int64 
> >> , ::Int64) 
> >> Closest candidates are: 
> >>   BoundsError(::Any...) 
> >>   TypeVar(::Any...) 
> >>   TypeConstructor(::Any...) 
> >>   ... 
> >> 
> >> So any guidance appreciated. 
> >> 
> >> Thanks, 
> >> Andrew 
> >> 
>
>

Reply via email to