# No difference between .. and ... flip/flop operators?

**URL:** <https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938>\
**Category:** ruby-talk\
**Created:** [31 January 2004 08:09 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938 "2004-01-31T08:09:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [31 January 2004 08:09 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/1 "2004-01-31T08:09:49Z")

</div>

I thought … meant inclusive and … meant ‘not including matching lines’.

Why do these snippets both do exactly the same thing:

irb(main):032:0\> File.open(‘filename’) {|f|  
irb(main):033:1\* f.each\_line{|l|  
irb(main):034:2\* puts l if l=~/BEGIN/ … l=~/END/  
irb(main):035:2\> }  
irb(main):036:1\> }

Output:  
10 BEGIN PATTERN  
eleven  
12  
thirteen  
14 END PATTERN

irb(main):026:0\> File.open(‘filename’) {|f|  
irb(main):027:1\* f.each\_line{|l|  
irb(main):028:2\* puts l if l=~/BEGIN/ … l=~/END/  
irb(main):029:2\> }  
irb(main):030:1\> }

Output:  
10 BEGIN PATTERN  
eleven  
12  
thirteen  
14 END PATTERN

Both … and … produced the same output. I would have expected the  
output of the second snippet to be:

eleven  
12  
thirteen

???

Phil

---

<div class="post-metadata">

**Author:** ![Dan\_Doel](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@Dan\_Doel](https://rubytalk.org/u/Dan_Doel)\
**Post date:** [31 January 2004 08:30 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/2 "2004-01-31T08:30:59Z")

</div>

When constructing ranges of values (such as Fixnums), … excludes the  
end, while … includes it.

So:

(1…10).each { |i| puts i }

prints 1 - 10, while:

(1…10).each { |i| puts i }

prints 1 - 9.

As far as I know, … and … are identical in flip-flops (which I  
thought was in the Pickaxe, but I  
can’t find it right now, so maybe I just read it here a while ago).

However, regarding this and your last mail, I believe Matz is  
considering taking out flip-flops  
in the future (in Rite, maybe?), so you may want to look into other ways  
of doing stuff (if you’re  
worried about it running in 2.0 and beyond, that is).

- Dan

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [31 January 2004 14:38 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/3 "2004-01-31T14:38:05Z")

</div>

Dan Doel wrote:

> However, regarding this and your last mail, I believe Matz is  
> considering taking out flip-flops

Which is a darn shame.

---

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [31 January 2004 19:39 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/4 "2004-01-31T19:39:53Z")

</div>

> When constructing ranges of values (such as Fixnums), … excludes the  
> end, while … includes it.
> 
> So:
> 
> (1…10).each { |i| puts i }
> 
> prints 1 - 10, while:
> 
> (1…10).each { |i| puts i }
> 
> prints 1 - 9.
> 
> As far as I know, … and … are identical in flip-flops (which I  
> thought was in the Pickaxe, but I  
> can’t find it right now, so maybe I just read it here a while ago).

identical as in there is no difference in behavior between them?

> However, regarding this and your last mail, I believe Matz is  
> considering taking out flip-flops  
> in the future (in Rite, maybe?), so you may want to look into other ways  
> of doing stuff (if you’re  
> worried about it running in 2.0 and beyond, that is).

taking out flip-flops?! But they seem so useful in certain situations.  
Why get rid of them? (Matz?)

Phil

> **···**
>
> In article [401B6792.10204@po.cwru.edu](mailto:401B6792.10204@po.cwru.edu), Dan Doel [djd15@po.cwru.edu](mailto:djd15@po.cwru.edu) wrote:

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Talbott1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Nathaniel\_Talbott1](https://rubytalk.org/u/Nathaniel_Talbott1)\
**Post date:** [31 January 2004 15:43 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/5 "2004-01-31T15:43:58Z")

</div>

previous.sub(/a darn shame/, ‘wonderful’)

This rubyist will be much happier when the flip-flop is _buried_.

Nathaniel

\<:((\>\<

> **···**
>
> On Jan 31, 2004, at 09:38, Michael campbell wrote:
> 
> > Dan Doel wrote:
> > 
> > > However, regarding this and your last mail, I believe Matz is  
> > > considering taking out flip-flops
> > 
> > Which is a darn shame.

---

<div class="post-metadata">

**Author:** ![Dan\_Doel](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@Dan\_Doel](https://rubytalk.org/u/Dan_Doel)\
**Post date:** [31 January 2004 21:51 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/6 "2004-01-31T21:51:54Z")

</div>

Phil Tomson wrote:

> identical as in there is no difference in behavior between them?

Yes, that’s what I meant.

As for all the stuff about what to replace it with and such (not just  
the parent post, but many others)…

Some of the examples given can be done almost as easily without flip  
flops, as long as you don’t insist on doing things within a loop.  
I realize this isn’t the general case, but sometimes they turn out  
that way, for instance:

> The Perl code that needs to be duplicated in Ruby is:  
> while (\<\>) {  
> $in\_header = 1 … /^$/;  
> $in\_body = /^$/ … eof();  
> }

This can be done by something like this (borrowing from your modified code):

File.open(“filename”) do |f|  
str = f.readlines  
m = /\n\n/.match str  
in\_header = m.pre\_match  
in\_body = m.post\_match  
end

This is as short as your flip flop code, and in fact, I can eliminate 1  
line.

I also cooked up a little magic in an attempt to reproduce flip flops on my  
own. It, of course, doesn’t work as well as real flip flops. Here’s my code:

module Kernel  
def between(a, b, &blk)  
within = false  
proc do |l|  
within = true if a === l  
blk.call l if within  
within = false if b === l  
end  
end  
end

With this, the following two pieces of code produce identical output:

lines.each { |l|  
puts l if l=~/BEGIN/ … l=~/END/  
}

lines.each &between(/BEGIN/, /END/ { |l|  
puts l  
}

Further, you can technically chain together #between calls to make  
nested flipflops, but it looks very ugly. It’s not as general as  
flip flops, nested or otherwise, either, so I’ll let this stew for  
a while and see if I can come up with any hideous code that makes  
homebrew flip flops look nice.

As for the devil’s advocate talking about Unix idioms as methods,  
I’d point out that I can define my own #grep and use it, so you’d  
have to look it up anyway. I cannot define my own Ruby syntax based  
on other languages. Just a little devil’s advocate back at you. 🙂

I, for one, don’t have a strong opinion about whether flip flops  
should be in the language. From the perl code posted, it looks like  
that’s where it’s taken from. Matz is also considering taking out  
some other perlisms, I believe (like certain $ variables), so  
maybe this is something else he took from perl that he wishes he  
didn’t. However, I’d note that taking this out isn’t a catastrophe.  
Most languages don’t have such an idiom, and they do fine. And,  
maybe we can even figure out something to replace it that isn’t  
too bad from either side’s perspective, given that Ruby is quite  
able to be modified by itself for things like this.

Sorry for the long post.

- Dan

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [31 January 2004 15:58 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/7 "2004-01-31T15:58:00Z")

</div>

Nathaniel Talbott wrote:

> **···**
>
> > On Jan 31, 2004, at 09:38, Michael campbell wrote:
> > 
> > > Dan Doel wrote:
> > > 
> > > > However, regarding this and your last mail, I believe Matz is  
> > > > considering taking out flip-flops
> > > 
> > > Which is a darn shame.
> > 
> > previous.sub(/a darn shame/, ‘wonderful’)
> > 
> > This rubyist will be much happier when the flip-flop is _buried_.
> 
> Why? If you didn’t like it, why would you use it?

---

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [31 January 2004 19:39 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/8 "2004-01-31T19:39:52Z")

</div>

In article [45F0D15E-5404-11D8-83F8-000A95CD7A8E@talbott.ws](mailto:45F0D15E-5404-11D8-83F8-000A95CD7A8E@talbott.ws),

> **···**
>
> Nathaniel Talbott [nathaniel@talbott.ws](mailto:nathaniel@talbott.ws) wrote:
> 
> > On Jan 31, 2004, at 09:38, Michael campbell wrote:
> > 
> > > Dan Doel wrote:
> > > 
> > > > However, regarding this and your last mail, I believe Matz is  
> > > > considering taking out flip-flops
> > > 
> > > Which is a darn shame.
> > 
> > previous.sub(/a darn shame/, ‘wonderful’)
> > 
> > This rubyist will be much happier when the flip-flop is _buried_.
> 
> Why? Care to elaborate? If you don’t like them, you don’t have to use  
> them, right? But if you do like the feature it saves a good bit of  
> coding.
> 
> Phil

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [31 January 2004 22:01 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/9 "2004-01-31T22:01:28Z")

</div>

Dan Doel wrote:

> I, for one, don’t have a strong opinion about whether flip flops  
> should be in the language. From the perl code posted, it looks like  
> that’s where it’s taken from. Matz is also considering taking out  
> some other perlisms, I believe (like certain $ variables), so  
> maybe this is something else he took from perl that he wishes he  
> didn’t.

I can’t speak for Matz, but my impression is that the perlisms  
belonged in there, but are now wearing thin. Ruby is approxmiately  
ten years old, and there are many things that are acceptable for  
five-year-olds but not ten-year-olds. 🙂

As for the swearing variables, I have never liked the idea of  
changing the behavior of a piece of code or a library function by  
altering the value of a global. After all, why are global variables  
usually considered bad?

As for the flipflop issue, I favor a solution that makes sense in  
terms of normal Ruby syntax and semantics.

Given that only false and nil are false, and a range is never nil,  
why should

```
 if x..y
    puts "yes"
 else
    puts "no"
 end

```

ever print “no”?

Just my opinion.

Hal

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Talbott1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Nathaniel\_Talbott1](https://rubytalk.org/u/Nathaniel_Talbott1)\
**Post date:** [31 January 2004 22:09 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/10 "2004-01-31T22:09:51Z")

</div>

Actually there is a difference… see:

[http://sean.chittenden.org/programming/ruby/programming\_ruby/](http://sean.chittenden.org/programming/ruby/programming_ruby/)  
language.html

Search for “Ranges in Boolean Expressions” (this was missing from the  
online pickaxe at [rubycentral.com](http://rubycentral.com) - not sure why).

If someone can explain the difference in a meaningful way, I’d be  
grateful… I have enough trouble with the flip-flop as it is, and now  
this!

Nathaniel

\<:((\>\<

> **···**
>
> On Jan 31, 2004, at 16:51, Dan Doel wrote:
> 
> > Phil Tomson wrote:
> > 
> > > identical as in there is no difference in behavior between them?
> > 
> > Yes, that’s what I meant.

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Talbott1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Nathaniel\_Talbott1](https://rubytalk.org/u/Nathaniel_Talbott1)\
**Post date:** [31 January 2004 17:07 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/11 "2004-01-31T17:07:03Z")

</div>

An interesting question; I’ll try to give a coherent answer. First of  
all, I have to read other people’s code, and if they use obscure,  
hard-to-understand constructs that I have to look up every time, it  
makes it much harder to grok what’s going on. Since I learn most  
libraries by reading their code (and I often do that even when they  
have top-notch docs - I’m just that kind of guy), opaque language  
constructs are particularly biting.

Secondly, and really more importantly, is the issue of aesthetics.  
Every bit of syntax, whether I use it or not, affects and reflects the  
language as a whole. One of the things I like about Ruby the language  
is that the syntax tends to explain itself. I don’t use or even see for  
loops very much in Ruby code, but when I run across one, it’s pretty  
obvious what’s going on. The flip-flop gives me no external clues as to  
its modus operandi, and I don’t like the way affects Ruby, by making a  
bit of the gem opaque, and how it reflects Ruby, when someone sees it  
and goes, “WHAT IN TARNATION IS THAT THING?!?” and I have to explain  
that Ruby unfortunately gained a few of the “P” language’s bad points  
along with a lot of its good points.

That’s why I personally would like to see it gone, and good riddance.  
You, of course, are welcome to root for a pardon, but I just wanted to  
make sure the other side of the aisle was represented 🙂

Just my $0.02,

Nathaniel

\<:((\>\<

> **···**
>
> On Jan 31, 2004, at 10:58, Michael campbell wrote:
> 
> > Nathaniel Talbott wrote:
> > 
> > > This rubyist will be much happier when the flip-flop is _buried_.
> > 
> > Why? If you didn’t like it, why would you use it?

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [31 January 2004 22:23 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/12 "2004-01-31T22:23:22Z")

</div>

> [http://sean.chittenden.org/programming/ruby/programming\_ruby/](http://sean.chittenden.org/programming/ruby/programming_ruby/)  
> language.html
> 
> Search for “Ranges in Boolean Expressions” (this was missing from the  
> online pickaxe at [rubycentral.com](http://rubycentral.com) - not sure why).
> 
> If someone can explain the difference in a meaningful way, I’d be  
> grateful… I have enough trouble with the flip-flop as it is, and now  
> this!

The 2 dot form evaluates the end condition at the same time as the beginning one, so will flip to “on” then “off” if both are true. The 3 dot form does not.

---

<div class="post-metadata">

**Author:** ![Dan\_Doel](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@Dan\_Doel](https://rubytalk.org/u/Dan_Doel)\
**Post date:** [31 January 2004 22:35 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/13 "2004-01-31T22:35:36Z")

</div>

Ah, I see.

Well, I can explain it.

When you use “expr1…expr2”, if expr1 and expr2 are both true for some  
element,  
then the expression evaluates to true for just that element. That is, it  
gets turned  
on, evaluates the code, and then turns it off. In other words, it’s  
doing this in the  
internal state:

within\_range = false  
collection.each do |l|  
within\_range = true if expr1  
#do stuff  
within\_range = false if expr2  
end

When you use 3 dots, it seems you can either turn it on or turn it off,  
but not  
both on an iteration (although it only talks about turning it on). So  
it’s doing  
something more like this:

within\_range = false

collection.each do |l|  
if within\_range || expr1  
#do stuff  
end

```
if !within_range
   within_range = true if expr1
else
   within_range = false if expr2
end

```

end

Or something like that. I may not have gotten the semantics quite right.

I must say, this seems completely unrelated to … and … in the context of  
ranges.

- Dan

---

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [31 January 2004 23:54 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/14 "2004-01-31T23:54:52Z")

</div>

In article [2F46EE5C-543A-11D8-99FF-000A95CD7A8E@talbott.ws](mailto:2F46EE5C-543A-11D8-99FF-000A95CD7A8E@talbott.ws),

> > Phil Tomson wrote:
> > 
> > > identical as in there is no difference in behavior between them?
> > 
> > Yes, that’s what I meant.
> 
> Actually there is a difference… see:
> 
> [http://sean.chittenden.org/programming/ruby/programming\_ruby/](http://sean.chittenden.org/programming/ruby/programming_ruby/)  
> language.html
> 
> Search for “Ranges in Boolean Expressions” (this was missing from the  
> online pickaxe at [rubycentral.com](http://rubycentral.com) - not sure why).
> 
> If someone can explain the difference in a meaningful way, I’d be  
> grateful… I have enough trouble with the flip-flop as it is, and now  
> this!
> 
> Nathaniel

Thanks for the reference. I thought I’d seen that state diagram  
somewhere. It wasn’t in the online version I was checking.

The best way to illustrate the difference is to use an example. Given the  
file ‘file’:

nine  
10 BEGIN skdadk END  
eleven  
12  
thirteen  
14 END PATTERN  
fifteen  
---------END OF FILE-------------

And given the script:

File.foreach(“filename”){|l|  
if l=~/BEGIN/ … l=~/END/  
puts l  
end  
}

The output will be:

10 BEGIN skdadk END

changing the … to … , the output will be:

10 BEGIN skdadk END  
eleven  
12  
thirteen  
14 END PATTERN

I think this is different behavior from Perl’s version of the …  
flip/flop, but I’ld have to check.

Phil

> **···**
>
> Nathaniel Talbott [nathaniel@talbott.ws](mailto:nathaniel@talbott.ws) wrote:
> 
> > On Jan 31, 2004, at 16:51, Dan Doel wrote:

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [31 January 2004 17:37 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/15 "2004-01-31T17:37:18Z")

</div>

Nathaniel Talbott wrote:

> An interesting question; I’ll try to give a coherent answer. First of  
> all, I have to read other people’s code, and if they use obscure,  
> hard-to-understand constructs

I don’t find it either of those.

> that I have to look up every time

nor do I have to do that.

> , it  
> makes it much harder to grok what’s going on.

I understand and respect your point here, but is it not a nicer way of saying “I find hard to grok, so it should be restricted from _everyone’s_ use”?

---

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [31 January 2004 19:54 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/16 "2004-01-31T19:54:52Z")

</div>

In article [E15487A8-540F-11D8-83F8-000A95CD7A8E@talbott.ws](mailto:E15487A8-540F-11D8-83F8-000A95CD7A8E@talbott.ws),

> > Nathaniel Talbott wrote:
> > 
> > > This rubyist will be much happier when the flip-flop is _buried_.
> > 
> > Why? If you didn’t like it, why would you use it?
> 
> An interesting question; I’ll try to give a coherent answer. First of  
> all, I have to read other people’s code, and if they use obscure,  
> hard-to-understand constructs that I have to look up every time, it  
> makes it much harder to grok what’s going on. Since I learn most  
> libraries by reading their code (and I often do that even when they  
> have top-notch docs - I’m just that kind of guy), opaque language  
> constructs are particularly biting.
> 
> Secondly, and really more importantly, is the issue of aesthetics.  
> Every bit of syntax, whether I use it or not, affects and reflects the  
> language as a whole. One of the things I like about Ruby the language  
> is that the syntax tends to explain itself. I don’t use or even see for  
> loops very much in Ruby code, but when I run across one, it’s pretty  
> obvious what’s going on. The flip-flop gives me no external clues as to  
> its modus operandi, and I don’t like the way affects Ruby, by making a  
> bit of the gem opaque, and how it reflects Ruby, when someone sees it  
> and goes, “WHAT IN TARNATION IS THAT THING?!?” and I have to explain  
> that Ruby unfortunately gained a few of the “P” language’s bad points  
> along with a lot of its good points.
> 
> That’s why I personally would like to see it gone, and good riddance.  
> You, of course, are welcome to root for a pardon, but I just wanted to  
> make sure the other side of the aisle was represented 🙂

And just what would you replace that functionality with? It seems to me  
that it would take several lines of code to replace the following  
functionality:

f.each\_line {|l|  
if l=~/BEGIN/ … l=~/END/  
#do something in this range of lines  
end  
}

If you know the meaning of what ‘…’ is doing here, it seems quite clear.  
It’s also clear to anyone coming from Perl to Ruby as to what is  
going on here. Without the flip/flop op that code code has to become  
something like:

#untested  
begin\_state = false  
f.each\_line {|l|  
if l=~/BEGIN/  
begin\_state = true  
elsif l=~/END/  
begin\_state = false  
end  
if begin\_state == true  
#do something in this range of lines  
end  
}

I’ve got to introduce a state variable and more conditionals and my one  
line has grown into 5. Add another flip/flop operator to your parsing  
code and you add another state variable and a bunch more lines. It’s not  
uncommon to use several of these when parsing.

Save the flip/flop!

Phil

> **···**
>
> Nathaniel Talbott [nathaniel@talbott.ws](mailto:nathaniel@talbott.ws) wrote:
> 
> > On Jan 31, 2004, at 10:58, Michael campbell wrote:

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Talbott1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Nathaniel\_Talbott1](https://rubytalk.org/u/Nathaniel_Talbott1)\
**Post date:** [31 January 2004 18:29 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/17 "2004-01-31T18:29:53Z")

</div>

> Nathaniel Talbott wrote:
> 
> > An interesting question; I’ll try to give a coherent answer. First of  
> > all, I have to read other people’s code, and if they use obscure,  
> > hard-to-understand constructs
> 
> I don’t find it either of those.
> 
> > that I have to look up every time
> 
> nor do I have to do that.

Point taken. But then, I know from talking to others that my opinion on  
it’s clarity and my need to look it up are not isolated occurrences.

> > , it makes it much harder to grok what’s going on.
> 
> I understand and respect your point here, but is it not a nicer way of  
> saying “I find hard to grok, so it should be restricted from  
> _everyone’s_ use”?

Well, I’d phrase it more as, “It’s hard for a lot of people to grok, so  
we should find a better construct for it.” I don’t think the  
functionality should go away, but I think it should be implemented as a  
library function, not a piece of the syntax. Or, if it is syntax, that  
that syntax should be more inherently self-apparent.

I’d also add the sentence, “I find it dog-ugly, so I will do everything  
within my power to see that it DIES!” It’s this that really drives  
me… the aesthetics of the construct just make me want to wretch. It’s  
an amalgamation of several different pieces of the language that just  
don’t make sense together. Oh, and it has internal state that those  
various pieces don’t. It just doesn’t seem to fit in. Now if I was the  
only one who had this opinion, then it should certainly stay… but  
apparently matz agrees with me at some level. I’m bummed that some  
people will miss it, but that’s the fun of language design - you get to  
“Tick off all of the people, some of the time.” I’m glad he’s the  
designer and not me 🙂

Nathaniel

\<:((\>\<

> **···**
>
> On Jan 31, 2004, at 12:37, Michael campbell wrote:

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [31 January 2004 20:04 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/18 "2004-01-31T20:04:27Z")

</div>

Phil Tomson wrote:

> > That’s why I personally would like to see it gone, and good riddance.  
> > You, of course, are welcome to root for a pardon, but I just wanted to  
> > make sure the other side of the aisle was represented 🙂
> 
> And just what would you replace that functionality with?

Phil,

I’m with Nathaniel. Save the functionality but please KILL the  
syntax. Only a perler could love it. (No offense meant.)

I haven’t thought this through yet. But let’s do it with a  
method call.

#untested  
f.set\_context(/BEGIN/,/END/)  
f.each\_line do |l|  
if f.in\_context  
# do something with l…  
else  
# whatever  
end  
end

Comments, Phil? Nathaniel? Others?

Hal

---

<div class="post-metadata">

**Author:** ![Avi\_Bryant1](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Avi\_Bryant1](https://rubytalk.org/u/Avi_Bryant1)\
**Post date:** [1 February 2004 00:09 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/19 "2004-02-01T00:09:53Z")

</div>

[ptkwt@aracnet.com](mailto:ptkwt@aracnet.com) (Phil Tomson) wrote in message news:[bvgv9u2mb1@enews1.newsguy.com](mailto:bvgv9u2mb1@enews1.newsguy.com)…

> And just what would you replace that functionality with? It seems to me  
> that it would take several lines of code to replace the following  
> functionality:
> 
> f.each\_line {|l|  
> if l=~/BEGIN/ … l=~/END/  
> #do something in this range of lines  
> end  
> }

What an odd operator! It took me a bit of toying around to figure out  
exactly what it does (I didn’t know what the scope of its state  
variable was, but evidently it’s the enclosing method).

Anyway, it seems to me you could pretty easily replace this with a  
simple flipflop class:

ff = FlipFlop.new  
f.each\_line {|l|  
ff.from(l=~/BEGIN/, l=~/END/) do  
#do something in this range of lines  
end  
}

class FlipFlop  
def initialize  
@in\_range = false  
end

def from(start\_cond, end\_cond)  
@in\_range = true if start\_cond  
yield  
@in\_range = false if end\_cond  
end  
end

Seems a lot clearer than a special operator. But maybe that’s just my  
Smalltalker’s minimalism coming out…

Avi

---

<div class="post-metadata">

**Author:** ![Avi\_Bryant1](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Avi\_Bryant1](https://rubytalk.org/u/Avi_Bryant1)\
**Post date:** [1 February 2004 00:14 UTC](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938/20 "2004-02-01T00:14:52Z")

</div>

I wrote:

def from(start\_cond, end\_cond)  
@in\_range = true if start\_cond  
yield  
@in\_range = false if end\_cond  
end

Ack. That should be “yield if @in\_range”, of course.

[Next page](https://rubytalk.org/t/no-difference-between-and-flip-flop-operators/9938.md?page=2)
