[plt-scheme] Scope question

From: Steven Kroeger (skroegs at gmail.com)
Date: Fri Dec 28 15:44:56 EST 2007

Hi,

I'm a scheme newb.

I've got a procedure that generates threads in a loop. I'd like be
able to access them out side that loop once they are generated. My
procedure seems to work fine, but I'm not sure how to get at them.

(define cp (list 1 2 3 4 5 6 7 8 9))

(define busy '())

(define (th-test lst)
  (let loop ((vals lst))
    (if (null? vals)
        '()
        (begin (append busy (cons (thread
                                   (lambda ()
                                     (let ((x (car vals)))
                                       (begin (sleep x)
                                              (display x)
                                              (newline)))))
                                  '()))
               (loop (cdr vals))))))

It generates the threads and outputs the numbers as its supposed to,
but my  list "busy" never appears to have any threads in it.

> (th-test cp)
()
1
2
3
4
5
6
7
8
9
>

What would I have to do to to be able to see the created threads
outside the creating loop?

Thanks,
Steve


Posted on the users mailing list.