[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] scheduling and coroutines
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] scheduling and coroutines |
Date: |
Sun, 27 Feb 2011 13:07:44 +0100 |
User-agent: |
Mutt/1.4.2.3i |
On Sat, Feb 26, 2011 at 01:50:10PM +0100, Tomtom wrote:
> Now, how should I change the code in the routine ?
>
> Buf if I change the routine by adding one argument to call/cc
>
> (define (routine cont)
> (let loop ((n 10))
> (set! cont (call/cc cont n))
> (if (> n 0)
> (loop (- n 1)))))
>
> Error: bad argument count - received 2 but expected 1: #<procedure
> (call-with-current-continuation proc1295)>
>
> Well, I guess it's normal too, as call/cc is taking only one argument - so how
> am I supposed to pass this second argument ?
You don't pass it to call/cc. Call/cc merely *captures* the continuation
at that point and passes it to its lambda argument. What you want is
to also pass the value to the continuation of the scheduler:
(define (routine cont)
(let loop ((n 10))
(display n)(newline)
(set! cont (call/cc (lambda (k) (cont k n))))
(if (> n 0)
(loop (- n 1)))))
HTH,
Peter
--
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
is especially attractive, not only because it can be economically
and scientifically rewarding, but also because it can be an aesthetic
experience much like composing poetry or music."
-- Donald Knuth