[r6rs-discuss] [Formal] last-element behavior of for-each
| Date: Fri, 6 Oct 2006 18:56:27 -0400 (EDT)
| From: AndrevanTonder <andre_at_het.brown.edu>
| ...
| Sorry, what I meant to write (but didn't) was the following:
|
| (define (traverse-tree tree)
| (for-each (lambda (node)
| (if (list? node)
| (traverse-tree node)
| (display node)))
| tree))
|
| (traverse-tree '((1 2 3) (3 4 5) (((((6))))) (7)))
|
| ===> 1234567
|
| (traverse-tree '(((((((((((((((((1))))))))))))))))))
|
| ===> 1
|
| Here, for example, the sequence of examples
|
| (1), ((1)), (((1))), ...
|
| will all require the same space to run under the proposed r6rs
| semantics. For e.g. a balanced binary tree, the maximum amount of
| memory used during traversal will not be affected, but the average
| amount over the time of execution will be about half with
| r6rs-semantics (only the leftmost branch would take the maximum
| memory, and after that the memory use just gets less and less).
To minimize memory usage, wouldn't balanced binary trees put child
nodes in the CAR and CDR? In that case, FOR-EACH can't be used.
Received on Fri Oct 06 2006 - 22:38:45 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC