[Oberon] Alternatives for cases.

Chris Burrows chris at cfbsoftware.com
Thu Mar 7 12:45:40 CET 2019


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Chris Burrows
> Sent: Thursday, 7 March 2019 7:14 AM
> To: 'ETH Oberon and related systems'
> Subject: Re: [Oberon] Alternatives for cases.
> 
> > -----Original Message-----
> > From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> > peter at easthope.ca
> > Sent: Thursday, 7 March 2019 6:20 AM
> > To: oberon at lists.inf.ethz.ch
> > Subject: [Oberon] Alternatives for cases.
> >
> > Hi,
> >
> > Seeing as alternative techniques for exiting a procedure and for
> > ending interation are popular subjects recently, another question
> > about alternatives.
> >
> > Elimination of IF and CASE has some aesthetic appeal.
> > Otherwise, is the array technique ever worth using?
> > OK when most elements in the array are distinct?
> > How fast is array indexing compared to jumping?
> > How bad is the additional procedure call?
> >
> 
> This is one of my test CASEs - I hope it's self-explanatory. Try
> implementing that using procedures and see what you think.
> Consider the resulting readability / maintainability / code size as
> well as speed of execution:
> 
>     IF (ch <= 02FX) OR (ch >= 07BX) THEN
>       INC(others)
>     ELSE
>       CASE ch OF
>       03AX..040X, 05BX..060X:
>         INC(others) |
>       "a", "e", "i", "o", "u":
>         INC(vowels);
>         INC(letters) |
>       "A", "E", "I", "O", "U":
>         INC(vowels);
>         INC(letters);
>         INC(capitals) |
>       "b".."d", "f".."h", "j".."n", "p".."t", "v".."z":
>         INC(letters) |
>       "B".."D", "F".."H", "J".."N", "P".."T", "V".."Z":
>         INC(letters);
>         INC(capitals) |
>       "0".."9":
>         INC(digits)
>       END
>     END
> 

I've just done a test run using an array of Procedure variables with 50000
characters (almost) evenly distributed from CHR(0) to CHR(127). The results
show that for this application, procedure variables are not a good idea:

         Data (bytes)    Code (bytes)    Time (ms)
PROCs     540            1404              65
IF-ELSE     8             864              53
CASE        8            1080              42

Apart from anything else, initialising the array of procedures in what I
considered to be an elegant way took a bit of thought. There are many
different ways it could be done. Mine looks like this:

  InitMinMax(0, LEN(Procs) - 1, Others);
  InitChars("bcdfghjklmnpqrstvwxyz", LowerLetters);
  InitChars("BCDFGHJKLMNPQRSTVWXYZ", UpperLetters);
  InitChars("aeiou", LowerVowels);
  InitChars("AEIOU", UpperVowels);
  InitChars("0123456789", Digits) 

where the last parameter in each is the name of the procedure. InitMinMax
and InitChars are both just one-line procedures.

Regards,
Chris

Chris Burrows
CFB Software
http://www.astrobe.com







More information about the Oberon mailing list