Re: Suggestion for Euphoria 2.3, 2.2a, 2.2.1, whatever

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message -----
From: irv <irv at ELLIJAY.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Friday, September 08, 2000 10:26 AM
Subject: Re: Suggestion for Euphoria 2.3, 2.2a, 2.2.1, whatever


> On Thu, 07 Sep 2000, you wrote:
> >
> > switch a do
> >   case 1 do
> >     puts(1,"a is 1\n")
> >   elsif 2 do
> >     puts(1,"a is 2\n")
> >   else
> >     puts(1,"a is some other value\n")
> >   end case
> > end switch
>
> Useful,  but ugly.
> Why not simplify it somewhat:
> case a
>  = 1 then  puts(1,"a is 1"),
>  = 2 then puts(1,"a is 2"),
>  < 5 then puts(1,"a is between 3 and 5")
> else
>   puts(1,"ERROR")
> end case
>
> --
> Regards,
> Irv

Or perhaps

 case a
    1: puts(1,"a is 1"),
    2: puts(1,"a is 2"),
    <5: puts(1,"a is between 3 and 5")
    otherwise: puts(1,"ERROR")
end case

which I find more readable. The "otherwise" statement makes it easy to
distinguish case blocks from if blocks at a glance, even if internally
they'd work the same way. The same philosophy evidently inspired the
"unless" statement (can't remember where), actually an "if not" in disguise,
as in

  unless a = b
    puts(1,"Alert! A no longer equals B")
  end unless

While I'm at it, my own wish list might include something equivalent to the
COBOL level 88 definitions, which let you assign a name to a value, series
of values, or range. In Eu this could be accomplished thru the CONSTANT
statement, as in

constant CHILD = {0..12}, TEEN = {13..19}, OLDGEEZER {20..999}
constant PRIME = {1,2,3,5,7,11}
constant USER_SAYS_OK = {"y", "yes", "ok", "si", "oui"}

This would also help towards shorter, more readable code. As it would
obviously apply sequence processing, subscripting might be allowed, also for
recursive redefinition:

constant BABY = CHILD[0..3], USER_SOUNDS_FRENCH = USER_SAYS_OK[5]

Thus you'd write

case users_age
  baby: puts(1,"Please call Mom.\n")
  child: puts(1,"Sorry, kid. This is a boring adult math puzzle.\n")
  teen: puts(1,"Welcome to Goreville!\n")
  oldgeezer: puts(1,"Go get a life!\n")
  otherwise: puts(1,"Hi, Methuselah!\n")
end case

and nicer-looking ifs, which could get very complicated in just a few words:

  if teen_user and after_midnight and long_program_run and weekday
    puts(1,"Go get some sleep.")
  end if

Wish I could...

Gerardo


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu