trs.scm 849 B

123456789101112131415161718192021222324252627282930
  1. ;(define-module (trs trs)
  2. ; #:use-module (trs utilities)
  3. ; #:use-module (ice-9 match)
  4. ; #:export (define-trs))
  5. (library (trs)
  6. (export define-trs)
  7. (import (chezscheme) (utilities) (match))
  8. (define-syntax define-trs
  9. (lambda (x)
  10. (syntax-case x (==>)
  11. ((define-trs <name>
  12. (==> <pattern> <result>) ...)
  13. (let ((patterns (map qqify (syntax->list #'(<pattern> ...))))
  14. (results (map qqify (syntax->list #'(<result> ...)))))
  15. #`(begin
  16. (define (step s)
  17. (match s
  18. #,@(map (lambda (p r)
  19. #`(#,p (values #t #,r)))
  20. patterns results)
  21. (else (if (atomic? s)
  22. (values #f s)
  23. (step-body step s)))))
  24. (define (<name> s)
  25. (iterate step s))))))))
  26. )