Actually, I was trying to think too much like tuples earlier… would a
subsignature work here?

…Turns out no. Seems unfortunate.

pyanfar Z$ perl6 derp.p6
===SORRY!=== Error while compiling /home/allbery/derp.p6
Unable to parse expression in typename; couldn't find final ')'
(corresponding starter was at line 1)
at /home/allbery/derp.p6:1
------> sub foo (Int $a --> List(Str⏏, Int)) { return ~$a, $a + 1 }


On Fri, Oct 12, 2018 at 6:44 PM Ralph Mellor <ralphdjmel...@gmail.com>
wrote:

> I imagine P6 may one day be changed to do as you suggest.
>
> But for now I think something like this is the closest you'll get:
>
> subset Str_Int of List where Str, Int;
>
> sub foo (--> Str_Int) { return 'a', 42 }
>
> --
> raiph
>
> On Fri, Oct 12, 2018 at 11:23 PM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> On 10/12/18 2:35 PM, Curt Tilmes wrote:
>> >
>> >
>> > On Fri, Oct 12, 2018 at 5:08 PM ToddAndMargo via perl6-users
>> > <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:
>> >
>> >      >>     On 10/12/18 12:52 PM, Curt Tilmes wrote:
>> >      >>      > You could make a subset for the List your're trying to
>> >     return:
>> >      >>      >
>> >      >>      > subset liststrint of List where .[0] ~~ Str && .[1] ~~
>> Int;
>> >      >>      > sub RtnOrd( Str $Char --> liststrint) ...
>> >      >>
>> >      >>     I am confused.
>> >      >>
>> >      >>     I want to get the --> syntax correct for `return $Char,
>> >     ord($Char)`
>> >
>> >     On 10/12/18 1:49 PM, Brad Gilbert wrote:
>> >      > That would be `List`
>> >      >
>> >      >      sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) }
>> >      >      say RtnOrd "A"
>> >      >      # (A 65)
>> >
>> >     $ p6 'sub RtnOrd( Str $Char --> List ){return $Char, ord($Char)};
>> say
>> >     RtnOrd "A";'
>> >     (A 65)
>> >
>> >     But "List" does not tell my what is in the list.
>> >
>> >
>> > You can create a brand new type, a subset of Lists where the first
>> element
>> > (we refer to with [0]) is of type Str (~~ Str) and the second element
>> of
>> > the List
>> > (we refer to with [1]) is of type Int (~~ Int).
>> >
>> > Define it like this:
>> > subset list-str-int of List where .[0] ~~ Str && .[1] ~~ Int;
>> >
>> > then you can say that your routine returns a list that looks like that:
>> >
>> >   sub RtnOrd( Str $Char --> list-str-int)
>> >
>>
>> Is there any way to say I am return two things: a string and an integer?
>>
>

-- 
brandon s allbery kf8nh
allber...@gmail.com

Reply via email to