[M3devel] IsAssignable

Jay K jay.krell at cornell.edu
Sun Jan 10 03:05:24 CET 2010


Current:


PROCEDURE IsAssignable (a, b: T): BOOLEAN =
  VAR i, e: T;  min_a, max_a, min_b, max_b, min, max: Target.Int;
  BEGIN
    IF IsEqual (a, b, NIL) OR IsSubtype (b, a) THEN
      RETURN TRUE;
    ELSIF IsOrdinal (a) THEN
      (* ordinal types:  OK if there is a common supertype
         and they have at least one member in common. *)
      IF IsEqual (Base(a), Base(b), NIL)
         AND GetBounds (a, min_a, max_a)
         AND GetBounds (b, min_b, max_b) THEN
        (* check for a non-empty intersection *)
        min := min_a;  IF TInt.LT (min, min_b) THEN min := min_b; END;
        max := max_a;  IF TInt.LT (max_b, max) THEN max := max_b; END;
        RETURN TInt.LE (min, max);
      ELSE
        RETURN FALSE;
      END;

my proposed:




PROCEDURE IsAssignable (a, b: T): BOOLEAN =

  VAR i, e: T;  min_a, max_a, min_b, max_b, min, max: Target.Int;

  BEGIN

    IF IsEqual (a, b, NIL) OR IsSubtype (b, a) THEN

      RETURN TRUE;

    ELSIF IsOrdinal (a) THEN

      (* ordinal types:  OK if they have at least one member in common. *)

      IF GetBounds (a, min_a, max_a)

         AND GetBounds (b, min_b, max_b) THEN

        (* check for a non-empty intersection *)

        min := min_a;  IF TInt.LT (min, min_b) THEN min := min_b; END;

        max := max_a;  IF TInt.LT (max_b, max) THEN max := max_b; END;

        RETURN TInt.LE (min, max);

      ELSE

        RETURN FALSE;

      END;



Your proposed:

> IF (IsEqual (Base(a), Base(b), NIL)
> OR IsEqual (Base(a), Int.T, NIL) AND IsEqual (Base(b), LInt.T, NIL)
> OR IsEqual (Base(a), LInt.T, NIL) AND IsEqual (Base(b), Int.T, NIL))
> AND GetBounds (a, min_a, max_a)
> AND GetBounds (b, min_b, max_b) THEN

What's the point of checking the types? Given that they are both ordinal?
To restrict certain assignments?
Aren't the base types of any ordinal type either Int.T or LInt.T?
 So the check will always be true?
I have to check.


 - Jay

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100110/35490984/attachment-0001.html>


More information about the M3devel mailing list