Created
July 14, 2012 01:52
-
-
Save rsimoes/3108774 to your computer and use it in GitHub Desktop.
Set::Builder synopsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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