f(x, y, z) = return x^2, y^3, z^4
_, _, v = f(1, 2, 3)
However, this doesn’t work if you want to pick out more than one variable. E.g.
julia> function foo()
1,2,3
end
foo (generic function with 1 method)
julia> _, x, y = foo()
(1,2,3)
julia> x
2
julia> y
3
julia> _, x, y = foo()[2:3]
ERROR: BoundsError()
in indexed_next at /Users/ethananderes/Software/julia/usr/lib/julia/sys.dylib (repeats 2 times)
Is there a fancy way to handle this case?
Cheers,
Ethan
Oops, now I’m embarrassed. This is obviously how you do it.
julia> x, y = foo()[2:3]
(2,3)
julia> x
2
81
julia> f(x, y, z) = return x^2, y^3, z^4;
julia> g(a, b, c) = f(a, b, c)[3];
julia> @code_llvm g(1.0, 1.0, 1.0)
define double @"julia_g;767954"(double, double, double) {
top:
%3 = call double @pow(double %2, double 4.000000e+00), !dbg !525
ret double %3, !dbg !525
}
julia> function g(a, b, c)
_, _, v = f(a, b, c)
v
end;
julia> @code_llvm g(1.0, 1.0, 1.0)
define double @"julia_g;767955"(double, double, double) {
top:
%3 = call double @pow(double %2, double 4.000000e+00), !dbg !528
ret double %3, !dbg !530
}