> On 22 Jan 2020, at 01:17, Todd Chester via perl6-users <[email protected]>
> wrote:
>
> Hi All,
>
> What is the syntax for returning two variable from a sub?
>
> > sub x(--> Int, UInt) { return(-2,4) };
>
> ===SORRY!=== Error while compiling:
> Malformed return value (return constraints only allowed at the end of the
> signature)
> ------> sub x(--> Int⏏, UInt) { return(-2,4) };
Raku *ALWAYS* only returns a *SINGLE* value.
That value may be a List.
The comma is the operator that creates Lists.
`return 1,2,3` is therefore returning a List with 1, 2 and 3 as its elements.
if you say: `my ($a,$b,$c)`, you're creating a List with three variables in
them.
if you say: `my ($a,$b,$c) = foo` and `sub foo() { return 1,2,3 }` you will
effectively assign a list of values to a list of variables, assigning 1 to $a,
2 to $b, 3 to $c.