utilities.scm 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. (define-module (trs utilities)
  2. #:use-module (ice-9 match)
  3. #:use-module (srfi srfi-11)
  4. #:export (step-body atomic? iterate qqify))
  5. (define (any/map f l)
  6. (if (null? l)
  7. (values #f '())
  8. (let-values (((p1 v1) (f (car l)))
  9. ((p2 v2) (any/map f (cdr l))))
  10. (values (or p1 p2)
  11. (cons v1 v2)))))
  12. (define (step-body step s)
  13. (let-values (((progress tail) (any/map step (cdr s))))
  14. (values progress (cons (car s) tail))))
  15. (define (iterate step s)
  16. (let-values (((progress s^) (step s)))
  17. (if progress
  18. (iterate step s^)
  19. s^)))
  20. (define (atomic? s)
  21. (or (symbol? s) (boolean? s) (number? s)))
  22. (define (qqify xs)
  23. (define (rec x)
  24. (cond ((symbol? x)
  25. (list 'unquote x))
  26. ((or (boolean? x)
  27. (number? x))
  28. x)
  29. (else
  30. `(,(car x) . ,(map rec (cdr x))))))
  31. (list 'quasiquote (rec xs)))