RE: Case/switch

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

-------Phoenix-Boundary-07081998-

Hi Kat, you wrote on 2/14/02 11:21:23 AM:

>
>On 15 Feb 2002, at 13:46, Matthew Lewis wrote
> > -----Original Message-----
> > From: SR.Williamson [mailto:writeneu at hotmail.com]
>
> Your example might look something like:
>
> sequence condition, result
>
> condition = { middle, leftedge, rightedge, topedge, bottomedge }
> result = { routine_id("do_middle"),.....}
>
> Then, for your decision:
>
> case = find( situation, condition )
> call_proc( result[case] )
>

>Shouldn't this be in the official Eu help files? Karl, if this can be
done
>in two
>lines of Eu, wouldn't it be easy as a command alias in the native code?
>

What you really have here is a single function call:
    switch (situation, condition, result)
which does the 2 lines in question. One improvement might be
to combine the condition and result arrays into one:
   sequence mycases = {{middle, routine_id (do_middle)}
                       , (top, routine_id (do_proc)}
                       ... }
Then write a switch procedure:
    switch (situation, mycases)

All of which, to my mind, shows the versatility of
Euphoria but misses the point of the real
switch statement-- the close coupling between the
'case' and the executed code.

For source code hackers I would suggest two
approaches:

1) Simple renaming for clarity:
   switch var_x
   case 3:
   case 4:
   ...
   end switch

Which would be exactly equivalent to:
   if var_x = 3 then
   elsif var_x = 4 then
   ...
   end if

2) The addition of a new opcode which does a direct
   branch through a table.
   There are some tough issues in the generation of
   a table -- for instance:
     switch x
     case 1:
     case 120000:

Karl

-------Phoenix-Boundary-07081998---

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

Search



Quick Links

User menu

Not signed in.

Misc Menu