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

Re: Set difference using hashes vs array

Thread Previous
From:
Elizabeth Mattijsen
Date:
November 23, 2017 10:16
Subject:
Re: Set difference using hashes vs array
Message ID:
401DF05D-CB24-4B91-8F61-A7B96E977C16@dijkmat.nl
Will have a look at this in about 12 hours (probably).  Meanwhile, don’t let that stop anyone from figuring this out  :-)


> On 23 Nov 2017, at 05:27, Norman Gaywood <ngaywood@une.edu.au> wrote:
> 
> 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  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
> 
> 
> 
> -- 
> 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


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