Example 8
- Last UpdatedJan 20, 2023
- 1 minute read
This example illustrates the possibility of writing a recursive macro, that means, a macro which calls itself as a submacro. It uses a modified version of the macro RECTANGLE given in Appendix 2.
MACRO,RECPNT,PNT1,PNT2;
DECLARE,PNT1,POINT_2D;
DECLARE,PNT2,POINT_2D;
CALL,RECTANGLE,PNT1,PNT2;
ASSIGN,X1,PNT1/XCOORD;
ASSIGN,Y1,PNT1/YCOORD;
!
! When the condition is not fulfilled
! no further calls to RECPNT are made
! and the execution is terminated
!
IF,X1 < 250;
ASSIGN,X2,PNT2/XCOORD;
ASSIGN,Y2,PNT2/YCOORD;
POINT_2D,PNT3,X2+X2-X1,Y2+Y2-Y1;
CALL,RECPNT,PNT2,PNT3;
ENDIF;
ENDMACRO;
MACRO,RECTANGLE,P1,P3;
DECLARE,P1,POINT_2D;
DECLARE,P3,POINT_2D;
ASSIGN,X1,P1/XCOORD;
ASSIGN,Y1,P1/YCOORD;
ASSIGN,X3,P3/XCOORD;
ASSIGN,Y3,P3/YCOORD;
POINT_2D,P2,X1,Y3;
POINT_2D,P4,X3,Y1;
CONTOUR,CNT,P1
/LINEEND = P2
/LINEEND = P3
/LINEEND = P4
/LINEEND = P1;
PRESENT,CNT;
ENDMACRO;