Re: how do you --> two variables?
On 2020-01-22 10:25, ToddAndMargo via perl6-users wrote: On 2020-01-21 16:17, Todd Chester via perl6-users 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) }; Many thanks, -T The guys on the chat line gave me a work around: subset Tuple where * ~~ (Int, UInt, Str); sub f($a,$b,$c --> Tuple) { ($a,$b,$c) }; say f(-1, 'x', 5) # out of order, fails. And I just added: RFE: returns for multiple variables #152 https://github.com/Raku/problem-solving/issues/152 And thanks to the guys on the chat line, I hvae a pretty workaround.
Re: how do you --> two variables?
On 2020-01-21 16:17, Todd Chester via perl6-users 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) }; Many thanks, -T The guys on the chat line gave me a work around: subset Tuple where * ~~ (Int, UInt, Str); sub f($a,$b,$c --> Tuple) { ($a,$b,$c) }; say f(-1, 'x', 5) # out of order, fails.
Re: how do you --> two variables?
> On 22 Jan 2020, at 01:17, Todd Chester via perl6-users > 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.
how do you --> two variables?
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) }; Many thanks, -T