develooper Front page | perl.perl6.users | Postings from September 2018

Re: .kv ?

Thread Previous | Thread Next
From:
Todd Chester
Date:
September 14, 2018 10:44
Subject:
Re: .kv ?
Message ID:
493eea9b-8e97-f287-755e-283be77bf864@zoho.com
>> On Fri, 14 Sep 2018, 11:22 Todd Chester, <ToddAndMargo@zoho.com 
>> <mailto:ToddAndMargo@zoho.com>> wrote:
>> 
>>     Hi All,
>> 
>>     I adore the "kv" method:
>> 
>>     $ p6 'for "abc\n23\n4.56".lines.kv -> $i, $j { say "$i  $j" };'
>>     0  abc
>>     1  23
>>     2  4.56
>> 
>>     So, I decided to go and look at:
>>     https://docs.perl6.org/routine/kv
>> 
>>     multi method kv(Any:U:  -->List)
>>     multi method kv(Any:D:  -->List)
>> 
>> 
>>     Okay, here is what I see:
>> 
>>     "method"  is .foo style of a routine
>> 
>>     "Any:U:" and "Any:D:" are what goes in front of .foo
>>     and it can be of type "Any".
>> 
>>     https://docs.perl6.org/type/Any
>> 
>>            ":D" mean constrained, meaning it much have something
>> 
>>            What is ":U"?
>> 
>>            Whatever ":U", how can it be both?
>> 
>>     The second ":" is the delimiter for what goes in front of the .foo,
>>     meaning it has finished its declaration of what that in front is.
>>     Kind of like a comma.
>> 
>>     "-->List" mean something is returned of type "List"
>>     https://docs.perl6.org/type/List
>> 
>>            0  abc
>>            1  23
>>            2  4.56
>> 
>> 
>>     How have I done so far?
>> 
>> 
>>     And is there a list somewhere of the meanings of ":U" and ":D"
>>     and such so the next time I see one that I do not recognize,
>>     I can look it up?
>> 
>>     Many thanks,
>>     -T
>> 


On 09/14/2018 03:28 AM, Simon Proctor wrote:
> :D means a defined value. So it's when you have an instance. :U is 
> undefined so it's when you call kv as a classethod.
> 
> Pair.kv would be :U.
> (A => "b").kv would be :D
> 
> 

Hi Simion,

I am not following.  What do you mean by "undefined"?

I can't make head or tails out of "Pair"
https://docs.perl6.org/type/Pair

I thought ":D" meant "constrained"?

Yours in confusion ,
-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About