/usr/lib/s9fes/tree-copy.scm is in scheme9 2010.11.13-2.
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 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2010
; See the LICENSE file of the S9fES package for terms of use
;
; (tree-copy pair) ==> pair
; (tree-copy pair 'with-atoms) ==> pair
;
; Create an exact copy of an arbitrary non-cyclic cons structure.
; When a second argument is passed to TREE-COPY and that argument
; is not #F, then TREE-COPY will copy modifyable leaves of the tree,
; too.
;
; Example: (tree-copy '(((a . b) (c . d)) (e . f)))
; ==> (((a . b) (c . d)) (e . f))
;
; (let* ((tree (list (string #\A)))
; (tree2 (tree-copy tree))
; (tree3 (tree-copy tree 'with-atoms)))
; (string-set! (car tree) 0 #\X)
; (list tree2 tree3)) ==> (("X") ("A"))
(load-from-library "subvector.scm")
(load-from-library "type-case.scm")
(define (tree-copy tree . with-atoms)
(let ((with-atoms (and (not (null? with-atoms))
(car with-atoms))))
(let copy ((tree tree))
(cond ((pair? tree)
(cons (copy (car tree))
(copy (cdr tree))))
(with-atoms
(type-case tree
((vector) (vector-copy tree))
((string) (string-copy tree))
(else tree)))
(else
tree)))))
|