trs.scm 832 B

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