/usr/share/gauche-0.9/0.9.1/lib/util/tree.scm is in gauche 0.9.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ;;;
;;; tree.scm - walk tree
;;;
;;; Written by Shiro Kawai (shiro@acm.org) 2001
;;; Public Domain.. I guess lots of Scheme programmers have already
;;; written similar code.
;;;
(define-module util.tree
(use srfi-1)
(export tree-fold tree-walk tree-fold-bf tree-walk-bf)
)
(select-module util.tree)
(define (tree-walk tree proc leaf? walker)
(define (rec node)
(walker (lambda (n) (if (leaf? n) (proc n) (rec n))) node))
(if (leaf? tree) (proc tree) (rec tree)))
(define (tree-fold tree proc knil leaf? folder)
(define (rec node r)
(folder (lambda (n knil) (if (leaf? n) (proc n knil) (rec n knil)))
r node))
(if (leaf? tree) (proc tree knil) (rec tree knil)))
(define (tree-walk-bf tree proc leaf? walker)
(define (rec node)
(let* ((branches '()))
(walker (lambda (n) (if (leaf? n) (proc n) (push! branches n))) node)
(for-each rec (reverse branches))))
(if (leaf? tree) (proc tree) (rec tree)))
(define (tree-fold-bf tree proc knil leaf? folder)
(define (rec node r)
(let* ((branches '())
(r (folder (lambda (n knil)
(if (leaf? n)
(proc n knil)
(begin (push! branches n) knil)))
r node)))
(fold rec r (reverse branches))))
(if (leaf? tree) (proc tree knil) (rec tree knil)))
|