On Sat, Dec 04, 2004 at 01:11:30AM +0100, Juerd wrote: : What happens to the flip flop operator? Will .. in scalar context remain : the same?
I don't think so. It's definitely a candidate for a longer Huffmanization simply in terms of frequency of use. On top of which, almost no Perl 5 programmers even know what it does. Plus it's basically opaque state in the pad. Not that opaque is bad when you want the abstraction, but I would characterize the state of scalar .. as almost "sneaky" state. Plus we have the problem that we don't have a $. variable anymore, nor really the concept of "last input handle". I expect the p5-to-p6 translator will have to detect any references to $. and set some kind of global $*LASTIN handle on input, and define &p5dot to be $*LASTIN.chunknum or some such. Then the flip flop might be done with a real state variable. So Perl 5's if (1..10) {...} could look something like this: if flipflop(state $x, { p5dot() == 1 }, { p5dot() == 10 }) {...} Pity it clobbers the current lexical scope with the name $x. Now we see that it'd be cool to have an anonymous state variable somehow: if flipflop(state, { p5dot() == 1 }, { p5dot() == 10 }) {...} That would let us have a state variable that is attached to our scope but that is nevertheless only named within the flipflop function. Of course, if flipflop were a macro, that could easily be reduced to if flipflop(p5dot() == 1, p5dot() == 10) {...} or even, if you get fancy with the macro: if flipflop 1, 10 {...} But then we lose the flexibility of writing any of: if flipflop(state, { p5dot() == 1 }, { p5dot() == 10 }) {...} if flipflop(my, { p5dot() == 1 }, { p5dot() == 10 }) {...} if flipflop(our, { p5dot() == 1 }, { p5dot() == 10 }) {...} to control when the state gets reset, or who can reset it. So I'd guess there's a &*flipflop builtin function, and we let people define a macro if they want it sugary, or sugarier, or sugarierier. Or if people carp too much, we go ahead and give them a macro too. Call it p5dotdot or some such. : What comes in place of ...? (An adverb?) Presumably a named arg of some sort, maybe if flipflop(state, { p5dot() == 1 }, { p5dot() == 10 }, :after) {...} or some such. Now I'm trying to figure out the uses of a closure that ends with: return \state; That would allow a caller to change my state without me keeping track of it at all. Works sort of a like a (void*) that's reserved for the user. On the other hand, if it's returning a bare state it's not gonna be very good at returning anything else useful. But maybe return $value, \state; has something useful in it. Larry