Hi all,
I wonder what would be the Perl notation for 'set-builders', as exposed
in this wikipedia article:
https://en.wikipedia.org/wiki/Set-builder_notation#Parallels_in_programming_languages
This is the Python notation:
Example 1: {l for l in L}
Example 2: {(k, x) for k in K for x in X if P(x)}
This is another example in Python:
s = {v for v in 'ABCDABCD' if v not in 'CB'}
https://en.wikipedia.org/wiki/List_comprehension#Similar_constructs
I have been playing with the code below. Nevertheless, I am unsure on
how to use the code to define a set.
Cheers!
<--- Code
#!/usr/bin/env perl6
my @L = 1 .. 10;
my @K = 1 .. 10;
my @X = 5 .. 15;
say "Example 1:";
for @L -> $l {
print "$l " if $l ∈ @L;
}
say "\nExample 2:";
for @K -> $k { for @X -> $x {
print "($k, $x), " if ($k ∈ @K and $x ∈ @X and $x < 8);
}}
<---
--
(≧∇≦) Mimosinnet (Linux User: #463211)