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.
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
#prints:
foo
bar
....but maybe there's a better way to do that. Also, how do you get
the same kind of behavioral differences that we see with the current
... and ... flip flop operators?
It seems like the 'from (condition) to (condition)' statement could
also return the underlying flip/flop object, kind of like [] returns
an Array or {} returns a Hash. So there could still be a FlipFlop
class, but this would just be a shortcut that keeps you from having to
instantiate a FlipFlop object explicitly prior to use.
ff = from l=~/BEGIN/ to l=~/END/ { ... }
OR:
from l=~/BEGIN/ to l=~/END/ {|ff| ... }
then you could call methods on the ff object, like:
ff.status? (true or false)
ff.class #=> FlipFlop
I'm just sort of brainstorming here, but I think the 'from .. to ..
{}' statement is very readable and the intent is quite clear and it
just might be able to replace the current flipflop operators.
Phil