gltest 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. % GLTEST.PSL.2 22 OCTOBER 82
  2. % GLISP TEST FUNCTIONS, PSL VERSION. GSN 22 OCTOBER 82
  3. (DE GIVE-RAISE
  4. (:COMPANY)
  5. (FOR EACH ELECTRICIAN WHO IS NOT A TRAINEE
  6. DO (SALARY _+(IF SENIORITY > 1
  7. THEN 2.5
  8. ELSE 1.5))
  9. (PRINT (THE NAME OF THE ELECTRICIAN))
  10. (PRINT (THE PRETTYFORM OF DATE-HIRED))
  11. (PRINT MONTHLY-SALARY) ))
  12. (DE CURRENTDATE ()
  13. (A DATE WITH YEAR = 1981 !, MONTH = 11 !, DAY = 30))
  14. (PUTPROP 'CURRENTDATE 'GLRESULTTYPE 'DATE)
  15. (GLISPOBJECTS
  16. (EMPLOYEE
  17. (LIST (NAME STRING)
  18. (DATE-HIRED (A DATE))
  19. (SALARY REAL)
  20. (JOBTITLE ATOM)
  21. (TRAINEE BOOLEAN))
  22. PROP ((SENIORITY ((THE YEAR OF (CURRENTDATE))
  23. -
  24. (THE YEAR OF DATE-HIRED)))
  25. (MONTHLY-SALARY (SALARY * 174)))
  26. ADJ ((HIGH-PAID (MONTHLY-SALARY > 2000)))
  27. ISA ((TRAINEE (TRAINEE))
  28. (GREENHORN (TRAINEE AND SENIORITY < 2)))
  29. MSG ((YOURE-FIRED (SALARY _ 0))) )
  30. (DATE
  31. (LIST (MONTH INTEGER)
  32. (DAY INTEGER)
  33. (YEAR INTEGER))
  34. PROP ((MONTHNAME ((NTH
  35. ' (JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
  36. OCTOBER NOVEMBER DECEMBER)
  37. MONTH)))
  38. (PRETTYFORM ((LIST DAY MONTHNAME YEAR)))
  39. (SHORTYEAR (YEAR - 1900))) )
  40. (COMPANY
  41. (ATOM (PROPLIST (PRESIDENT (AN EMPLOYEE))
  42. (EMPLOYEES (LISTOF EMPLOYEE) )))
  43. PROP ((ELECTRICIANS ((THOSE EMPLOYEES WITH JOBTITLE='ELECTRICIAN)))) )
  44. )
  45. (PUTPROP 'COMPANY1 'PRESIDENT
  46. '("OSCAR THE GROUCH" (3 15 1907) 88.0 PRESIDENT NIL) )
  47. (PUTPROP 'COMPANY1 'EMPLOYEES
  48. '(("COOKIE MONSTER" (7 21 1947) 12.5 ELECTRICIAN NIL)
  49. ("BETTY LOU" (5 14 1980) 9.0 ELECTRICIAN NIL)
  50. ("GROVER" (6 13 1978) 3.0 ELECTRICIAN T)) )
  51. (GLISPOBJECTS
  52. (VECTOR
  53. (LIST (X INTEGER)
  54. (Y INTEGER))
  55. PROP ((MAGNITUDE ((SQRT X^2 + Y^2))))
  56. ADJ ((ZERO (X IS ZERO AND Y IS ZERO))
  57. (NORMALIZED (MAGNITUDE = 1.0)))
  58. MSG ((+ VECTORPLUS OPEN T)
  59. (- VECTORDIFF OPEN T)
  60. (* VECTORTIMES OPEN T)
  61. (/ VECTORQUOTIENT OPEN T)
  62. (_+ VECTORMOVE OPEN T)
  63. (PRIN1 ((PRIN1 "(")
  64. (PRIN1 X)
  65. (PRIN1 ",")
  66. (PRIN1 Y)
  67. (PRIN1 ")")))
  68. (PRINT ((_ SELF PRIN1)
  69. (TERPRI))) ) )
  70. (GRAPHICSOBJECT
  71. (LIST (SHAPE ATOM)
  72. (START VECTOR)
  73. (SIZE VECTOR))
  74. PROP ((LEFT (START:X))
  75. (BOTTOM (START:Y))
  76. (RIGHT (LEFT+WIDTH))
  77. (TOP (BOTTOM+HEIGHT))
  78. (WIDTH (SIZE:X))
  79. (HEIGHT (SIZE:Y))
  80. (CENTER (START+SIZE/2))
  81. (AREA (WIDTH*HEIGHT)))
  82. MSG ((DRAW ((APPLY (GET SHAPE 'DRAWFN)
  83. (LIST SELF
  84. (QUOTE PAINT)))))
  85. (ERASE ((APPLY (GET SHAPE 'DRAWFN)
  86. (LIST SELF
  87. (QUOTE ERASE)))))
  88. (MOVE GRAPHICSOBJECTMOVE OPEN T)) )
  89. (MOVINGGRAPHICSOBJECT
  90. (LIST (TRANSPARENT GRAPHICSOBJECT)
  91. (VELOCITY VECTOR))
  92. MSG ((ACCELERATE MGO-ACCELERATE OPEN T)
  93. (STEP ((_ SELF MOVE VELOCITY)))) )
  94. )
  95. (DE VECTORPLUS
  96. (V1!,V2:VECTOR)
  97. (A VECTOR WITH X = V1:X + V2:X !, Y = V1:Y + V2:Y))
  98. (DE VECTORDIFF
  99. (V1!,V2:VECTOR)
  100. (A VECTOR WITH X = V1:X - V2:X !, Y = V1:Y - V2:Y))
  101. (DE VECTORTIMES
  102. (V:VECTOR N:NUMBER)
  103. (A VECTOR WITH X = X*N !, Y = Y*N))
  104. (DE VECTORQUOTIENT
  105. (V:VECTOR N:NUMBER)
  106. (A VECTOR WITH X = X/N !, Y = Y/N))
  107. (DE VECTORMOVE
  108. (V!,DELTA:VECTOR)
  109. (V:X _+
  110. DELTA:X)
  111. (V:Y _+
  112. DELTA:Y))
  113. (DE GRAPHICSOBJECTMOVE
  114. (SELF:GRAPHICSOBJECT DELTA:VECTOR)
  115. (_ SELF ERASE)
  116. (START _+
  117. DELTA)
  118. (_ SELF DRAW))
  119. (DE MGO-ACCELERATE
  120. (SELF: MOVINGGRAPHICSOBJECT ACCELERATION: VECTOR)
  121. VELOCITY _+
  122. ACCELERATION)
  123. (DE TESTFN1 ()
  124. (PROG (MGO N)
  125. (MGO _(A MOVINGGRAPHICSOBJECT WITH SHAPE =(QUOTE
  126. RECTANGLE)
  127. !, SIZE =(A VECTOR WITH X = 4 !, Y = 3)
  128. !, VELOCITY =(A VECTOR WITH X = 3 !, Y = 4)))
  129. (N _ 0)
  130. (WHILE (N_+1)
  131. <100 (_ MGO STEP))
  132. (_(THE START OF MGO)
  133. PRINT)))
  134. (DE TESTFN2
  135. (:GRAPHICSOBJECT)
  136. (LIST SHAPE
  137. START
  138. SIZE
  139. LEFT
  140. BOTTOM
  141. RIGHT
  142. TOP
  143. WIDTH
  144. HEIGHT
  145. CENTER
  146. AREA
  147. ))
  148. (DE DRAWRECT
  149. (SELF:GRAPHICSOBJECT DSPOP:ATOM)
  150. (PROG (OLDDS)
  151. (OLDDS _(CURRENTDISPLAYSTREAM DSPS))
  152. (DSPOPERATION DSPOP)
  153. (MOVETO LEFT BOTTOM)
  154. (DRAWTO LEFT TOP)
  155. (DRAWTO RIGHT TOP)
  156. (DRAWTO RIGHT BOTTOM)
  157. (DRAWTO LEFT BOTTOM)
  158. (CURRENTDISPLAYSTREAM OLDDS))))
  159. )
  160. (GLISPOBJECTS
  161. (LISPTREE
  162. (CONS (CAR LISPTREE)
  163. (CDR LISPTREE))
  164. PROP ((LEFTSON ((IF SELF IS ATOMIC THEN NIL ELSE CAR)))
  165. (RIGHTSON ((IF SELF IS ATOMIC THEN NIL ELSE CDR))))
  166. ADJ ((EMPTY (~SELF))) )
  167. (PREORDERSEARCHRECORD
  168. (CONS (NODE LISPTREE)
  169. (PREVIOUSNODES (LISTOF LISPTREE)))
  170. MSG ((NEXT ((PROG (TMP)
  171. (IF TMP_NODE:LEFTSON THEN
  172. (IF NODE:RIGHTSON THEN PREVIOUSNODES+_NODE)
  173. NODE_TMP ELSE TMP-_PREVIOUSNODES NODE_TMP:RIGHTSON))))) )
  174. )
  175. (DE TP
  176. (:LISPTREE)
  177. (PROG (PSR)
  178. (PSR _(A PREORDERSEARCHRECORD WITH NODE =(THE LISPTREE)))
  179. (WHILE NODE (IF NODE IS ATOMIC (PRINT NODE))
  180. (_ PSR NEXT))))
  181. (GLISPOBJECTS
  182. (ARITHMETICOPERATOR
  183. (SELF ATOM)
  184. PROP ((PRECEDENCE OPERATORPRECEDENCEFN RESULT INTEGER)
  185. (PRINTFORM ((GET SELF (QUOTE PRINTFORM))
  186. OR SELF)))
  187. MSG ((PRIN1 ((PRIN1 THE PRINTFORM)))) )
  188. (INTEGERMOD7
  189. (SELF INTEGER)
  190. PROP ((MODULUS (7))
  191. (INVERSE ((IF SELF IS ZERO THEN 0 ELSE (MODULUS - SELF)))))
  192. ADJ ((EVEN ((ZEROP (LOGAND SELF 1))))
  193. (ODD (NOT EVEN)))
  194. ISA ((PRIME PRIMETESTFN))
  195. MSG ((+ IMOD7PLUS OPEN T RESULT INTEGERMOD7)
  196. (_ IMOD7STORE OPEN T RESULT INTEGERMOD7)) )
  197. )
  198. (DE IMOD7STORE
  199. (LHS:INTEGERMOD7 RHS:INTEGER)
  200. (LHS:SELF __(IREMAINDER RHS MODULUS)))
  201. (DE IMOD7PLUS
  202. (X!,Y:INTEGERMOD7)
  203. (IREMAINDER (X:SELF + Y:SELF)
  204. X:MODULUS))
  205. (DE SA
  206. (:ARITHMETICOPERATOR)
  207. (IF PRECEDENCE>5 (_ (THE ARITHMETICOPERATOR)
  208. PRIN1)))
  209. (DE SB
  210. (X:INTEGERMOD7)
  211. (PROG (Y)
  212. (LIST MODULUS INVERSE)
  213. (IF X IS ODD OR X IS EVEN OR X IS A PRIME THEN (Y _ 5)
  214. (X _ 12)
  215. (X _+5))))
  216. (GLISPOBJECTS
  217. (CIRCLE (LIST (START VECTOR) (RADIUS REAL))
  218. PROP ((PI (3.1415926))
  219. (DIAMETER (RADIUS*2))
  220. (CIRCUMFERENCE (PI*DIAMETER))
  221. (AREA (PI*RADIUS^2)) ) ))
  222. % EXAMPLE OF ASSIGNMENT TO COMPUTED PROPERTY
  223. (DE GROWCIRCLE (C:CIRCLE)
  224. (C:AREA_+100)
  225. (PRINT RADIUS) )
  226. (SETQ MYCIRCLE '((0 0) 0.0))
  227. % EXAMPLE OF ELIMINATION OF COMPILE-TIME CONSTANTS
  228. (DE SQUASH ()
  229. (IF 1>3 THEN 'AMAZING
  230. ELSEIF 6<2 THEN 'INCREDIBLE
  231. ELSEIF 2 + 2 = 4 THEN 'OKAY
  232. ELSE 'JEEZ))