char-macro.sl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. %
  2. % CHAR-MACRO.SL - Character constant macro
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 10 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % Edit by Cris Perdue, 1 Feb 1983 1355-PST
  12. % pk:char.red merged with the version in USEFUL. Some symbolic names
  13. % for characters removed (not needed, I hope).
  14. (dm Char (U) %. Character constant macro
  15. (DoChar (cadr U)))
  16. % Table driven char macro expander
  17. (de DoChar (u)
  18. (cond
  19. ((idp u) (or
  20. (get u 'CharConst)
  21. ((lambda (n) (cond ((lessp n 128) n))) (id2int u))
  22. (CharError u)))
  23. ((pairp u) % Here's the real change -- let users add "functions"
  24. ((lambda (fn)
  25. (cond
  26. (fn (apply fn (list (dochar (cadr u)))))
  27. (t (CharError u))))
  28. (cond ((idp (car u)) (get (car u) 'char-prefix-function)))))
  29. ((and (fixp u) (geq u 0) (leq u 9)) (plus u #\!0))
  30. (t (CharError u))))
  31. (deflist
  32. `((lower ,(function (lambda(x) (lor x 2#100000))))
  33. (quote ,(function (lambda(x) x)))
  34. (control ,(function (lambda(x) (land x 2#11111))))
  35. (cntrl ,(function (lambda(x) (land x 2#11111))))
  36. (meta ,(function (lambda(x) (lor x 2#10000000)))))
  37. 'char-prefix-function)
  38. (de CharError (u)
  39. (ErrorPrintF "*** Unknown character constant: %r" u)
  40. 0)
  41. (DefList '((NULL 0)
  42. (BELL 7)
  43. (BACKSPACE 8)
  44. (TAB 8#11)
  45. (LF 8#12)
  46. % (RETURN 8#12) % RETURN is LF: it's end-of-line. Out! /csp
  47. (EOL 8#12)
  48. (FF 8#14)
  49. (CR 8#15)
  50. (ESC 27)
  51. (ESCAPE 27)
  52. (BLANK 32)
  53. (SPACE 32)
  54. (RUB 8#177)
  55. (RUBOUT 8#177)
  56. (DEL 8#177)
  57. (DELETE 8#177)
  58. ) 'CharConst)