(use tree-rewrite) (include "arith.scm") (define (list->seq lst) (if (null? lst) '(seq-empty) `(seq ,(car lst) ,(list->seq (cdr lst))))) ;; Extract the nth element from a sequence of elements ;; nth(0,(t,_)) -> somestr(t) ;; nth(n,(_,l)) when n > 0 -> nth(n - 1,l) (define rule-seq `( ( (M nth (zero) (seq $h $t)) => $h ) ( (M nth (succ $n) (seq $h $t)) => (M nth $n $t) ) ,@rule-arith )) (define term `(M nth ,(make-numeral 2) ,(list->seq '(a b c d)))) (pp term) (print (reduce term rule-seq))