A function may return multiple values by returning a sequence. Multiple assignment (see =) or multiple local assignment (see :=) can be used to assign the values to separate variables, if the number of values to be returned is known.
i1 : f = i -> (i, i^2, i^3); |
i2 : (x,y,z) = f 3 o2 = (3, 9, 27) o2 : Sequence |
i3 : x o3 = 3 |
i4 : y o4 = 9 |
i5 : z o5 = 27 |
Simple assignment may be used if the number of values to be returned is unknown.
i6 : s = f 4 o6 = (4, 16, 64) o6 : Sequence |
i7 : #s o7 = 3 |
i8 : s_0 o8 = 4 |
i9 : s_1 o9 = 16 |
i10 : s_2 o10 = 64 |