develooper Front page | perl.perl6.users | Postings from November 2017

Re: Set difference using hashes vs array

Thread Previous | Thread Next
From:
Norman Gaywood
Date:
November 23, 2017 05:28
Subject:
Re: Set difference using hashes vs array
Message ID:
CAHJ-_U66Wq_YsTo+zHRNtp-LYhxzJUFxgYRC5HZ8GgRSUGLsQA@mail.gmail.com
Talking to myself :-)

Seems it has something to do with the values in the hash. If they are just
True, this works:
$ perl6
To exit type 'exit' or '^D'
> my %a= :k, :e, :r; my %r= :r; my %e= :e; my Set $s = %a (-) %r (-) %e;
set(k)



On 23 November 2017 at 16:20, Norman Gaywood <ngaywood@une.edu.au> wrote:

> For compactness, here are the 1-liners:
>
> $ perl6
> To exit type 'exit' or '^D'
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s =
> %a (-) %r (-) %e;
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏k' (indicated by ⏏)
>   in block <unit> at <unknown file> line 1
>
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s =
> (%a (-) %r) (-) %e;
> set(k)
> > my @a= "k", "e", "r"; my @r= "r"; my @e= "e"; my Set $s = @a (-) @r (-)
> @e;
> set(k)
> >
>
>
> On 23 November 2017 at 15:41, Norman Gaywood <ngaywood@une.edu.au> wrote:
>
>> I'm not sure what this error message means and what is going on here:
>> perl6 --version
>> This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
>> implementing Perl 6.c.
>>
>> $ cat tt-h.p6
>> #!/usr/bin/env perl6
>>
>> my %excludes = "exclude" => "exclude";
>> my %all = :keep("keep"), :exclude("exclude"), :remove("remove");
>> my %remove = :remove("remove");
>>
>> my Set $take1 = (%all (-) %remove) (-) %excludes;
>> dd $take1;
>> my Set $take2 = %all (-) %remove (-) %excludes;
>> dd $take2;
>>
>> $ ./tt-h.p6
>> Set $take1 = set("keep")
>> Cannot convert string to number: base-10 number must begin with valid
>> digits or '.' in '⏏remove' (indicated by ⏏)
>>   in block <unit> at ./tt-h.p6 line 10
>>
>> The difference in $take1 and $take2 are the brackets around the 1st set
>> operation.
>>
>> If I use arrays then no problem with either expression:
>>
>> $ cat tt-a.p6
>> #!/usr/bin/env perl6
>>
>> my @excludes = "exclude";
>> my @all = "keep", "exclude", "remove";
>> my @remove = "remove";
>>
>> my Set $take1 = (@all (-) @remove) (-) @excludes;
>> dd $take1;
>> my Set $take2 = @all (-) @remove (-) @excludes;
>> dd $take2;
>>
>> $ ./tt-a.p6
>> Set $take1 = set("keep")
>> Set $take2 = set("keep")
>>
>> --
>> Norman Gaywood, Computer Systems Officer
>> School of Science and Technology
>> University of New England
>> Armidale NSW 2351, Australia
>>
>> ngaywood@une.edu.au  http://turing.une.edu.au/~ngaywood
>> Phone: +61 (0)2 6773 2412 <(02)%206773%202412>  Mobile: +61 (0)4 7862
>> 0062
>>
>> Please avoid sending me Word or Power Point attachments.
>> See http://www.gnu.org/philosophy/no-word-attachments.html
>>
>
>
>
> --
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
>
> ngaywood@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412 <(02)%206773%202412>  Mobile: +61 (0)4 7862 0062
>
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>



-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngaywood@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

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