Phil Tomson wrote: > Jamis Buck <jgb3 / email.byu.edu> wrote in message news:<401F1E82.1080008 / email.byu.edu>... > >>ts wrote: >> >> >>>>>>>>"P" == Phil Tomson <ptkwt / aracnet.com> writes: >>>>>>>> >>>>>>>> >>> >>>P> Yes, I figured that it was being interpreted that way, but my question is >>>P> why? >>> >>>ruby use `..' for the range operator and the flip-flop operator. >>> >>> >> >>Reading the posts in this discussion has been very enlightening for me. >>I finally understand the flip-flop operator, for one thing. And I think >>I understand the root of the "dislike" some people have for the >>flip-flop: it uses the same syntax as a completely unrelated (and >>possibly more common) concept, which can make the intuitive leap a bit hard. >> >>I can certainly see the value in the flip-flop, and where I was >>originally on the "team" that was rooting for its removal, I now would >>like to see it remain, but in different form. What if it used a >>different syntax, but the same semantics? This would allow the >>flip-flop to be used outside of conditionals, too, since there would be >>no ambiguity involved. >> >>So, instead of '..' and '...', how about something completely new, like >>perhaps '--', or '~~'? Or even a new keyword, like 'flip' or >>'flipflop'? It would be nice to also somehow provide a way to access >>some underlying objectified represention of the flip-flop, so that its >>state could be queried and manipulated, > > > -- would look too much like decrement (from the perspective of other > languages) so that could also be confusing. ~~ might be better. > > 'flipflop' is the object, not the action and in this case it seems > like you're basically trying to say: > > "do something from the time condition A becomes true until the time > condition B becomes true". Perhaps, as you say, a new keyword is in > order. But what if we could make use of an existing keyword; I'm > thinking that 'until' might work. It would look something like: > > if l=~/BEGIN/ until l=~/END/ do > #do something in this range > end > > Actually, I don't think 'until' is really a keyword (correct me if I'm > wrong), but that it's actually a buit-in method that takes a block, so > it might be difficult to coerce it into this proposed usage. It's a kewyword: irb(main):001:0> until(1) {} irb(main):002:1> end SyntaxError: compile error (irb):1: parse error until(1) {} ^ from (irb):2 > Another idea would be to have a 'from (condition) to (condition)' > statement that looks looks like: > from l=~/BEGIN/ to l=~/END/ do > #do something in this range > end > > Then we just need some way to determine if the range is inclusive or > exclusive... > from l=~/BEGIN/ to l=~/END/ inclusive do > puts l > end > > #prints: > BEGIN > foo > bar > END > > from l=~/BEGIN/ to l=~/END/ exclusive do > puts l > end Very readable! It may be an improvement that the flipflop isn't being used with if, but with a special keyword. The hidden state bothers me less that way. Of course you lose the possibility of a condition with more complex logic.