Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

any(@originals) ~~ { .foo eq $bar} (was Re: renaming "grep" to "where")

2 views
Skip to first unread message

Markus Laire

unread,
Sep 19, 2006, 7:51:56 AM9/19/06
to perl6-l...@perl.org
On 9/19/06, Trey Harris <tr...@lopsa.org> wrote:
> In a message dated Mon, 18 Sep 2006, Darren Duncan writes:
> > @filtered = @originals.where:{ .foo eq $bar };
>
> Note that this can be written:
>
> @filtered = any(@originals) ~~ { .foo eq $bar};

This doesn't seem to be correct.

According to S03 junctions "thread through operations, returning
another junction representing the result". Instead of returning the
filtered values, this seems to allways return one of
any(Bool::False) # If all comparisons were false
any(Bool::True) # If all comparisons were true
any(Bool::False, Bool::True) # If some comparisons were false and some true

Testing a concrete example in pugs (r13034):
pugs> my @a = (1..10);
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
pugs> any(@a) ~~ { $_ < 0 }
(Bool::False)
pugs> any(@a) ~~ { $_ > 0 }
(Bool::True)
pugs> any(@a) ~~ { $_ % 2 }
(Bool::False | Bool::True)

--
Markus Laire

Trey Harris

unread,
Sep 19, 2006, 12:34:13 PM9/19/06
to Markus Laire, perl6-l...@perl.org
In a message dated Tue, 19 Sep 2006, Markus Laire writes:

> On 9/19/06, Trey Harris <tr...@lopsa.org> wrote:
>> In a message dated Mon, 18 Sep 2006, Darren Duncan writes:
>> > @filtered = @originals.where:{ .foo eq $bar };
>>
>> Note that this can be written:
>>
>> @filtered = any(@originals) ~~ { .foo eq $bar};
>
> This doesn't seem to be correct.

See S09. "In particular,

@result = any(@x) ~~ {...};

is equivalent to

@result = grep {...}, @x;"

> Testing a concrete example in pugs (r13034):
> pugs> my @a = (1..10);
> (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
> pugs> any(@a) ~~ { $_ < 0 }
> (Bool::False)
> pugs> any(@a) ~~ { $_ > 0 }
> (Bool::True)
> pugs> any(@a) ~~ { $_ % 2 }
> (Bool::False | Bool::True)

This feature is unimplemented.

Trey

0 new messages