[Oberon] identity of two VARs

jan verhoeven jan at verhoeven272.nl
Wed Sep 14 21:22:42 CEST 2005


Op Wednesday 14 September 2005 17:48 schreef shark at gulfnet.sd64.bc.ca:

 > PROCEDURE Identical*(VAR source, target: ARRAY OF CHAR):integer;
 > (* Return 0, 1, 2 or 3 according to identity of location and
 >    identity of content strings. *)
 > VAR
 > 	identicallocation, identicalcontent: INTEGER;
 > BEGIN
 > 	IF ?? THEN (* source and target are the same array *)
 > 		identicallocation := 1 ELSE identicallocation := 0
 > 	END;
 > 	IF source = target THEN (* the strings in source and target match. *)
 > 		identicalcontent := 1 ELSE identicalcontent := 0
 > 	END;
 > 	RETURN((2*identicalcontent)+identicallocation)
 > END Identical;

Why not:

PROCEDURE Identical*(VAR source, target: ARRAY OF CHAR):integer;
   (* Return 0, 1, 2 or 3 according to identity of location and
      identity of content strings. *)

BEGIN
  IF  ??  THEN
     RETURN (3)
  ELSE
     IF  src=target  THEN
        RETURN (1)
     ELSE
        RETURN (2)
     END
  END;
  RETURN (0)	(* Just in case.,.. *)
END Identical;

There are only THREE outcomes. If the strings are at the same location, 
they MUST be identical. So that's outcome 1. If they are in different 
places, they MAY be equal, so that's two more outcomes. So in total, you 
have three possible results, not four.

As Wirth proclaims: if the code is unclear, your basic analysis was wrong. 
Back to the drawing table.

 > More briefly,
 > PROCEDURE Identical*(VAR source, target: ARRAY OF CHAR):integer;
 > BEGIN
 > 	RETURN((2*(source=target))+??)
 > END Identical;.

If Niklaus would have been dead (which he isn't to my knowledge and I hope 
it will stay so for many years to come), he would have turned in his grave 
after such a monstrous piece of code.

Also, Martin Reiser is very explicit about this in 'Programming in Oberon':

 | 4.2.2 Type rules. 
 | 
 | Let us look at a second set of syntactically well-formed expressions: 
 | 
 | 	"a" + 3.14159
 | 	(a=b) - sqrt ("144")
 |                                                    
 | It is not clear how these expressions should be evaluated. What sense 
 | does it make to add a character constant to a number? Can a truth value 
 | be used as a number? There are various schools of thought with respect 
 | to these questions. Some languages (e.g. PL/I) define elaborate type 
 | conversion rules or treat truth values as the numerical constants 0 and 
 | 1 (e.g. APL). We believe that what such languages teach us is the way 
 | not to do it. 

I prefer longer code over C style functions.

-- 
Met vriendelijke groeten

Jan Verhoeven
http://fruttenboel.verhoeven272.nl



More information about the Oberon mailing list