list comprehension

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)
0
mimosinnet
2/10/2019 4:26:30 PM
perl.perl6.users 1202 articles. 0 followers. Follow

6 Replies
81 Views

Similar Articles

[PageSpeed] 20

In

     {l for l in L}

The reason it is in `{}` is to create a Set from iterating over `L`.

> In Python, the set-builder's braces are replaced with square brackets, pa=
rentheses, or curly braces, giving list, generator, and set objects, respec=
tively.

So in Python:

    [ l for l in L ]     gives a list
    ( l for l in L )     gives a generator
    { l for l in L }     gives a set

In Perl6 those would most likely be written as:

    L.List   or   L.Array   or   L.list
    L.Seq
    L.Set

---

The way to do that is

    my \L =3D ((1..10) xx 3).flat.pick(*).list;

    set( L ) # A
    L.Set # B

    my %set is SetHash;
    { ++%set{$_} for L }  # C

    # D
    do {
        # add the {} syntax to create a Set (lexically)
        my sub circumfix:=C2=AB{ }=C2=BB ( \L ) { L.Set };

        { $_ for L } # <--
    }

Something that seems similar to me is `unique`

    .say for L.unique;

By that I mean, some places where you would use a Set, it makes sense
to use `.unique` instead

---

As for `{(k, x) for k in K for x in X if P(x)}`

The easiest one to directly translate appears to be the Scala one

    my \K =3D 1..10;
    my \X =3D 5..15;

    # for (k <- K; x <- X if P(x)) yield (k,x)
    Set.new: gather {
        for K -> \k {
            for X -> \x {
                if P(x) {
                    take (k,x);
                }
            }
        }
    }

Other ways:

    Set.new: (K X[,] X).grep: -> ( \k, \x ) { P(x) }

    Set.new: K X[,] X.grep: &P

    Set.new: K X[,] X.grep: &P

    Set.new: ( -> ( \k, \x ) { (k,x) if P(x) } for K X[,] X )

    Set.new: ( -> \x { |(-> \k { (k,x) if P x } for K) } for X)

On Sun, Feb 10, 2019 at 10:26 AM mimosinnet <mimosinnet@gmail.com> wrote:
>
> 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_programmi=
ng_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 =3D {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 =3D 1 .. 10;
> my @K =3D 1 .. 10;
> my @X =3D 5 .. 15;
>
> say "Example 1:";
> for @L -> $l {
>   print "$l " if $l =E2=88=88 @L;
> }
>
> say "\nExample 2:";
> for @K -> $k { for @X -> $x {
>     print "($k, $x), " if ($k =E2=88=88 @K and $x =E2=88=88 @X and $x < 8=
);
> }}
> <---
>
> --
> (=E2=89=A7=E2=88=87=E2=89=A6) Mimosinnet (Linux User: #463211)
0
b2gills
2/10/2019 6:05:35 PM
Dear Brad,

Thanks very much for the answer. I have been playing with your examples in the
code below (and learned a lot!). Based on your insight, I would suggest these
solutions to be added to the wikipedia:
https://en.wikipedia.org/wiki/Set-builder_notation#Parallels_in_programming_languages

Example1: Set.new: gather { for L { take $_ } };
Example2: Set.new: cross( K, X.grep: P(x) );

Cheers!

<--- Working code
my \L = 1..10; my \K = 1..10; my \X = 5..15;

# Example 1
my $e1 = Set.new: gather { for L { take $_ } };

# Example 2
my $s1 = Set.new: gather {
   for K -> \k {
       for X -> \x {
           if x < 8 {
               take (k,x);
           }
       }
   }
}
my $s2 = Set.new: (K X[,] X).grep: -> ( \k, \x ) { x < 8 };
my $s3 = Set.new: ( -> \x { |(-> \k { (k,x) if x < 8 } for K) } for X );
my $s4 = Set.new: gather { -> \k { -> \x { take (k,x) if x < 8; } for X } for K }
my $s5 = Set.new: cross( K, X.grep: * < 8 );

say $e1; say $s1; say $s2; say $s3; say $s4; say $s5;
<---

El Sunday, 10 de February del 2019 a les 12:05, Brad Gilbert va 
escriure:

>In
>
>     {l for l in L}
>
>The reason it is in `{}` is to create a Set from iterating over `L`.
>
>> In Python, the set-builder's braces are replaced with square brackets, parentheses, or curly braces, giving list, generator, and set objects, respectively.
>
>So in Python:
>
>    [ l for l in L ]     gives a list
>    ( l for l in L )     gives a generator
>    { l for l in L }     gives a set
>
>In Perl6 those would most likely be written as:
>
>    L.List   or   L.Array   or   L.list
>    L.Seq
>    L.Set
>
>---
>
>The way to do that is
>
>    my \L = ((1..10) xx 3).flat.pick(*).list;
>
>    set( L ) # A
>    L.Set # B
>
>    my %set is SetHash;
>    { ++%set{$_} for L }  # C
>
>    # D
>    do {
>        # add the {} syntax to create a Set (lexically)
>        my sub circumfix:«{ }» ( \L ) { L.Set };
>
>        { $_ for L } # <--
>    }
>
>Something that seems similar to me is `unique`
>
>    .say for L.unique;
>
>By that I mean, some places where you would use a Set, it makes sense
>to use `.unique` instead
>
>---
>
>As for `{(k, x) for k in K for x in X if P(x)}`
>
>The easiest one to directly translate appears to be the Scala one
>
>    my \K = 1..10;
>    my \X = 5..15;
>
>    # for (k <- K; x <- X if P(x)) yield (k,x)
>    Set.new: gather {
>        for K -> \k {
>            for X -> \x {
>                if P(x) {
>                    take (k,x);
>                }
>            }
>        }
>    }
>
>Other ways:
>
>    Set.new: (K X[,] X).grep: -> ( \k, \x ) { P(x) }
>
>    Set.new: K X[,] X.grep: &P
>
>    Set.new: K X[,] X.grep: &P
>
>    Set.new: ( -> ( \k, \x ) { (k,x) if P(x) } for K X[,] X )
>
>    Set.new: ( -> \x { |(-> \k { (k,x) if P x } for K) } for X)
>
>On Sun, Feb 10, 2019 at 10:26 AM mimosinnet <mimosinnet@gmail.com> wrote:
>>
>> 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)

-- 
(≧∇≦) Mimosinnet (Linux User: #463211)

(≧∇≦) Ningún Lugar
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
★ Activisme Cultural per a la Transformació Social

(≧∇≦) Fractalitats en Investigació Crítica
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
* Investigació Crítica per a la Transformació Social
* http://psicologiasocial.uab.es/fic
0
mimosinnet
2/11/2019 6:51:36 PM
Actually I would suggest NOT adding Perl6, because the best way to
create a Set is not to use =E2=80=9Clist comprehension=E2=80=9D, but to jus=
t call
`.Set`

That whole page is about Set Builder Notation, but Perl6 doesn't
actually have such a thing.

You create a Set through a method call, or a subroutine call.

That is true even in the translations I did.

The closest one is where I added a circumfix operator.

    my sub circumfix:=C2=AB{ }=C2=BB ( \L ) { L.Set };

I mean this:

    Set.new: gather { for L { take $_ } };

can be simplified to:

    Set.new( L );

Or if you're being pedantic:

    Set.new( L.Seq );

On Mon, Feb 11, 2019 at 12:51 PM mimosinnet <mimosinnet@gmail.com> wrote:
>
> Dear Brad,
>
> Thanks very much for the answer. I have been playing with your examples i=
n the
> code below (and learned a lot!). Based on your insight, I would suggest t=
hese
> solutions to be added to the wikipedia:
> https://en.wikipedia.org/wiki/Set-builder_notation#Parallels_in_programmi=
ng_languages
>
> Example1: Set.new: gather { for L { take $_ } };
> Example2: Set.new: cross( K, X.grep: P(x) );
>
> Cheers!
>
> <--- Working code
> my \L =3D 1..10; my \K =3D 1..10; my \X =3D 5..15;
>
> # Example 1
> my $e1 =3D Set.new: gather { for L { take $_ } };
>
> # Example 2
> my $s1 =3D Set.new: gather {
>    for K -> \k {
>        for X -> \x {
>            if x < 8 {
>                take (k,x);
>            }
>        }
>    }
> }
> my $s2 =3D Set.new: (K X[,] X).grep: -> ( \k, \x ) { x < 8 };
> my $s3 =3D Set.new: ( -> \x { |(-> \k { (k,x) if x < 8 } for K) } for X )=
;
> my $s4 =3D Set.new: gather { -> \k { -> \x { take (k,x) if x < 8; } for X=
 } for K }
> my $s5 =3D Set.new: cross( K, X.grep: * < 8 );
>
> say $e1; say $s1; say $s2; say $s3; say $s4; say $s5;
> <---
>
> El Sunday, 10 de February del 2019 a les 12:05, Brad Gilbert va
> escriure:
>
> >In
> >
> >     {l for l in L}
> >
> >The reason it is in `{}` is to create a Set from iterating over `L`.
> >
> >> In Python, the set-builder's braces are replaced with square brackets,=
 parentheses, or curly braces, giving list, generator, and set objects, res=
pectively.
> >
> >So in Python:
> >
> >    [ l for l in L ]     gives a list
> >    ( l for l in L )     gives a generator
> >    { l for l in L }     gives a set
> >
> >In Perl6 those would most likely be written as:
> >
> >    L.List   or   L.Array   or   L.list
> >    L.Seq
> >    L.Set
> >
> >---
> >
> >The way to do that is
> >
> >    my \L =3D ((1..10) xx 3).flat.pick(*).list;
> >
> >    set( L ) # A
> >    L.Set # B
> >
> >    my %set is SetHash;
> >    { ++%set{$_} for L }  # C
> >
> >    # D
> >    do {
> >        # add the {} syntax to create a Set (lexically)
> >        my sub circumfix:=C2=AB{ }=C2=BB ( \L ) { L.Set };
> >
> >        { $_ for L } # <--
> >    }
> >
> >Something that seems similar to me is `unique`
> >
> >    .say for L.unique;
> >
> >By that I mean, some places where you would use a Set, it makes sense
> >to use `.unique` instead
> >
> >---
> >
> >As for `{(k, x) for k in K for x in X if P(x)}`
> >
> >The easiest one to directly translate appears to be the Scala one
> >
> >    my \K =3D 1..10;
> >    my \X =3D 5..15;
> >
> >    # for (k <- K; x <- X if P(x)) yield (k,x)
> >    Set.new: gather {
> >        for K -> \k {
> >            for X -> \x {
> >                if P(x) {
> >                    take (k,x);
> >                }
> >            }
> >        }
> >    }
> >
> >Other ways:
> >
> >    Set.new: (K X[,] X).grep: -> ( \k, \x ) { P(x) }
> >
> >    Set.new: K X[,] X.grep: &P
> >
> >    Set.new: K X[,] X.grep: &P
> >
> >    Set.new: ( -> ( \k, \x ) { (k,x) if P(x) } for K X[,] X )
> >
> >    Set.new: ( -> \x { |(-> \k { (k,x) if P x } for K) } for X)
> >
> >On Sun, Feb 10, 2019 at 10:26 AM mimosinnet <mimosinnet@gmail.com> wrote=
:
> >>
> >> Hi all,
> >>
> >> I wonder what would be the Perl notation for 'set-builders', as expose=
d
> >> in this wikipedia article:
> >>
> >> https://en.wikipedia.org/wiki/Set-builder_notation#Parallels_in_progra=
mming_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 =3D {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 =3D 1 .. 10;
> >> my @K =3D 1 .. 10;
> >> my @X =3D 5 .. 15;
> >>
> >> say "Example 1:";
> >> for @L -> $l {
> >>   print "$l " if $l =E2=88=88 @L;
> >> }
> >>
> >> say "\nExample 2:";
> >> for @K -> $k { for @X -> $x {
> >>     print "($k, $x), " if ($k =E2=88=88 @K and $x =E2=88=88 @X and $x =
< 8);
> >> }}
> >> <---
> >>
> >> --
> >> (=E2=89=A7=E2=88=87=E2=89=A6) Mimosinnet (Linux User: #463211)
>
> --
> (=E2=89=A7=E2=88=87=E2=89=A6) Mimosinnet (Linux User: #463211)
>
> (=E2=89=A7=E2=88=87=E2=89=A6) Ning=C3=BAn Lugar
> =E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=
=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=
=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=
=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=
=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=
=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=
=AC=E2=96=AC=E2=96=AC
> =E2=98=85 Activisme Cultural per a la Transformaci=C3=B3 Social
>
> (=E2=89=A7=E2=88=87=E2=89=A6) Fractalitats en Investigaci=C3=B3 Cr=C3=ADt=
ica
> =E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=
=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=
=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=
=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=
=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=
=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=AC=E2=96=
=AC=E2=96=AC=E2=96=AC
> * Investigaci=C3=B3 Cr=C3=ADtica per a la Transformaci=C3=B3 Social
> * http://psicologiasocial.uab.es/fic
>
0
b2gills
2/11/2019 11:04:14 PM
RWwgTW9uZGF5LCAxMSBkZSBGZWJydWFyeSBkZWwgMjAxOSBhIGxlcyAxNzowNCwgQnJhZCBHaWxi
ZXJ0IHZhIGVzY3JpdXJlOg0KDQo+QWN0dWFsbHkgSSB3b3VsZCBzdWdnZXN0IE5PVCBhZGRpbmcg
UGVybDYsIGJlY2F1c2UgdGhlIGJlc3Qgd2F5IHRvDQo+Y3JlYXRlIGEgU2V0IGlzIG5vdCB0byB1
c2Ug4oCcbGlzdCBjb21wcmVoZW5zaW9u4oCdLCBidXQgdG8ganVzdCBjYWxsDQo+YC5TZXRgDQoN
ClVwcyA6TyAuVGhhbmtzIGZvciB0aGUgY29uY2VwdHVhbCBjbGFyaWZpY2F0aW9uLiA6RCAgSSB3
aWxsIGxlYXZlIFBlcmw2IA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O6biBMdWdhcg0KPj4g4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas
4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas
4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas4pas
4pas4pas4pasDQo+PiDimIUgQWN0aXZpc21lIEN1bHR1cmFsIHBlciBhIGxhIFRyYW5zZm9ybWFj
acOzIFNvY2lhbA0KPj4NCj4+ICjiiafiiIfiiaYpIEZyYWN0YWxpdGF0cyBlbiBJbnZlc3RpZ2Fj
acOzIENyw610aWNhDQo+PiDilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzi
lqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzi
lqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzilqzi
lqwNCj4+ICogSW52ZXN0aWdhY2nDsyBDcsOtdGljYSBwZXIgYSBsYSBUcmFuc2Zvcm1hY2nDsyBT
b2NpYWwNCj4+ICogaHR0cDovL3BzaWNvbG9naWFzb2NpYWwudWFiLmVzL2ZpYw0KPj4NCg0KLS0g
DQoNCkpvYW4gUHVqb2wgVGFycsOpcw0KRGVwYXJ0YW1lbnQgZGUgUHNpY29sb2dpYSBTb2NpYWwN
CkZhY3VsdGF0IGRlIFBzaWNvbG9naWEsIFVuaXZlcnNpdGF0IEF1dMOybm9tYSBkZSBCYXJjZWxv
bmENCkRlc3BhdHg6IEI1LTAzNiAoUGFzc2Fkw61zIERlcGFydGFtZW50IFBzaWNvbG9naWEgU29j
aWFsKQ0KRWRpZmljaSBCLCAwODE5MyBCZWxsYXRlcnJhIChCYXJjZWxvbmEpLCBGYXg6ICszNCA5
MzU4MTIwMDENCg0KaHR0cDovL29yY2lkLm9yZy8wMDAwLTAwMDItMDQ2Mi0zMjc4DQpodHRwczov
L3BvcnRhbHJlY2VyY2EuY3N1Yy5jYXQvb3JjaWQvMDAwMC0wMDAyLTA0NjItMzI3OA0K
0
Joan
2/13/2019 1:19:37 AM
Hello folks. Did I understand correctly that this thread is about list
comprehension syntax in Perl 6? :-)
I don't if it was mentioned, but I think this syntax just simply works
already. See an example:

  > say ($_~$_ if $_ %% 2 for ^10).Set
  set(00 22 44 66 88)

  > say ($_.item if $_[0] eq 'a' or $_[1] == 2 for <a b c> X ^3).Set
  set((a 0) (a 1) (a 2) (b 2) (c 2))

(Just drop the .Set from the end if it's not needed)
0
lucasbuchala
2/22/2019 5:41:14 PM
Yes, +1 and we have this documented on the py-to-perl6 nutshell page:

https://docs.perl6.org/language/py-nutshell#List_comprehensions

On Friday, February 22, Lucas Buchala wrote: 
> Hello folks. Did I understand correctly that this thread is about list
> comprehension syntax in Perl 6? :-)
> I don't if it was mentioned, but I think this syntax just simply works
> already. See an example:
> 
>   > say ($_~$_ if $_ %% 2 for ^10).Set
>   set(00 22 44 66 88)
> 
>   > say ($_.item if $_[0] eq 'a' or $_[1] == 2 for <a b c> X ^3).Set
>   set((a 0) (a 1) (a 2) (b 2) (c 2))
> 
> (Just drop the .Set from the end if it's not needed)
0
bduggan2
2/24/2019 3:06:43 PM
Reply: