On Tue, 16 Dec 2008, David Green wrote:

On 2008-Dec-6, at 7:37 am, Aristotle Pagaltzis wrote:
Funnily enough, I think you?re onto something here that you didn?t even notice: [...] if we had a NOTFIRST (which would run before ENTER just as FIRST does, but on *every* iteration *except* the first), then we could trivially attain the correct semantics and achieve all desired results:

  repeat {
      @stuff = grep { !.valid }, @stuff };
      NOTFIRST {
          .do_something( ++$i ) for @stuff;
      }
  } while @stuff;

The really nice thing about this is that the blocks are nested, so that any variable in scope for the invariant enforcement will also be in scope in the NOTFIRST block without the user ever having to arrange another enclosing scope.

Oh, yes! So what if we had "LOOP $n {}" that executed on the nth iteration? "LOOP 0 {}" at the beginning would be like FIRST {}, "LOOP * {}" at the end would be like LAST {}, and "LOOP 1..* {}" would give us the NOTFIRST block. Presumably you could have multiple LOOP blocks too.

(Actually, you couldn't quite do FIRST/LAST using LOOP $n, because FIRST/LAST occur outside ENTER/LEAVE, whereas LOOP would occur inside. But perhaps you could have LOOP blocks inside ENTER/LEAVE blocks?)

Or, instead of having a new block, just add the iterator indicator to the NEXT block, and get rid of ENTER and LEAVE. That way, you'd have this sequence:

-       FIRST {}
-       NEXT 0 {} # Replaces ENTER
-       NEXT 1..* {} # Does NOTFIRST
-       NEXT * {} # Replaces LEAVE
-       LAST {}

        Would that do it?

The difficulty to my mind would be sequencing the NEXT blocks; does the NEXT 1..* run before or after NEXT 2..(*-2) ? Maybe we need a NEXT stack.

        :)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayl...@wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to