(use tree-rewrite) (define rule-toc `( ( (M section $level $title) => (li $title) ) )) (define test `(M body (page-title) (section 2 "Abstract") (p "This is the abstract") (p "This is the second paragraph.") (section 2 "Results") (p "This is the next section") (section 2 "Discussion") (p "This is the final section. ") (p "This is a paragraph. ") (p "This is another paragraph. ") )) (print ((rewrite-fold-tree-partial rule-toc cons '()) test ))