[plt-scheme] Project Euler was Hash Table implementation

From: Phil Bewig (pbewig at gmail.com)
Date: Sat Aug 4 11:29:07 EDT 2007

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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070804/aacdfa5f/attachment.html>

Posted on the users mailing list.