Here is a fun and possibly useful solution (that works only on 0.4 due to 
call overloading):

https://gist.github.com/dpsanders/d8ef239ec8c78c4debee

It introduces a `MultidimFunction` type, and a macro `@multidim` that works 
as follows:

julia> @multidim f(x) = [sqrt(x[1]), 2x[2]]
MultidimFunction([(anonymous function),(anonymous function)])

julia> f([1., 2.])
2-element Array{Float64,1}:
 1.0
 4.0

julia> x = [1., 2.]
2-element Array{Float64,1}:
 1.0
 2.0

julia> f(x)
2-element Array{Float64,1}:
 1.0
 4.0

julia> f[1](x)
1.0

julia> f[2](x)
4.0

julia> y = [-1., 2.]
2-element Array{Float64,1}:
 -1.0
  2.0

julia> f[1](y)
ERROR: DomainError:
sqrt will only return a complex result if called with a complex argument.
try sqrt (complex(x))
 in sqrt at ./math.jl:144
 in anonymous at 
/Users/dsanders/.julia/v0.3/ValidatedNumerics/src/multidim/multidim_functions.jl:49

julia> f[2](y)
4.0

David.

Reply via email to