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

Re: forany, forall...

69 views
Skip to first unread message

Jonathan Scott Duff

unread,
Jan 17, 2005, 12:38:19 AM1/17/05
to Jonathan Lang, Perl6
On Sun, Jan 16, 2005 at 09:27:56PM -0800, Jonathan Lang wrote:
> How would I do the following in Perl 6?

Modulo any syntax foibles, I think it'd look like this:

>
> if a given condition is true for every element in a list, do something.

if all(LIST) > 3 { do_something }

>
> or
>
> if a given condition is true for any element in a list, do something.

if any(LIST) > 3 { do_something }

Where LIST is, of course, the actual list of things. The exact syntax
of the conditional would change with what you wish to test.

if all(LIST) ~~ /foo/ { do_something }

if 7 < all(LIST) < 15 { do_something }

if all(LIST) eq 'fred' { do_something }


-Scott
--
Jonathan Scott Duff
du...@pobox.com

Jonathan Lang

unread,
Jan 17, 2005, 12:27:56 AM1/17/05
to Perl6
How would I do the following in Perl 6?

if a given condition is true for every element in a list, do something.

or

if a given condition is true for any element in a list, do something.

=====
Jonathan "Dataweaver" Lang



__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

Brent 'Dax' Royal-Gordon

unread,
Jan 17, 2005, 12:31:39 AM1/17/05
to Jonathan Lang, Perl6
Both of your questions are quite elegantly handled by junctions. If
the condition were, say, $elem > 10:

Jonathan Lang <datawe...@yahoo.com> wrote:
> if a given condition is true for every element in a list, do something.

if all(@list) > 10 { ... }

> if a given condition is true for any element in a list, do something.

if any(@list) > 10 { ... }

--
Brent 'Dax' Royal-Gordon <br...@brentdax.com>
Perl and Parrot hacker

"For those of you that can't spell, this site also contains free
imags, iamges, imges, picturs, pcitures, picktures, picturess, and
pistures."

0 new messages