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

Control Structures III: flow modifiers

5 views
Skip to first unread message

Timothy S. Nelson

unread,
Nov 14, 2002, 3:46:21 PM11/14/02
to perl6-l...@perl.org
These are mostly not my ideas (except activate); hopefully not too
many of them have already been used.

In the same list as "last", "next", and "redo", we should also have
- deeper (works with nest -- cf. II: loop)
- yield and resume (for co-routines)

Also useful could be:
activate <blockname>
deactivate <blockname>

Useful for optimising:
---------------------------------------
$first = 1;
foreach (@example) {
if($first) {
do_something;
$first = 0;
} else {
do_normal_stuff;
}
}
---------------------------------------

Can be done as:

---------------------------------------

LABEL: foreach(@example) {
OTHEREXAMPLE: {
do_something;
deactivate OTHEREXAMPLE;
next LABEL;
}
do_normal_stuff;
}

---------------------------------------

In the example above, the code could modify itself so that
OTHEREXAMPLE would not get used at all after the first time (just have an
appropriate assembly jump or something).

Anyway, that pretty much covers my ideas on Control Structures.

:)

---------------------------------------------------------------------
| Name: Tim Nelson | Because the Creator is, |
| E-mail: way...@smartchat.net.au | I am |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.1
GCS d? s: a-- C++>++++$ US+ P++ L++ E- W+++ N+ w+> M-- V- Y+>++
PGP->++ R(+) !tv B++ DI++++ D+ G e>++ h!/* y-
-----END GEEK CODE BLOCK-----


Luke Palmer

unread,
Nov 14, 2002, 2:02:50 PM11/14/02
to way...@smartchat.net.au, perl6-l...@perl.org
> Mailing-List: contact perl6-lan...@perl.org; run by ezmlm
> Date: Fri, 15 Nov 2002 07:46:21 +1100 (EST)
> From: "Timothy S. Nelson" <way...@smartchat.net.au>
> Sender: way...@elphin.nelson.org.au
> X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/

Also, it could be done as:

for @example { # the foreach keyword has gone away
FIRST {
do_something;
next;
}
do_normal_stuff;
}

Beautiful.

Deactivating blocks, on a more general scale (if you find it useful),
can be achieved because of the new concept of "everything is a
closure":

our bit %inactive;
sub block ($name: &block) {
&block() unless %inactive{$name}
}
sub deactivate ($name) {
%inactive{$name} = 1
}

LABEL: foreach(@example) {
block 'OTHEREXAMPLE': {

0 new messages