Skip to content

Instantly share code, notes, and snippets.

@rsimoes
Created July 14, 2012 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsimoes/3108774 to your computer and use it in GitHub Desktop.
Save rsimoes/3108774 to your computer and use it in GitHub Desktop.
Set::Builder synopsis
use Set::Builder qw(Set Var for_all);
# set constructor, roster style:
my $set = Set { 0..9 };
# element variable constructor:
my ($x, $y) = (Var) x 2;
# subset consisting of the numbers 0 and 1
my $subset1 = Set { $x ~~ $set | $x ~~ Set { 0..1 } };
# subset also consisting of the numbers 0 and 1:
my $subset2 = Set { $x ~~ $set | $x ~~ Set { -1..1 } };
# subset consisting of the numbers 0, 1, and 10:
my $subset4 = Set { $subset1 + Set { 10 } };
# subset consisting of the number 9:
my $subset5 = Set { $x ~~ $set | for_all $y ~~ $set, $x >= $y };
# empty subset:
my $subset6 = Set { $x ~~ $set | for_all $y ~~ $set, $x != $y };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment