[plt-scheme] Check-error

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Apr 15 10:22:42 EDT 2010

Thomas and Matthias,

Thanks for your answers. The following works too:

(define coroutine4
  (letrec
      ((local-state
        (lambda (first-resume-value)
          (toggle 0)
          (toggle 1)
          (let ((old-toggle toggle))
            (set! toggle (λ (ignore) (error "expired coroutine")))
            (old-toggle 2))))
       (toggle
        (lambda (return/resume-value)
          (call-with-current-continuation
           (lambda (cc)
             (let ((old-state local-state))
               (set! local-state cc)
               (old-state return/resume-value)))))))
    (λ (x) (toggle x))))

(check-expect (coroutine4 'ignored) 0)
(check-expect (coroutine4 'ignored) 1)
(check-expect (coroutine4 'ignored) 2) 
(check-error  (coroutine4 'ignored) "expired coroutine")

Jos

-----Original Message-----
From: Matthias Felleisen [mailto:matthias at ccs.neu.edu] 
Sent: 15 April 2010 15:33
To: Jos Koot
Cc: plt-scheme at list.cs.brown.edu
Subject: Re: [plt-scheme] Check-error


It's not check-expect/check-error that's at fault here. It is the widely
spread belief that coroutines are plain old functions in Scheme.

Try this program instead:

> #lang scheme
> (require test-engine/scheme-tests)
>
> (define (run coroutine val)
>   (let ([x (coroutine val)])
>     (if (exn:fail? x)
>         (raise x)
>         x)))
>
> (define coroutine4
>   (letrec
>       ((local-state
>         (lambda (first-resume-value)
>           (toggle 0)
>           (toggle 1)
>           (toggle 2)
>           (toggle (make-exn:fail "expired coroutine" (current-
> continuation-marks)))))
>        (toggle
>         (lambda (return/resume-value)
>           (call-with-current-continuation
>            (lambda (cc)
>              (let ((old-state local-state))
>                (set! local-state cc)
>                (old-state return/resume-value)))))))
>     toggle))
>
> (check-expect (run coroutine4 'ignored) 0) (check-expect (run 
> coroutine4 'ignored) 1) (check-expect (run coroutine4 'ignored) 2) 
> (check-error  (run coroutine4 'ignored) "expired coroutine")
>
> (test)




On Apr 15, 2010, at 5:04 AM, Jos Koot wrote:

> Is it me or check-error who is wrong?
> Jos
>
> #lang scheme
> (require test-engine/scheme-tests)
>
> (define coroutine4
>  (letrec
>   ((local-state
>     (lambda (first-resume-value)
>      (toggle 0)
>      (toggle 1)
>      (toggle 2)
>      (error "expired coroutine")))
>    (toggle
>     (lambda (return/resume-value)
>      (call-with-current-continuation
>       (lambda (cc)
>        (let ((old-state local-state))
>         (set! local-state cc)
>         (old-state return/resume-value)))))))
>   toggle))
>
> (check-expect (coroutine4 'ignored) 0) (check-expect (coroutine4 
> 'ignored) 1) (check-expect (coroutine4 'ignored) 2) (check-error 
> (coroutine4 'ignored) "expired coroutine")
>
> (test)
>
> Welcome to DrScheme, version 4.2.5.7-svn10apr2010 [3m].
> Language: scheme [custom]; memory limit: 2000 MB.
> bug: collects\test-engine\scheme-tests.ss:157:0: expired coroutine Ran 
> 4 checks.
> 1 of the 4 checks failed.
>
>         check-expect encountered the following error instead of the 
> expected value, 0.
>    :: expired coroutine
>  At line 21 column 0
> >
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme





Posted on the users mailing list.