Advertisement
cwchen

[Perl 6] Creating and removing elements from sets.

Nov 8th, 2017
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.46 KB | None | 0 0
  1. my $set = (1, 2, 3).SetHash;
  2. $set.elems == 3 or die "Wrong element count";
  3.  
  4. # Add a new element.
  5. $set{4} = True;
  6. $set.elems == 4 or die "Wrong element count";
  7.  
  8. # Add a duplicated element, no effect.
  9. $set{3} = True;
  10. $set.elems == 4 or die "Wrong element count";
  11.  
  12. # Remove an element.
  13. $set{1} = False;
  14. $set.elems == 3 or die "Wrong element count";
  15.  
  16. # Remove a non-existing element, no effect.
  17. $set{1} = False;
  18. $set.elems == 3 or die "Wrong element count";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement