fend.red 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. COMMENT R E D U C E PREPROCESSOR FOR DECSYSTEMS 10 AND 20;
  2. COMMENT Standard LISP Functions Defined in LISP 1.6:
  3. ABS AND APPEND APPLY ATOM CAR ... CDDDDR COND CONS DIVIDE EQ EQUAL
  4. EVAL FIX GENSYM GET GO LENGTH LINELENGTH MEMBER MEMQ MINUS NCONC
  5. NOT NULL NUMBERP OR PRINC PRIN1 PROG QUOTE READCH REMAINDER
  6. RETURN REVERSE RPLACA RPLACD SET SETQ SUBST TERPRI;
  7. COMMENT compiler support functions needed for DEC-10 implementation;
  8. REMFLAG('(LIST2 LIST3 LIST4 LIST5 REVERSIP),'LOSE);
  9. SYMBOLIC PROCEDURE LIST2(U,V); U . V . NIL;
  10. SYMBOLIC PROCEDURE LIST3(U,V,W); U . V . W . NIL;
  11. SYMBOLIC PROCEDURE LIST4(U,V,W,X); U . V . W . X . NIL;
  12. SYMBOLIC PROCEDURE LIST5(U,V,W,X,Y); U . V . W . X . Y . NIL;
  13. SYMBOLIC PROCEDURE REVERSIP U;
  14. BEGIN SCALAR X,Y;
  15. WHILE U DO <<X := CDR U; Y := RPLACD(U,Y); U := X>>;
  16. RETURN Y
  17. END;
  18. COMMENT Primitive Standard LISP Functions Defined in terms of LISP 1.6;
  19. SYMBOLIC PROCEDURE EQN(M,N); M EQ N OR NUMBERP M AND M=N;
  20. SYMBOLIC PROCEDURE EXPLODE2 U; EXPLODEC U;
  21. SYMBOLIC PROCEDURE FLUID U;
  22. BEGIN
  23. A: IF NULL U THEN RETURN NIL;
  24. IF GETD 'MODBIND AND NOT GET(CAR U,'MODE)
  25. THEN PUT(CAR U,'MODE,'SYMBOLIC); %interface to mode system;
  26. IF GETD CAR U
  27. THEN ERROR(10,LIST("Function",CAR U,"cannot be fluid"));
  28. FLAG(LIST CAR U,'FLUID);
  29. IF NULL !*DEFN THEN QSET(CAR U,NIL);
  30. U := CDR U;
  31. GO TO A
  32. END;
  33. SYMBOLIC PROCEDURE QSET(U,V); IF ATOM ERRORSET(U,NIL,NIL) THEN SET(U,V);
  34. !*DEFN := NIL;
  35. SYMBOLIC PROCEDURE FLUIDP U; FLAGP(U,'FLUID);
  36. SYMBOLIC PROCEDURE GLOBAL U;
  37. BEGIN
  38. A: IF NULL U THEN RETURN NIL;
  39. IF GETD 'MODBIND AND NOT GET(CAR U,'MODE)
  40. THEN PUT(CAR U,'MODE,'SYMBOLIC); %interface to mode system;
  41. IF GETD CAR U
  42. THEN ERROR(10,LIST("Function",CAR U,"cannot be global"));
  43. FLAG(LIST CAR U,'GLOBAL);
  44. IF NULL !*DEFN THEN QSET(CAR U,NIL);
  45. U := CDR U;
  46. GO TO A
  47. END;
  48. SYMBOLIC PROCEDURE GLOBALP U; FLAGP(U,'GLOBAL);
  49. GLOBAL '(OBLIST);
  50. FLUID '(!*PI!*);
  51. GLOBAL '(FTYPES!*);
  52. FTYPES!* := '(EXPR FEXPR MACRO);
  53. FLAG('(EXPR FEXPR),'COMPILE);
  54. PUTD('!%PUTD,'EXPR,CDR GETD 'PUTD);
  55. SYMBOLIC PROCEDURE PUTD(NAME,TYPE,BODY);
  56. BEGIN
  57. IF TYPE EQ 'SUBR THEN TYPE:='EXPR
  58. ELSE IF TYPE EQ 'FSUBR THEN TYPE:='FEXPR
  59. ELSE GO NOWARN;
  60. WARNING "(F)SUBR converted to (F)EXPR in PUTD";
  61. NOWARN:
  62. IF FLAGP(NAME,'LOSE) THEN RETURN NIL
  63. ELSE IF TYPE MEMQ FTYPES!* AND GETD NAME
  64. AND NULL !*DEFN THEN <<WARNING LIST(NAME,"redefined");
  65. REMPROP(NAME,'TRACE);
  66. REMPROP(NAME,'TRACECNT)>>;
  67. IF !*COMP AND FLAGP(TYPE,'COMPILE) AND NOT CODEP BODY
  68. THEN COMPD(NAME,TYPE,BODY)
  69. ELSE IF TYPE MEMQ FTYPES!* THEN !%PUTD(NAME,TYPE,BODY)
  70. ELSE PUT(NAME,TYPE,BODY);
  71. RETURN NAME
  72. END;
  73. !*COMP := NIL;
  74. SYMBOLIC PROCEDURE UNFLUID U;
  75. <<FOR EACH X IN U DO REMPROP(X,'MODE); REMFLAG(U,'FLUID)>>;
  76. COMMENT COMPOSITE STANDARD LISP FUNCTIONS NOT DEFINED IN LISP 1.6;
  77. SYMBOLIC PROCEDURE ASSOC(U,V);
  78. %looks for U in association list V using an EQUAL test;
  79. IF NULL V THEN NIL
  80. ELSE IF U=CAAR V THEN CAR V
  81. ELSE ASSOC(U,CDR V);
  82. FEXPR PROCEDURE DE U; PUTD(CAR U,'EXPR,'LAMBDA . CADR U . CDDR U);
  83. SYMBOLIC PROCEDURE DEFLIST(L,V);
  84. IF NULL L THEN NIL
  85. ELSE PROGN(PUT(CAAR L,V,CADAR L),CAAR L) . DEFLIST(CDR L,V);
  86. SYMBOLIC PROCEDURE DELETE(U,V);
  87. IF NULL V THEN NIL
  88. ELSE IF U = CAR V THEN CDR V
  89. ELSE CAR V . DELETE(U,CDR V);
  90. FEXPR PROCEDURE DF U; PUTD(CAR U,'FEXPR,'LAMBDA . CADR U . CDDR U);
  91. FEXPR PROCEDURE DM U; PUTD(CAR U,'MACRO,'LAMBDA . CADR U . CDDR U);
  92. SYMBOLIC PROCEDURE EXPAND(L,FN);
  93. IF NULL L THEN NIL
  94. ELSE IF NULL CDR L THEN CAR L
  95. ELSE LIST(FN,CAR L,EXPAND(CDR L,FN));
  96. SYMBOLIC PROCEDURE M**N;
  97. BEGIN SCALAR P,Q;
  98. IF N<0 THEN RETURN (1.0/M**(-N))
  99. ELSE IF N=0 OR M=1 THEN RETURN 1;
  100. P := 1;
  101. A: Q := DIVIDE(N,2);
  102. IF CDR Q = 0 THEN GO TO B;
  103. P := M*P;
  104. IF CAR Q = 0 THEN RETURN P;
  105. B: N := CAR Q;
  106. M := M*M;
  107. GO TO A
  108. END;
  109. SYMBOLIC PROCEDURE MAPOBL !*PI!*;
  110. FOR EACH X IN OBLIST DO FOR EACH Y IN X DO !*PI!* Y;
  111. SYMBOLIC MACRO PROCEDURE MAX U; EXPAND(CDR U,'MAX2);
  112. SYMBOLIC PROCEDURE MAX2(U,V); IF U<V THEN V ELSE U;
  113. SYMBOLIC MACRO PROCEDURE MIN U; EXPAND(CDR U,'MIN2);
  114. SYMBOLIC PROCEDURE MIN2(U,V); IF U>V THEN V ELSE U;
  115. SYMBOLIC PROCEDURE ONEP U; U=1 OR U=1.0;
  116. SYMBOLIC PROCEDURE PAIR(U,V);
  117. IF NULL U AND NULL V THEN NIL
  118. ELSE IF NULL U OR NULL V
  119. THEN ERROR(171,LIST(LIST(U,V),"mismatched - PAIR"))
  120. ELSE (CAR U . CAR V) . PAIR(CDR U,CDR V);
  121. SYMBOLIC MACRO PROCEDURE PLUS U; EXPAND(CDR U,'PLUS2);
  122. SYMBOLIC PROCEDURE SASSOC(U,V,!*PI!*);
  123. %looks for U in association list V using an EQUAL test.
  124. %If U is not found, !*PI!*() is returned;
  125. IF NULL V THEN !*PI!*()
  126. ELSE IF U=CAAR V THEN CAR V
  127. ELSE SASSOC(U,CDR V,!*PI!*);
  128. SYMBOLIC PROCEDURE SUBLIS(X,Y);
  129. BEGIN SCALAR U;
  130. IF NULL X THEN RETURN Y;
  131. U := X;
  132. A: IF NULL U THEN RETURN IF ATOM Y
  133. OR (U := SUBLIS(X,CAR Y) . SUBLIS(X,CDR Y)) = Y
  134. THEN Y
  135. ELSE U
  136. ELSE IF Y = CAAR U THEN RETURN CDAR U;
  137. U := CDR U;
  138. GO TO A
  139. END;
  140. SYMBOLIC MACRO PROCEDURE TIMES U; EXPAND(CDR U,'TIMES2);
  141. SYMBOLIC PROCEDURE QUIT; FREEZE T;
  142. END;