[plt-scheme] Backwards compatibility?

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Wed May 30 01:37:40 EDT 2007

To batch process my directory of Scheme files, I took Matthew's "hard
way" code, and added the following two lines:
 (define files (find-files (λ(x)#t)))
 (map (λ(f) (convert-to-text f (build-path "Converted" f))) files)

Two problems:
1.  Some of the file conversions work, but sometimes I get the error message:
read-bytes: bad WXME stream; does not start with "WXME"

2.  I'm losing all the images, comment boxes, and other special items
in the conversion process (they are replaced by an annotation).
Ideally, I'd like to retain everything except the test case boxes
which are no longer supported.

Thanks,

Mark

On 5/25/07, Robby Findler <robby at cs.uchicago.edu> wrote:
> The script below takes the test case boxes and just concatenates their
> contents. If you wanted to do something fancier (like convert them to
> uses to the testing teachpack, say) you should be able to adjust the
> code below to make that happen, too.
>
> Let us know if you get stuck trying to do that (if that interests you).
>
> (Thanks, Matthew!)
>
> Robby
>
> On 5/24/07, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > At Thu, 24 May 2007 19:26:17 -0700, "Mark Engelberg" wrote:
> > > I have 90+ files with heavy use of the test case boxes.  A script
> > > would certainly be helpful...
> >
> > This *should* have worked in v370:
> >
> >  (require (lib "wxme.ss" "wxme")
> >           (lib "port.ss"))
> >
> >  (define (convert-to-text src dest)
> >    (call-with-output-file dest
> >      (lambda (out)
> >       (call-with-input-file src
> >         (lambda (in)
> >          (copy-port (wxme-port->text-port in) out))))))
> >
> > But it looks like "wmxe" test-case-box reading wasn't tested for text
> > conversion. I fixed it in SVN.
> >
> > Meanwhile, the hard way works in v370:
> >
> >   (require (lib "wxme.ss" "wxme")
> >            (lib "test-case.ss" "wxme")
> >            (lib "class.ss")
> >            (lib "port.ss"))
> >
> >   (define (concat port)
> >     (if port
> >         (let loop ([accum null])
> >           (let ([s (read-bytes 4096 port)])
> >             (if (eof-object? s)
> >                 (apply bytes-append (reverse accum))
> >                 (loop (cons s accum)))))
> >         #""))
> >
> >   (define (convert-to-text src dest)
> >     (call-with-output-file dest
> >       (lambda (out)
> >         (call-with-input-file src
> >           (lambda (in)
> >             (let ([in (wxme-port->port in)])
> >               (let loop ()
> >                 (let ([v (read-char-or-special in)])
> >                   (unless (eof-object? v)
> >                     (cond
> >                      [(v . is-a? . test-case%)
> >                       (display (bytes-append
> >                                 (concat (send v get-comment))
> >                                 (concat (send v get-test))
> >                                 (concat (send v get-expected))
> >                                 (concat (send v get-predicate))
> >                                 (concat (send v get-should-raise))
> >                                 (concat (send v get-error-message)))
> >                                out)]
> >                      [else (display v out)])
> >                     (loop))))))))))
> >
> >
> > Matthew
> >
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>

Posted on the users mailing list.