syntax-rules.scm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Mike Sperber
  3. (define-usual-macro 'syntax-rules
  4. (make-explicit-renaming-transformer/4
  5. (lambda (exp name? r c)
  6. (let ((%quote (r 'quote))
  7. (%cons (r 'cons))
  8. (%make-explicit-renaming-transformer/4 (r 'make-explicit-renaming-transformer/4)))
  9. (if (pair? (cdr exp))
  10. (let ((subkeywords (cadr exp))
  11. (rules (cddr exp)))
  12. (if (and (list? subkeywords)
  13. (every name? subkeywords))
  14. (receive (code inserted)
  15. (process-rules exp name? r c)
  16. (if code
  17. `(,%cons (,%make-explicit-renaming-transformer/4 ,code)
  18. (,%quote ,inserted)) ; should this be code-quote?
  19. exp))
  20. exp))
  21. exp))))
  22. '(cons lambda code-quote make-explicit-renaming-transformer/4 apply-rules))
  23. (define (process-rules exp name? r c)
  24. (let ((%quote (r 'quote))
  25. (%code-quote (r 'code-quote))
  26. (%cons (r 'cons))
  27. (%lambda (r 'lambda))
  28. (%apply-rules (r 'apply-rules))
  29. (%input (r 'input))
  30. (%name? (r 'name?))
  31. (%rename (r 'rename))
  32. (%compare (r 'compare)))
  33. (receive (compiled inserted)
  34. (compile-rules exp
  35. (lambda (n)
  36. (and (name? n)
  37. (c n (r '...)))))
  38. (if compiled
  39. (values `(,%lambda (,%input ,%name? ,%rename ,%compare)
  40. (,%apply-rules ,%input
  41. (,%code-quote ,compiled)
  42. ,%name?
  43. ,%rename
  44. ,%compare))
  45. inserted)
  46. (values #f #f)))))