[racket] trouble debugging - please help
On 1/9/11 6:50 PM, Lewis Brown wrote:
> Hello Racketeers,
>
> I'm getting back into racket/plt-sheme after years away from it (and programming in general). I'm warming back up by updating Jacob Matthews' Quasistring module to Racket. I may have bit off a bit too much as I've run out of ideas for fixing a bug.
>
> I've updated function names and calling conventions. Due to the bug, I've simplified this to a top level program (which may have been a mistake, though I wouldn't know why).
>
> Using both the debugger and the Macro Stepper have failed me. I've gotten feedback that makes me think that I've got a contract violation, but he error happens very early, before the expansion of the macro call. I'm rather mystified by both the bug and the proper way to debug it.
>
> The error is:
>
> string-length: expects argument of type<string>; given #"\0"
The value #"\0" is not a string, but a bytes. (Bytes are a somewhat new
kind of value in Racket, so they may not have been around when you were
hacking PLT Scheme.)
So in addition to the problem Robby pointed out, there is a type
mismatch here:
> ; fresh-port : ip (box num) -> ip
> ; makes a new port that just forwards to the original port
> (define (monitored-port p box)
> (make-input-port 'monitored
> (lambda (s)
> (let ((len (a s)))
> (let loop ((idx 0))
> (cond
> [(and (< idx len) (char-ready? p))
> (let ((c (read-char p)))
> (if (eof-object? c)
> (if (= idx 0) eof idx)
> (begin
> (string-set! s idx c)
> (set-box! box (+ (unbox box) (width c)))
> (loop (add1 idx)))))]
> [else idx]))))
> #f
> void))
The lambda bound variable s is going to be bound to bytes, but
string-set! expects a mutable string.
I'm guessing that unbound `a' used to be `string-length', which would
give you the error you reported.
David