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

Set difference using hashes vs array

Thread Next
From:
Norman Gaywood
Date:
November 23, 2017 04:42
Subject:
Set difference using hashes vs array
Message ID:
CAHJ-_U5e_MiKDG_NyXXHKiAOLtHAMWeovirtJs7+eZ5en_gXHw@mail.gmail.com
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

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