[plt-scheme] Project Euler was Hash Table implementation

From: David Einstein (deinst at gmail.com)
Date: Sat Aug 4 17:33:41 EDT 2007

I can't wait.  I happened across your original srfi-40 by accident
after I had written sorrier versions of the extended functions.  I'd
be interested in playing with whatever you have, and I am sure that
there are others that would as well.

I was the one who said that srfi-40 streams are tricky.  The fact that
they do not always delay when you expect them to coupled with the fact
that mzscheme 370 will occasionally crash on windows when you run out
of memory (even with memory limited) has caused me a certain amount of
anguish.  It took me a while to get an intuitive sense of what was
going on, but now it pretty much makes sense.  I suspect that either
too many forces, or too few delays are the penalty one pays for lazy
programming in an eager language (the Wadler paper is on my to read
list.)

On 8/4/07, Phil Bewig <pbewig at gmail.com> wrote:
> I wrote SRFI-40, and am currently working on SRFI-41.  No promises when it
> will be ready, though.  It will require the module system of R6RS (also
> records, error, and case-lambda).  If you're interested in code, I could
> send you some.  The current version of the code has stream comprehensions
> and also pattern-matching on streams.  It also has bugs.  Someone earlier in
> the thread said that SRFI-40 is tricky, and doesn't always delay what they
> expected; yes, that happens to me, too.
>
> Phil
>
>
> On 8/3/07, David Einstein <deinst at gmail.com> wrote:
> >
> > I do not know if you know, but there are a lot of stream utilities in
> > the initial proposal of srfi-40, that were going to be moved to
> > srfi-41, but I assume that the author lost interest before that
> > happened.
> >
> > On 8/3/07, Mark Engelberg <mark.engelberg at gmail.com> wrote:
> > > On 8/3/07, Matthias Felleisen < matthias at ccs.neu.edu> wrote:
> > > > Mark, why don't you try two different things:
> > > >
> > > >   1. use the srfis for lazy streams and comprehension to rewrite the
> > > > solutions
> > > >
> > > >   2. use Lazy Scheme and hack together a comprehension macro.
> > > >
> > >
> > > Actually, I ended up getting satisfactory results by tweaking misc.ss
> > > from the swindle directory.  I chose to do this because I find
> > > swindle's comprehension syntax to be more comfortable than the srfi
> > > version (probably because of its similarity to math/Haskell).
> > >
> > > Here are the changes I made:
> > >
> > > ;;added for stream support
> > > (require (lib "40.ss" "srfi"))
> > >
> > > ;;added stream comprehension
> > > (defsubst* (stream-of expr clause ...)
> > >     (collect => (_ stream-null (stream-cons expr _)) clause ...))
> > >
> > > ;;added stream case to collect-iterator so streams can be used in
> generators
> > > (define* (collect-iterator seq)
> > >   (define (out-of-range r) (lambda (x) (<= r x)))
> > >   (cond
> > >    [(list? seq) (list seq cdr null? car)]
> > > ;;>   * stream: iterate over the stream's element;
> > > ;;> This is the new line I added.  Everything else is the same.
> > >    [(stream? seq) (list seq stream-cdr stream-null? stream-car)]
> > >    [(vector? seq) (list 0 add1 (out-of-range (vector-length seq))
> > >                         (lambda (i) (vector-ref seq i)))]
> > >    [(string? seq) (list 0 add1 (out-of-range (string-length seq))
> > >                         (lambda (i) (string-ref seq i)))]
> > >    [(integer? seq) (list 0 add1 (out-of-range seq) #f)]
> > >    [(procedure? seq)
> > >     (function->iterator seq)]
> > >    [(hash-table? seq)
> > >     (collect-iterator (lambda (yield)
> > >                         (hash-table-for-each
> > >                          seq (lambda (k v) (yield (cons k v))))))]
> > >    [else (list seq identity #f #f)]))
> > >
> > > I'm pretty happy with this.  The stream srfi library is pretty
> > > minimalist, of course.  I had to add a lot of useful functions like
> > > stream-takewhile and more.
> > >
> > > So yes, it's cool that Scheme (and in particular, Eli's code) can be
> > > easily extended in this way.  I would have been even happier if I
> > > didn't need to do it myself :) .
> > >
> > > --Mark
> > >
> > _________________________________________________
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
>


Posted on the users mailing list.