[plt-scheme] Re: Using PLT Scheme libs elsewhere?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun May 20 20:33:46 EDT 2007

Probably the easiest thing is to use call-with-input-file, but you
might also want to look into custodians.

Robby

On 5/20/07, SpinyNorman <jmcaxolotl at gmail.com> wrote:
> So when opening a port, you need to save a reference to it, rather
> than just invoking the "open" function to provide a "port" argument
> for a calling function.  That is, rather than
>
>     (foo (open-input-file "bar"))
>
> you would need to do
>
>     (define iport (open-input-file "bar"))
>     (foo iport)
>     (close iport)
>
> Unless, of course, foo *knows* it is supposed to close the port when
> it is finished.
>
> Right?  Or is there another way to approach this that would allow the
> composition of these functions?
>
>
> On May 20, 7:39 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > On May 20, 2007, at 7:34 PM, SpinyNorman wrote:
> >
> > > Is the (UNLESS ...) vs. (IF (NOT...)) issue purely stylistic, or for
> > > enhancing clarity for the poor schmo who has to read my code a month
> > > from now, or would you expect a speed difference?
> >
> > Yes, it's for him. And he might be you. Promised. Try it out.
> >
> > ;; ---
> >
> > You want to close ports because some OSes don't support too many
> > open ports at once. It's just something to get used to.
> >
> > -- Matthias
> >
> >
> >
> >
> >
> > > On May 18, 7:37 am, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > >> Thanks. I'd use UNLESS instead of (if (not blah) one-armed-if).
> >
> > >> On May 18, 2007, at 4:18 AM, Jens Axel Søgaard wrote:
> >
> > >>> Hi,
> >
> > >>> SpinyNorman wrote:
> >
> > >>>> Share?  I'm flattered.  Here it is, and my only claim at this
> > >>>> point is
> > >>>> that hey, it works.  Algorithmic insights are more than welcome.
> >
> > >>>> (require (lib "md5.ss"))
> >
> > >>> This md5.ss implements MD5 in Scheme. The Java MD5 is probably
> > >>> implemented in C.
> > >>> So if you switch to a C-based MD5 implementation, you'll get a
> > >>> speedup. Here is
> > >>> what to do:
> >
> > >>> (require (planet "digest.ss" ("soegaard" "digest.plt" 1 2)))
> > >>> (require mzscheme)
> >
> > >>> (define test-string (make-string 10000))
> >
> > >>> (define (md-file-chunks port chunk-size)
> > >>>  (let loop ()
> > >>>    (begin
> > >>>      (display (md5 (read-bytes chunk-size port)))
> > >>>      (newline))
> > >>>    (if (not (eof-object? (peek-byte port)))
> > >>>    (loop))))
> >
> > >>> (md-file-chunks (open-input-string test-string) 1024)
> >
> > >>> See
> > >>> <http://planet.plt-scheme.org/display.ss?
> > >>> package=digest.plt&owner=soegaard>
> > >>> for documentation.
> >
> > >>> This was tested on Windows, but ought to work elsewhere too.
> > >>> You'll need a relatively new version of PLT Scheme, for
> > >>> example 369.100.
> >
> > >>> It wasn't obvious whether you put the md-file-chunks in a module or
> > >>> whether you are using the top-level. If you are using the top-level,
> > >>> the line
> >
> > >>>    (require mzscheme)
> >
> > >>> makes sure primitive operations are inlined.
> >
> > >>> I'd love to hear your new timings.
> >
> > >>> PS: Remember to close file ports after use.
> >
> > >>> --
> > >>> Jens Axel Søgaard
> >
> > >>> _________________________________________________
> > >>>  For list-related administrative tasks:
> > >>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > >> _________________________________________________
> > >>   For list-related administrative tasks:
> > >>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > > _________________________________________________
> > >   For list-related administrative tasks:
> > >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > _________________________________________________
> >   For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme"
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>

Posted on the users mailing list.