Hi,

Larry Wall wrote:
> On Sun, Nov 20, 2005 at 08:51:03PM +0100, Ingo Blechschmidt wrote:
> : according to the new S03, till is the new name for the flipflop
> : operator.
> 
> Presuming we can make it work out as an infix macro.

Ah, it's a macro. This clarifies things.

> : Do the flipflop operators of subroutines maintain own
> : per-invocation-of-the-sub states? I.e.:
> : 
> :     sub foo (&x) { x() till 0 }
> : 
> :     foo { 0 };  # evaluates to a false value, of course
> : 
> :     foo { 1 };  # evaluates to a true value, of course
> :     foo { 0 };
> :     # still true?
> :     #   (Argumentation: The flipflop is in the "true" state,
> :     #   so the LHS is not evaluated.)
> :     # Or is it false?
> :     #   (Argumentation: The flipflop operator of the previous
> :     #   invocation is not the flipflop operator of the current
> :     #   invocation, so the return value is false.)
> 
> It's still true.  Ignoring the "E0" issue, the desugar of "A till B"
> is something like:
[...]

Thanks very much, this code is very clear. :)

> : Also, all operators can be called using the subroutine form (which
> : is a very good thing), e.g.:
> : 
> :     say infix:<->(42, 19);  # 23
> : 
> : Is this true for till as well?
> : 
> :     say infix:<till>(LHS, RHS);
> 
> Probably not.  Calling macros as functions is a bit of a problem.

Yep. (I assumed &infix:<till> would be an ordinary subroutine.)

> : But how would &infix:<till> maintain the state then, as no explicit
> : ID is passed to it? Does &infix:<till> access an internal %states
> : hash, using $CALLER::POSITION as keys?
> 
> That feels like a hack to me.  I'd rather find a way of poking a real
> state variable into the caller's scope if we have to support that.

Agreed. The desugar you provides feels far more sane.

> : Perl 5's flipflop operator appends "E0" to the final sequence number
> : in a range, allowing searches for /E/. My guess is that this is
> : superseded by "$sequence_number but
> : this_is_the_endpoint_of_the_range" (you get the idea). Correct?
> 
> I was just thinking that you'd use till^ if you wanted to exclude the
> endpoint.  And ^till to exclude the beginning, and ^till^ to exclude
> both, just as with ..^, ^.., and ^..^.

Ok.

> In fact, that's really my main motivation for wanting it to be infix.
> Otherwise it might as well be an ordinary flipflip() macro, or
> fromto().

Makes sense.


--Ingo

Reply via email to