gltail.sl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. %
  2. % GLTAIL.PSL.10 14 Jan. 1983
  3. %
  4. % FILE OF FUNCTIONS FOR COMPATIBILITY WITH PORTABLE STANDARD LISP (PSL)
  5. % G. NOVAK 20 OCTOBER 1982
  6. %
  7. (DE GETDDD (X) (CDR (GETD X)))
  8. (DE PUTDDD (FN DEF) (REMD FN) (PUTD FN 'EXPR DEF))
  9. (DE LISTGET (L PROP)
  10. (COND ((NULL L) NIL)
  11. ((EQ (CAR L) PROP) (CADR L))
  12. (T (LISTGET (CDDR L) PROP) )) )
  13. % NOTE -- THIS VERSION OF NLEFT ONLY WORKS FOR N=2.
  14. (DE NLEFT (L N)
  15. (COND ((NOT (EQN N 2)) (ERROR 0 N))
  16. ((NULL L) NIL)
  17. ((NULL (CDDR L)) L)
  18. (T (NLEFT (CDR L) N) )) )
  19. (DE NLISTP (X) (NOT (PAIRP X)))
  20. (DF COMMENT (X) NIL)
  21. % ASSUME EVERYTHING UPPER-CASE FOR PSL.
  22. (DE U-CASEP (X) T)
  23. (de glucase (x) x)
  24. % PARTIAL IMPLEMENTATION OF SUBATOM FOR POSITIVE NUMBERS.
  25. (DE SUBATOM (ATM N M)
  26. (PROG (LST)
  27. (COND ((GREATERP M (FLATSIZE2 ATM))(RETURN NIL)))
  28. A (COND ((GREATERP N M)(RETURN (AND LST (IMPLODE (REVERSIP LST))))))
  29. (SETQ LST (CONS (GLNTHCHAR ATM N) LST))
  30. (COND ((MEMQ (CAR LST) '(!' !, !!))
  31. (RPLACD LST (CONS (QUOTE !!) (CDR LST))) ))
  32. (SETQ N (ADD1 N))
  33. (GO A) ))
  34. % FIND THE STRING POSITION IN ATOM ATM WHERE A CHARACTER IN THE
  35. % BIT TABLE BITTBL OCCURS, STARTING WITH CHARACTER N.
  36. (DE STRPOSL (BITTBL ATM N)
  37. (PROG (NC)
  38. (COND ((NULL N)(SETQ N 1)))
  39. (SETQ NC (FLATSIZE2 ATM))
  40. A (COND ((GREATERP N NC)(RETURN NIL))
  41. ((INDX GLSEPBITTBL (id2int (GLNTHCHAR ATM N)))(RETURN N)))
  42. (SETQ N (ADD1 N))
  43. (GO A) ))
  44. % MAKE A BIT TABLE FROM A LIST OF CHARACTERS.
  45. (DE MAKEBITTABLE (L)
  46. (PROG ()
  47. (SETQ GLSEPBITTBL (MkVect 255))
  48. (MAPC L (FUNCTION (LAMBDA (X)
  49. (PutV GLSEPBITTBL (id2int X) T) )))
  50. (RETURN GLSEPBITTBL) ))
  51. % Fexpr for defining GLISP functions.
  52. (df dg (x)
  53. (put (car x) 'gloriginalexpr (cons 'lambda (cdr x)))
  54. (put (car x) 'glcompiled nil)
  55. (putd (car x) 'macro '(lambda (gldgform)(glhook gldgform))) )
  56. % Hook for compiling a GLISP function on its first call.
  57. (de glhook (gldgform) (glcc (car gldgform)) gldgform)
  58. % Interlisp-style NTHCHAR.
  59. (de glnthchar (x n)
  60. (prog (s l)
  61. (setq s (id2string x))
  62. (setq l (size s))
  63. (cond ((minusp n)(setq n (add1 (plus l n))))
  64. (t (setq n (sub1 n))))
  65. (cond ((or (minusp n)(greaterp n l))(return nil)))
  66. (return (int2id (indx s n)))))
  67. % FIND FIRST ELEMENT OF A LIST FOR WHICH FN IS TRUE
  68. (DE SOME (L FN)
  69. (COND ((NULL L) NIL)
  70. ((APPLY FN (LIST (CAR L))) L)
  71. (T (SOME (CDR L) FN))))
  72. % TEST IF FN IS TRUE FOR EVERY ELEMENT OF A LIST
  73. % SOME and EVERY switched FN and L
  74. (DE EVERY (L FN)
  75. (COND ((NULL L) T)
  76. ((APPLY FN (LIST (CAR L))) (EVERY (CDR L) FN))
  77. (T NIL)))
  78. % SUBSET OF A LIST FOR WHICH FN IS TRUE
  79. (DE SUBSET (L FN)
  80. (PROG (RESULT)
  81. A (COND ((NULL L)(RETURN (REVERSIP RESULT)))
  82. ((APPLY FN (LIST (CAR L)))
  83. (SETQ RESULT (CONS (CAR L) RESULT))))
  84. (SETQ L (CDR L))
  85. (GO A)))
  86. (DE REMOVE (X L) (DELETE X L))
  87. % LIST DIFFERENCE X - Y
  88. (DE LDIFFERENCE (X Y)
  89. (MAPCAN X (FUNCTION (LAMBDA (Z)
  90. (COND ((MEMQ Z Y) NIL)
  91. (T (CONS Z NIL)))))))
  92. % FIRST A FEW FUNCTION DEFINITIONS.
  93. % GET FUNCTION DEFINITION FOR THE GLISP COMPILER.
  94. (DE GLGETD (FN)
  95. (OR (and (or (null (get fn 'glcompiled))
  96. (eq (getddd fn) (get fn 'glcompiled)))
  97. (GET FN 'GLORIGINALEXPR))
  98. (GETDDD FN)))
  99. (DE GLGETDB (FN) (GLGETD FN))
  100. (DE GLAMBDATRAN (GLEXPR)
  101. (PROG (NEWEXPR)
  102. (SETQ GLLASTFNCOMPILED FAULTFN)
  103. (PUT FAULTFN 'GLORIGINALEXPR GLEXPR)
  104. (COND ((SETQ NEWEXPR (GLCOMP FAULTFN GLEXPR NIL))
  105. (putddd FAULTFN NEWEXPR)
  106. (put faultfn 'glcompiled newexpr) ))
  107. (RETURN NEWEXPR) ))
  108. (DE GLERROR (FN MSGLST)
  109. (PROG ()
  110. (TERPRI)
  111. (PRIN2 "GLISP error detected by ")
  112. (PRIN1 FN)
  113. (PRIN2 " in function ")
  114. (PRINT FAULTFN)
  115. (MAPC MSGLST (FUNCTION (LAMBDA (X) (PRIN1 X)(SPACES 1))))
  116. (TERPRI)
  117. (PRIN2 "in expression: ")
  118. (PRINT (CAR EXPRSTACK))
  119. (TERPRI)
  120. (PRIN2 "within expression: ")
  121. (PRINT (CADR EXPRSTACK))
  122. (COND (GLBREAKONERROR (ERROR 0 (CAR EXPRSTACK))))
  123. (RETURN (LIST (LIST 'GLERR (LIST 'QUOTE (CAR EXPRSTACK))))) ))
  124. % PRINT THE RESULT OF GLISP COMPILATION.
  125. (DE GLP (FN)
  126. (PROG ()
  127. (SETQ FN (OR FN GLLASTFNCOMPILED))
  128. (TERPRI)
  129. (PRIN2 "GLRESULTTYPE: ")
  130. (PRINT (GET FN 'GLRESULTTYPE))
  131. (PRETTYPRINT (GETDDD FN))
  132. (RETURN FN)))
  133. % GLISP STRUCTURE EDITOR
  134. (DE GLEDS (STRNAME)
  135. (EDITV (GET STRNAME 'GLSTRUCTURE))
  136. STRNAME)
  137. % GLISP PROPERTY-LIST EDITOR
  138. (DE GLED (ATM) (EDITV (PROP ATM)))
  139. % GLISP FUNCTION EDITOR
  140. (DE GLEDF (FNNAME)
  141. (EDITV (GLGETD FNNAME))
  142. FNNAME)
  143. (DE KWOTE (X)
  144. (COND ((NUMBERP X) X)
  145. (T (LIST (QUOTE QUOTE) X))) )
  146. % INITIALIZE
  147. (SETQ GLBASICTYPES '(ATOM INTEGER REAL NUMBER STRING BOOLEAN
  148. ANYTHING))
  149. (SETQ GLTYPENAMES '(CONS LIST RECORD LISTOF ALIST ATOM
  150. OBJECT ATOMOBJECT LISTOBJECT))
  151. (SETQ GLLISPDIALECT 'PSL)
  152. (GLINIT)