1. Suggestion for Euphoria 2.3, 2.2a, 2.2.1, whatever

I noticed several things that C has that Euphoria doesn't. Among these are
structs and switch statements. It should be easy to implement a struct like:

struct thisStruct do
  integer a, b
  sequence st
end struct

And as for the switch statements:

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

And one feature that even secondbestlanguageintheworld Java doesn't have!
Using plain old math operators on sequences. Maybe you could say, 'st =
"hi"' instead of the current 'equals(st,"hi")' or 'compare(st,"hi")=0'. This
would be much clearer.

  - Thx for listening

new topic     » topic index » view message » categorize

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

On Thu, 07 Sep 2000, you wrote:
> I noticed several things that C has that Euphoria doesn't. Among these are
> structs and switch statements. It should be easy to implement a struct like:
>
> struct thisStruct do
>   integer a, b
>   sequence st
> end struct

Since a structure is very likely to be constant during its' existence,
why not declare it in much the same way:

structure x =
 integer a,b,
 sequence st
end structure


> And as for the switch statements:
>
> 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

new topic     » goto parent     » topic index » view message » categorize

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

----- 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 message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu