[comp.lang.icon] Case statements and string scanning

R.J.Hare@edinburgh.ac.uk (02/26/91)

 
Thanks to those who replied.
 
The method involving paired tests and operations seems an intersting idea, I
shall certainly try it out when I get a chance.
 
RGs comments on the use of if statements highlight the 'problem'. If I do
 
if expr1 then ...
if expr2 then ...
if expr3 then ...
 
obviously with varied 'expr's, I could have more than one block of code being
executed when I only want one. The alternative:
 
if expr1
then ...
else if expr2
     then ...
     else if expr3
          then ...
          else ...
 
is fine but awful hard to read (which is the part I am unhappy about). What is
really needed is something like the Fortran ELSEIF construct:
 
IF (test1) THEN
  .
ELSEIF (test2) THEN
  .
ELSEIF (test3) THEN
  .
ELSE
  .
ENDIF
 
which is only a case statement with a different hat on.
 
Is there such a thing in Icon (ie: have I missed it?). Should there be?
 
Roger Hare.

wgg@CS.WASHINGTON.EDU (William Griswold) (02/27/91)

No, there is no ELSEIF in Icon.  However, I indent my IF THEN ELSE's
differently to allow a more tabular appearance:

if t1 then
   e1
else if t2 then
   e2
else if t3 then
   e3
else
   e4

I don't find this confusing to interpret at all.

					bill

talmage@luvthang.aquin.ori-cal.COM (David W. Talmage) (02/27/91)

:is fine but awful hard to read (which is the part I am unhappy about). What is
:really needed is something like the Fortran ELSEIF construct:
: 
:IF (test1) THEN
:  .
:ELSEIF (test2) THEN
:  .
:ELSEIF (test3) THEN
:  .
:ELSE
:  .
:ENDIF
: 
:which is only a case statement with a different hat on.

How about using ipp, the Icon Pre-Processor that comes with the Icon
Program Library?  You could do something like this:

$define IF(x) if x
$define THEN {
$define ELSEIF(x) } else if (x) {
$define ELSE } {
$define ENDIF }

IF (test1) THEN
	.
ELSEIF (test2) THEN
	.
ELSEIF (test3) THEN
	.
ELSE
	.
ENDIF
-----------------------------------------------------------------------------
David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
"I need fifty dollars to make you hollar.  I get paid to run this luvthang."