Has something changed in how `error` works across modules? This code that I 
used last year without trouble seems to run into trouble now.

Here's the code all in one module:

#lang racket

(provide yield resume)

(define resumer #f)

(define (yield)
  (let/cc k
    (set! resumer k)
    (error 'yield "yielding computation")))

(define (resume)
  (resumer 'dummy))

(define (fact n)
  (if (= n 0)
      1
      (begin
        (when (= (remainder n 10) 0)
          (yield))
        (* n (fact (- n 1))))))

It results in the following (desired) interaction:

> (fact 10)
. . yield: yielding computation
> (resume)
3628800

But now I'm going to remove the definition of `fact` and put it in another 
module, saving the remainder as `yielder.rkt`:

#lang racket

(require "yielder.rkt")

(define (fact n)
  (if (= n 0)
      1
      (begin
        (when (= (remainder n 10) 0)
          (yield))
        (* n (fact (- n 1))))))

Now I get the following error. What should I be doing instead?

> (fact 10)
-- #(struct:exn:fail:contract "vector-ref: contract violation\n  expected: 
vector?\n  given: '((error 'yield \"yielding computation\") 
#<path:/Users/sk/Desktop/yielder.rkt> 10 4 113 37)\n  argument position: 
1st\n  other arguments...:\n   0" #<continuation-mark-set>)
  (errortrace-stack-item->srcloc . #(struct:srcloc 
#<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/stack-checkpoint.rkt> 168 0 6297 
203))
  (pick-first-defs . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/stack-checkpoint.rkt> 331 0 13000 
425))
  (get-exn-source-locs . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/stack-checkpoint.rkt> 585 0 23184 
391))
  (#f . #(struct:srcloc #<path:/Applications/Racket 
v7.8/collects/racket/contract/private/arrow-val-first.rkt> 486 18 20735 32))
  (error-display-handler/stacktrace . #(struct:srcloc 
#<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/debug.rkt> 362 2 15076 2612))
  (call-with-exception-handler . #(struct:srcloc 
#<path:/Applications/Racket v7.8/collects/racket/private/more-scheme.rkt> 
266 2 9251 256))
  (fact . #(struct:srcloc #<path:/Users/sk/Desktop/client.rkt> 5 0 40 139))
  (eval-one-top . #f)
  (call-with-exception-handler . #(struct:srcloc 
#<path:/Applications/Racket v7.8/collects/racket/private/more-scheme.rkt> 
266 2 9251 256))
  (loop . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/rep.rkt> 1210 24 50804 979))
  (call-with-break-parameterization . #(struct:srcloc 
#<path:/Applications/Racket v7.8/collects/racket/private/more-scheme.rkt> 
148 2 4909 517))
  (#f . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/rep.rkt> 1180 9 49153 5062))
  (#f . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/drracket/drracket/private/rep.rkt> 1493 15 64385 1548))
  (#f . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt> 435 6 19067 1056))
  (#f . #(struct:srcloc #<path:/Applications/Racket 
v7.8/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt> 486 32 21054 120))
  (call-with-break-parameterization . #(struct:srcloc 
#<path:/Applications/Racket v7.8/collects/racket/private/more-scheme.rkt> 
148 2 4909 517))
  (eventspace-handler-thread-proc . #(struct:srcloc 
#<path:/Applications/Racket 
v7.8/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt> 370 11 16515 690))
exception raised by error display handler: vector-ref: contract violation
  expected: vector?
  given: '((error 'yield "yielding computation") 
#<path:/Users/sk/Desktop/yielder.rkt> 10 4 113 37)
  argument position: 1st
  other arguments...:
   0; original exception raised: yield: yielding computation

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/6aa1ad8a-9f1a-4c11-8b75-5ed3ca09797dn%40googlegroups.com.

Reply via email to