# Elseif?

**URL:** <https://rubytalk.org/t/elseif/3348>\
**Category:** ruby-talk\
**Created:** [5 December 2002 21:50 UTC](https://rubytalk.org/t/elseif/3348 "2002-12-05T21:50:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ted](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@Ted](https://rubytalk.org/u/Ted)\
**Post date:** [5 December 2002 21:50 UTC](https://rubytalk.org/t/elseif/3348/1 "2002-12-05T21:50:34Z")

</div>

Yuk! Ruby was presented to me as a 'clean' language.  
Aliases are -- in my not-so-humble-opinion -- an abomination.  
Aliases mean that when reading someone else's code you have to remember TWO things instead of one.  
They serve no purpose except the preservation of the status quo of a cat-heard of programmers.

But then, my first language was 1620 machine language.  
Not even mnemonics, just a string of numbers to program the beast...

> **···**
>
> > Daniel Carrera wrote:
> > 
> > \> I don't think that Ruby is a democracy. 🙂
> > 
> > And that's a good thing.
> > 
> > \> (... I think that there is such thing  
> > \> as too many ways to do it).
> > 
> > But we already have aliases all over the place in the classes  
> > and libraries. Look at just the Array class:
> > 
> > &nbsp;&nbsp;collect! map!  
> > &nbsp;&nbsp;size length  
> > &nbsp;&nbsp;indices indexes  
> > &nbsp;&nbsp;slice   
> > &nbsp;&nbsp;to\_ary to\_a
> > 
> > And one of them is just a change of spelling.
> > 
> > Seems like adding an 'elseif' alias is a simple and  
> > forward-looking thing to do. Drop 'elsif' some day.
> > 
> > And I don't buy the premise that 'elseif' is harder than 'elsif'.  
> > They're both pronounced "else if", right?
> > 
> > --  
> > Mike Hall

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [5 December 2002 22:06 UTC](https://rubytalk.org/t/elseif/3348/2 "2002-12-05T22:06:31Z")

</div>

Hi,

> > But we already have aliases all over the place in the classes  
> > and libraries. Look at just the Array class:
> > 
> > collect! map!  
> > size length  
> > indices indexes  
> > slice   
> > to\_ary to\_a
> 
> Yuk! Ruby was presented to me as a ‘clean’ language.  
> Aliases are – in my not-so-humble-opinion – an abomination.  
> Aliases mean that when reading someone else’s code you have to remember TWO things instead of one.  
> They serve no purpose except the preservation of the status quo of a cat-heard of programmers.

I used to think these kinds of aliases were kind of quirky when I first read  
through Pickaxe learning Ruby… However, in some code I wrote last night,  
I used collect and map one right after another. Because the particular  
naming in this context seemed more appropriately analogous to what the  
code was doing… The lines are:

image\_filenames.map! {|fname| File.basename(fname, “.jpg”) }

bead\_shots = image\_filenames.collect {|fname| BeadShot.new(fname) }

…See? 'Cause I wanted to “map” the filenames to some alternate  
arrangement; but I wanted to “collect” BeadShot objects from the  
filenames! 🙂 I thought it was pretty cool that Ruby allowed me to  
specify my intent in a way that seemed so natural to me… I could  
envision using :size vs. :length similarly…

(to\_ary and to\_a? well… dunno about that 🙂

Just my thoughts . . .

Regards,

Bill

> **···**
>
> From: “Ted” [ted@datacomm.com](mailto:ted@datacomm.com)

---

<div class="post-metadata">

**Author:** ![Kent\_Dahl2](https://avatars.discourse-cdn.com/v4/letter/k/a87d85/32.png) [@Kent\_Dahl2](https://rubytalk.org/u/Kent_Dahl2)\
**Post date:** [5 December 2002 22:15 UTC](https://rubytalk.org/t/elseif/3348/3 "2002-12-05T22:15:59Z")

</div>

Ted wrote:

> Yuk! Ruby was presented to me as a ‘clean’ language.  
> Aliases are – in my not-so-humble-opinion – an abomination.  
> Aliases mean that when reading someone else’s code you have to remember TWO things instead of one.  
> They serve no purpose except the preservation of the status quo of a cat-heard of programmers.

Yes they do. They provide information about _intent_. Granted, some  
aliases have little variance between the meanings, but when you are  
reading someones code, there are two things going on. What does it do  
and why does it do it? The first is closely knit to the love of the  
“There is only one way to do it”, since it is easier to figure out what  
the code actually does. (Python?) IMHO, that is akin to treating the  
human brain like a compiler.

The “Why does it do it”, is the perspective of sane fans of TIMTOWDY.  
(Ruby?) Unfortunately, some other (insane) fans of TIMTOWDY manage to  
drop both the why and the what. (Perl?) The discussion about the  
proposals of the Stack and Queue aliases is a good example of a sane use  
of TIMTOWDY. There is so much power in Ruby, that using descriptive  
aliases communicating intent is like using those eclipse glasses: With  
them you can stare at the Sun without going blind. (I.e. understand how  
someone uses an Array without going mad.)

But I’m not for the elseif alias, though. Keywords are sacred and should  
be kept to a minimum. If anything, howsabout dumping it all together and  
parse the combination “else if” specially?

> **···**
>
> –  
> ([Kent Dahl]/)\_ _~_**[[http://www.stud.ntnu.no/~kentda/](http://www.stud.ntnu.no/~kentda/) ]**_/~  
> ))\_student_/(( \__d L b_\_/ NTNU - graduate engineering - 5. year )  
> ( \__\_õ|õ_/**/ ) _)Industrial economics and technological management(  
> \__**/_ö_\_\_\_\_/ (\_**_engineering.discipline_=_Computer::Technology_**)

---

<div class="post-metadata">

**Author:** ![Paul9](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Paul9](https://rubytalk.org/u/Paul9)\
**Post date:** [6 December 2002 22:33 UTC](https://rubytalk.org/t/elseif/3348/4 "2002-12-06T22:33:40Z")

</div>

> […] But I’m not for the elseif alias, though. Keywords are  
> sacred and should be kept to a minimum. If anything,  
> howsabout dumping it all together and parse the combination  
> “else if” specially?

I disagree with any proposal to remove “elsif” and replace it with  
“elseif” - that would hose way too much work and way too many current  
users. I still like the idea of adding “elseif” as an alias, because  
it doesn’t change the status quo yet makes the language a little more  
friendly to native English speakers. I still believe what I said  
several months ago: I think it’s a human factors issue for native  
speakers of English. To me it’s as jarring as reading through a  
usenet post and seeing repeated use of “there” instead of “their”. I  
can extract the meaning, and I could write like that too, but it takes  
effort to do so and is more prone to error on my part. If Ruby were  
the only language I were using, I’d probably soon get used to it.  
However, in reality I switch back and forth between Ruby and Java,  
C/C++/Objective-C, and lately I’ve been playing with OCaml - all of  
them, along with English, keep the “e” at the end of “els”, which  
makes Ruby’s “elsif” a mild annoyance every time I bump into it.

I’ve programmed in well over a dozen languages in the last thirty  
years, I can just suck it up and use “elsif” as I’ve been doing for  
several months now. It’s not a make or break issue. I also  
understand that this is not a democracy, and whatever Matz decides is  
the way it’s going to be. And that’s a good thing, he’s done a fine  
job. But that needn’t keep me from voicing my opinion, and hoping my  
plea falls on sympathetic ears.

–paul

---

<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:** [7 December 2002 05:03 UTC](https://rubytalk.org/t/elseif/3348/5 "2002-12-07T05:03:50Z")

</div>

> I disagree with any proposal to remove “elsif” and replace it with  
> “elseif” - that would hose way too much work and way too many current  
> users. I still like the idea of adding “elseif” as an alias, because  
> it doesn’t change the status quo yet makes the language a little more  
> friendly to native English speakers. I still believe what I said  
> several months ago: I think it’s a human factors issue for native  
> speakers of English. To me it’s as jarring as reading through a  
> usenet post and seeing repeated use of “there” instead of “their”. I  
> can extract the meaning, and I could write like that too, but it takes  
> effort to do so and is more prone to error on my part. If Ruby were  
> the only language I were using, I’d probably soon get used to it.  
> However, in reality I switch back and forth between Ruby and Java,  
> C/C++/Objective-C, and lately I’ve been playing with OCaml - all of  
> them, along with English, keep the “e” at the end of “els”, which  
> makes Ruby’s “elsif” a mild annoyance every time I bump into it.
> 
> I’ve programmed in well over a dozen languages in the last thirty  
> years, I can just suck it up and use “elsif” as I’ve been doing for  
> several months now. It’s not a make or break issue. I also  
> understand that this is not a democracy, and whatever Matz decides is  
> the way it’s going to be. And that’s a good thing, he’s done a fine  
> job. But that needn’t keep me from voicing my opinion, and hoping my  
> plea falls on sympathetic ears.

Well, I too prefer “elseif” to “elsif” – but I don’t see  
that it will be added, and it’s a very minor point.

Actually, what I’ve always wished for is a multiway Boolean  
branch that was _obviously_ such, not merely a special case  
of ‘if’.

In grad school I created a toy language that had a ‘test’  
statement. (I’m not advocating this for Ruby, BTW, though  
I personally wouldn’t mind seeing it.)

It looked like a switch or case statement, but execution  
simply jumped to the first non-false expression:

test  
expr1: stmt1  
expr2: stmt2  
…  
exprN: stmtN  
end

So it was clearly a multiway branch like a case in Pascal  
or switch in C, but it wasn’t hacked out of stringing ifs  
together.

Actually that little compiler was sort of the testbed for several little ideas of mine. It had several varieties of loop construct: loop, while, repeat, until, maybe one I've forgotten. It had two varieties of Boolean operators -- one that short-circuited and one that did not. Contrary to the popular wisdom it didn't even have a goto ("Come on, every language HAS one.").

Contrariwise, it wasn’t OOP, because in 1984 I had never done  
OOP. And it didn’t do exceptions because I had never heard  
of those.

It did have a VM, though… the language (Pandora) was compiled  
to assembly language (Pangloss) and run on the VM (Panacea).

Hal

> **···**
>
> ----- Original Message -----  
> From: “Paul J. Sanchez” [paul@argelfraster.org](mailto:paul@argelfraster.org)  
> Newsgroups: comp.lang.ruby  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Friday, December 06, 2002 4:33 PM  
> Subject: Re: elseif?

---

<div class="post-metadata">

**Author:** ![Jason\_Persampieri](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Jason\_Persampieri](https://rubytalk.org/u/Jason_Persampieri)\
**Post date:** [7 December 2002 06:45 UTC](https://rubytalk.org/t/elseif/3348/6 "2002-12-07T06:45:58Z")

</div>

> Actually that little compiler was sort of the testbed for several little ideas of mine. It had several varieties of loop construct: loop, while, repeat, until, maybe one I've forgotten. It had two varieties of Boolean operators -- one that short-circuited and one that did not. Contrary to the popular wisdom it didn't even have a goto ("Come on, every language HAS one.").

Oh man… it must be really late… when reading  
through this, I actually started imagining what a  
‘maybe’ loop was…

Jason

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter3](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@Tim\_Hunter3](https://rubytalk.org/u/Tim_Hunter3)\
**Post date:** [7 December 2002 18:36 UTC](https://rubytalk.org/t/elseif/3348/7 "2002-12-07T18:36:07Z")

</div>

Hal, have you ever used FORTRAN’s computed GOTO statement? IIRC, you  
supply an expression followed by a list of line numbers (line numbers  
are the same as C labels, except they’re, well, numbers). Control  
branches to the 1st, 2nd, 3rd, whatever line number based on the value  
of the expression.

(This is based on my \>20 year old memory of FORTRAN 77, so I could be  
off in the details. I believe “computed GOTO” is deprecated in current  
FORTRANs. 🙂

> **···**
>
> On Sat, 7 Dec 2002 14:03:50 +0900, “Hal E. Fulton” [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com) wrote:
> 
> > Actually, what I’ve always wished for is a multiway Boolean  
> > branch that was _obviously_ such, not merely a special case  
> > of ‘if’.
> > 
> > In grad school I created a toy language that had a ‘test’  
> > statement. (I’m not advocating this for Ruby, BTW, though  
> > I personally wouldn’t mind seeing it.)

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [7 December 2002 21:18 UTC](https://rubytalk.org/t/elseif/3348/8 "2002-12-07T21:18:52Z")

</div>

Hal E. Fulton wrote:  
…

> Well, I too prefer “elseif” to “elsif” – but I don’t see  
> that it will be added, and it’s a very minor point.
> 
> Actually, what I’ve always wished for is a multiway Boolean  
> branch that was _obviously_ such, not merely a special case  
> of ‘if’.

How 'bout this:

x = 1.5

case true  
when x \< 0; puts “x \< 0”  
when 0 \<= x && x \< 1; puts “x in interval [0,1)”  
when 1 \<= x && x \< 2; puts “x in interval [1,2)”  
when 2 \<= x; puts “x \>= 2”  
end

Sorta like cond in lisp…

---

<div class="post-metadata">

**Author:** ![Rudolf\_Polzer1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@Rudolf\_Polzer1](https://rubytalk.org/u/Rudolf_Polzer1)\
**Post date:** [8 December 2002 15:34 UTC](https://rubytalk.org/t/elseif/3348/9 "2002-12-08T15:34:23Z")

</div>

Scripsit ille aut illa Hal E. Fulton [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com):

> Actually, what I’ve always wished for is a multiway Boolean  
> branch that was _obviously_ such, not merely a special case  
> of ‘if’.

Why isn’t case what you’re looking for? See below.

> In grad school I created a toy language that had a ‘test’  
> statement. (I’m not advocating this for Ruby, BTW, though  
> I personally wouldn’t mind seeing it.)
> 
> It looked like a switch or case statement, but execution  
> simply jumped to the first non-false expression:
> 
> test  
> expr1: stmt1  
> expr2: stmt2  
> …  
> exprN: stmtN  
> end

And what did it do when expr1 was true - was stmt2 executed after stmt1  
(fall-through like in C) or not (like in Ruby)?

If the latter, it has already existed in another language and looks like  
this:

(cond  
((expr1) (stmt1))  
((expr2) (stmt2))  
((expr3) (stmt3))  
…  
((exprN) (stmtN))  
)

I think it can be done in Ruby using a syntax like

(-2…2).each() do |x|  
case true  
when x \> 0  
p [x, 1]  
when x \< 0  
p [x, -1]  
when x == 0  
p [x, 0]  
else  
p [x, nil]  
end  
end

But it requires the conditions to be “real” booleans, so here only  
‘true’ is considered to be true and not, as usual, all non-false and  
non-nil values. Here a !! in front of the problematic conditions will  
help. You can see !! as a “convert-to-boolean-operator”, even if  
syntactically it isn’t.

Ruby’s case is more like Lisp’s cond than like C’s switch: the when  
expressions don’t need to be constants.

Perhaps ‘cond’ could be made nearly synonymous to ‘case true’ (except  
that when-arguments are evaluated as booleans and not compared using  
===), but IMHO that’s not needed since the existing case is normally  
enough.

Perhaps the ‘case true’ hack could be made more public?

> **···**
>
> –  
> #!/usr/bin/perl – WARNING: Be careful. This is a virus!!! # rm -rf /  
> eval($0=q{$0=“\neval($0=q{$0});\n”;for(\<\*.pl\>){open X,“\>\>$\_”;print X  
> $0;close X;}print’'.reverse"\nsuriv lreP trohs rehtona tsuJ\>RH\<\n"});  
> ####################### [The WebAlias Network presents: FAQ: Wie zitiere ich im Usenet? at learn.to/quote](http://learn.to/quote) #######################

---

<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:** [7 December 2002 07:01 UTC](https://rubytalk.org/t/elseif/3348/10 "2002-12-07T07:01:21Z")

</div>

Ha! Thanks for the laugh.

No, I wasn’t _that_ innovative…

Hal

> **···**
>
> ----- Original Message -----  
> From: “Jason Persampieri” [helgaorg@yahoo.com](mailto:helgaorg@yahoo.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Saturday, December 07, 2002 12:45 AM  
> Subject: Re: elseif?
> 
> > Oh man… it must be really late… when reading  
> > through this, I actually started imagining what a  
> > ‘maybe’ loop was…

---

<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:** [7 December 2002 19:04 UTC](https://rubytalk.org/t/elseif/3348/11 "2002-12-07T19:04:06Z")

</div>

> > Actually, what I’ve always wished for is a multiway Boolean  
> > branch that was _obviously_ such, not merely a special case  
> > of ‘if’.
> > 
> > In grad school I created a toy language that had a ‘test’  
> > statement. (I’m not advocating this for Ruby, BTW, though  
> > I personally wouldn’t mind seeing it.)
> 
> Hal, have you ever used FORTRAN’s computed GOTO statement? IIRC, you  
> supply an expression followed by a list of line numbers (line numbers  
> are the same as C labels, except they’re, well, numbers). Control  
> branches to the 1st, 2nd, 3rd, whatever line number based on the value  
> of the expression.
> 
> (This is based on my \>20 year old memory of FORTRAN 77, so I could be  
> off in the details. I believe “computed GOTO” is deprecated in current  
> FORTRANs. 🙂

As far as I recall, your memory of FORTRAN (which I have struggled  
to block) is correct.

But that’s a different animal. What I want/wanted was an elegant,  
simple way to express successive (Boolean) tests as a multiway  
branch. The if/elsif/…/end solution is widespread, and there is  
nothing really wrong with it. But I like mine better. Many or most  
people, of course, will not.

It’s an unfamiliar construct. I don’t doubt that when the switch or  
case statement was introduced, a lot of people said, “Why would you  
want that?” After all, a chain of ifs will do the same thing. (Was  
it ALGOL that introduced this concept? Or BCPL? Or what?)

I’ve noticed with amusement over the years that every Blub programmer  
disdains minor improvements, deeming them more minor than they  
actually are. I recall when I was a freshman arguing the merits of  
the for-loop (in Pascal or BASIC) versus the DO-loop of FORTRAN. The  
other person was a die-hard FORTRAN programmer, not even F77 which  
was not widespread then, who had spent so much time on assembly (and  
perhaps even machine language) that FORTRAN seemed like a paradise  
to him. And I asked him something like, How would you make a loop go  
backwards, from a high value to a low? And his reply was: “Well, all  
you do is…” and told how he would keep a separate variable that was  
the difference of the high value and the counter.

And, in a sense, he was right. That’s “all you do.” Create another  
variable and do a subtraction. But why bother?

Whenever I have argued for a baby-step forward, a minor improvement  
over an older way of doing something, the most common response I  
have ever heard is: “All you do is…”

But of course, it’s the kai-zen principle at work. Take a hundred  
baby steps forward, and suddenly it looks like a giant quantum leap.  
That, I think, is why we like Ruby – or part of the reason – or  
that’s true for me, anyway.

But as for the multiway successive Boolean test: Frankly, I’d suggest  
it as an RCR – I do feel strongly enough about it – but I don’t  
think it would ever be accepted. And really, in the long run, who  
cares?

Hal

> **···**
>
> ----- Original Message -----  
> From: “Tim Hunter” [Tim.Hunter@sas.com](mailto:Tim.Hunter@sas.com)  
> Newsgroups: comp.lang.ruby  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Saturday, December 07, 2002 12:36 PM  
> Subject: (OT) Re: elseif?
> 
> > On Sat, 7 Dec 2002 14:03:50 +0900, “Hal E. Fulton” \> [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com) wrote:

---

<div class="post-metadata">

**Author:** ![Alan\_Chen2](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Alan\_Chen2](https://rubytalk.org/u/Alan_Chen2)\
**Post date:** [7 December 2002 19:04 UTC](https://rubytalk.org/t/elseif/3348/12 "2002-12-07T19:04:08Z")

</div>

I remember that. It was the closest thing FORTRAN 77 had to a case  
statement. IIRC F90 now has SELECT CASE.

> **···**
>
> On Sun, Dec 08, 2002 at 03:36:07AM +0900, Tim Hunter wrote:
> 
> > Hal, have you ever used FORTRAN’s computed GOTO statement? IIRC, you  
> > supply an expression followed by a list of line numbers (line numbers  
> > are the same as C labels, except they’re, well, numbers). Control  
> > branches to the 1st, 2nd, 3rd, whatever line number based on the value  
> > of the expression.
> > 
> > (This is based on my \>20 year old memory of FORTRAN 77, so I could be  
> > off in the details. I believe “computed GOTO” is deprecated in current  
> > FORTRANs. 🙂
> 
> –  
> Alan Chen  
> Digikata Computing  
> [http://digikata.com](http://digikata.com)

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [7 December 2002 21:56 UTC](https://rubytalk.org/t/elseif/3348/13 "2002-12-07T21:56:52Z")

</div>

Nice!! You should add it to the RubyIdioms wiki page.

martin

> **···**
>
> Joel VanderWerf [vjoel@path.berkeley.edu](mailto:vjoel@path.berkeley.edu) wrote:
> 
> > x = 1.5
> > 
> > case true  
> > when x \< 0; puts “x \< 0”  
> > when 0 \<= x && x \< 1; puts “x in interval [0,1)”  
> > when 1 \<= x && x \< 2; puts “x in interval [1,2)”  
> > when 2 \<= x; puts “x \>= 2”  
> > end
> > 
> > Sorta like cond in lisp…

---

<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:** [7 December 2002 23:24 UTC](https://rubytalk.org/t/elseif/3348/14 "2002-12-07T23:24:51Z")

</div>

> Hal E. Fulton wrote:  
> …
> 
> > Well, I too prefer “elseif” to “elsif” – but I don’t see  
> > that it will be added, and it’s a very minor point.
> > 
> > Actually, what I’ve always wished for is a multiway Boolean  
> > branch that was _obviously_ such, not merely a special case  
> > of ‘if’.
> 
> How 'bout this:
> 
> x = 1.5
> 
> case true  
> when x \< 0; puts “x \< 0”  
> when 0 \<= x && x \< 1; puts “x in interval [0,1)”  
> when 1 \<= x && x \< 2; puts “x in interval [1,2)”  
> when 2 \<= x; puts “x \>= 2”  
> end

In essence, that’s what I’m talking about. But the  
way it’s expressed here makes it seem even more  
foreign than cascading if/elsifs.

I’ve just always wished a language provided direct  
support for such a construct. But I’ve never run  
across anyone else who wished for it.

> Sorta like cond in lisp…

Probably. I don’t know LISP. Still thinking of  
learning it someday – along with FORTH, Latin,  
and Esperanto…

Hal

> **···**
>
> ----- Original Message -----  
> From: “Joel VanderWerf” [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Saturday, December 07, 2002 3:18 PM  
> Subject: Re: elseif?

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [8 December 2002 05:52 UTC](https://rubytalk.org/t/elseif/3348/15 "2002-12-08T05:52:19Z")

</div>

Hi,

> x = 1.5

case

> when x \< 0; puts “x \< 0”  
> when 0 \<= x && x \< 1; puts “x in interval [0,1)”  
> when 1 \<= x && x \< 2; puts “x in interval [1,2)”  
> when 2 \<= x; puts “x \>= 2”  
> end

If no expression after “case”, “when” clause evaled as true  
will be executed.

> **···**
>
> At Sun, 8 Dec 2002 06:18:52 +0900, Joel VanderWerf wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [8 December 2002 11:18 UTC](https://rubytalk.org/t/elseif/3348/16 "2002-12-08T11:18:26Z")

</div>

> (This is based on my \>20 year old memory of FORTRAN 77, so I could be  
> off in the details. I believe "computed GOTO" is deprecated in current  
> FORTRANs. 🙂

I hope it's deprecated. I take me 3 days to debug one of my FORTRAN 4  
program written with computed GOTO (ACP program) and it's worst than a  
case statement. But I always write stupid things :-))

Guy Decoux

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [8 December 2002 15:39 UTC](https://rubytalk.org/t/elseif/3348/17 "2002-12-08T15:39:06Z")

</div>

> &nbsp;&nbsp;case true

You don't need true

> &nbsp;&nbsp;&nbsp;when x \> 0

> But it requires the conditions to be "real" booleans, so here only  
> 'true' is considered to be true and not, as usual, all non-false and  
> non-nil values.

no, if you don't use true

pigeon% ruby -e 'case; when 12; puts 24; end'  
24  
pigeon%

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Dave\_Pearson](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@Dave\_Pearson](https://rubytalk.org/u/Dave_Pearson)\
**Post date:** [10 December 2002 17:54 UTC](https://rubytalk.org/t/elseif/3348/18 "2002-12-10T17:54:18Z")

</div>

- Rudolf Polzer [AntiATField\_adsgohere@durchnull.de](mailto:AntiATField_adsgohere@durchnull.de):

> If the latter, it has already existed in another language and looks like  
> this:
> 
> (cond  
> ((expr1) (stmt1))  
> ((expr2) (stmt2))  
> ((expr3) (stmt3))  
> …  
> ((exprN) (stmtN))  
> )

Those who know and remember Clipper (and Fox, and probably dBase) will also  
recognise its case statement as being such a facility:

> **···**
>
> ,----
> 
> > Do Case  
> > Case x \> 0  
> > ? “x \> 0”  
> > Case x == 0  
> > ? “x == 0”  
> > Case x \< 0  
> > ? “x \< 0”  
> > Otherwise  
> > ? “Something wonderful has happened”  
> > EndCase  
> > `----
> 
> –  
> Harbour is a free | Harbour Web Site: [http://www.harbour-project.org/](http://www.harbour-project.org/)  
> software, cross | Harbour FAQ…: [Frequently Asked Questions about Harbour](http://www.harbour-project.org/faq/)  
> platform, Clipper | My Harbour Pages: [http://www.davep.org/harbour/](http://www.davep.org/harbour/)  
> compatible compiler | My Harbour News.: [http://www.davep.org/harbour/news/](http://www.davep.org/harbour/news/)

---

<div class="post-metadata">

**Author:** ![Dave\_Mail\_Archive](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Dave\_Mail\_Archive](https://rubytalk.org/u/Dave_Mail_Archive)\
**Post date:** [7 December 2002 20:23 UTC](https://rubytalk.org/t/elseif/3348/19 "2002-12-07T20:23:00Z")

</div>

Unfortunately, many folks seem to feel that continuous improvement means  
continuous accretion of features. I have a theory that in really, really  
good designs, the total amount of _stuff_ stays the same over time. As  
improvements are added, less good things are discarded.

This isn’t easy in a programming language, where throwing stuff away  
breaks backward compatibility.

Cheers

Dave

> **···**
>
> On Sat, 2002-12-07 at 13:04, Hal E. Fulton wrote:
> 
> > But of course, it’s the kai-zen principle at work. Take a hundred  
> > baby steps forward, and suddenly it looks like a giant quantum leap.  
> > That, I think, is why we like Ruby – or part of the reason – or  
> > that’s true for me, anyway.

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [8 December 2002 01:40 UTC](https://rubytalk.org/t/elseif/3348/20 "2002-12-08T01:40:05Z")

</div>

> I’ve just always wished a language provided direct  
> support for such a construct. But I’ve never run  
> across anyone else who wished for it.
> 
> > Sorta like cond in lisp…
> 
> Probably. I don’t know LISP. Still thinking of  
> learning it someday – along with FORTH, Latin,  
> and Esperanto…
> 
> Hal

I’d like to learn LISP and Latin too. Maybe if someone coded a LISP  
environment whose interface (and code) was entirely in Latin… two birds one  
stone???

Gavin

[Next page](https://rubytalk.org/t/elseif/3348.md?page=2)
