[M3devel] m3front/Force_pair

Jay K jay.krell at cornell.edu
Fri Apr 12 18:05:34 CEST 2013


m3front/misc/CG.m3


PROCEDURE Force_pair (commute: BOOLEAN): BOOLEAN =
  (* Returns TRUE if the items are stacked in the wrong order *)
  VAR s1 := stack [SCheck (1, "Force_pair")].kind = VKind.Stacked;
  VAR s2 := stack [SCheck (2, "Force_pair")].kind = VKind.Stacked;
  BEGIN
    IF s1 AND s2 THEN
      (* both elements are already stacked *)
      RETURN FALSE;
    ELSIF s2 THEN
      (* bottom element is already stacked *)
      Force ();
      RETURN FALSE;
    ELSIF s1 THEN
      Swap ();
      Force ();
      IF commute THEN RETURN TRUE END;
      Swap ();
      RETURN FALSE;
    ELSE (* neither element is stacked *)
      Swap ();
      Force ();
      Swap ();
      Force ();
      RETURN FALSE;
    END;
  END Force_pair;


Shouldn't the last part be:

    ELSE (* neither element is stacked *)
      IF commute THEN
        Force ();
        Swap ();
        Force ();
        RETURN TRUE;
      END;
      Swap ();
      Force ();
      Swap ();
      Force ();
      RETURN FALSE;
    END;

?


Probably there is a way to write the function with less duplication.


 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20130412/1c497771/attachment-0001.html>


More information about the M3devel mailing list