Eduardo Cavazos wrote:
I put an implementation of the queues up at (dharmalab misc queue):
http://github.com/dharmatech/dharmalab/raw/master/misc/queue.sls
I added a few utility procedures to the library:
queue-for-each-with-index
queue-tabulate
queue-car
queue-cdr
With queue-for-each-with-index, the trail drawing code goes from:
(let ((trail-length (queue-length trail)))
(let loop ((i 0)
(trail trail))
(if (not (queue-empty? trail))
(let ((fraction (/ i trail-length)))
(queue-remove
trail
(lambda (point trail)
(circle (vector-ref point 0)
(vector-ref point 1)
(max 5.0 (* fraction 14.0)))
(loop (+ i 1) trail)))))
to:
(let ((trail-length (queue-length trail)))
(queue-for-each-with-index
(lambda (i point)
(let ((fraction (/ i trail-length)))
(circle point (max 5.0 (* fraction 14.0)))))
trail))
(I'm also using a simpler 'circle' procedure there).
With queue-tabulate, the trail initialization goes from:
(define initial-trail-length 100)
(define trail (new-queue))
(do ((i 0 (+ i 1)))
((>= i initial-trail-length))
(set! trail (queue-insert trail (vector 0.0 0.0))))
to:
(define trail (queue-tabulate (lambda (x) (vector 0.0 0.0)) 100))
Ed