[plt-scheme] SRFI 41

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Wed Oct 8 14:42:01 EDT 2008

michael rice skrev:
> There's a stream-member function given in SRFI 41 that doesn't seem to 
> work as expected.
> =================
> (require srfi/41)
> (define s1 (stream-cons 'a (stream-cons 'b stream-null)))
> (define-stream (stream-member eql? obj strm)
>   (stream-let loop ((strm strm))
>     (cond ((stream-null? strm) #f)
>           ((eql? obj (stream-car strm)) strm)
>           (else (loop (stream-cdr strm))))))
> ===================
> Welcome to DrScheme, version 4.1 [3m].
> Language: Swindle; memory limit: 128 megabytes.
> > (stream-member equal? 'c s1)
> #<stream>
> >
> ===================
> Shouldn't the answer be #f?
> Michael

The documentation for srfi 41 says:

(stream-let tag ((var expr) ...) body)

... stream-let evaluates the expressions in its body in an environment 
the newly-bound variables, returning the value of the last expression 
which must yield a stream.

Since #f is not a stream, the behaviour is undefined.

Note that evaluating (stream-car (stream-member equal? 'c s1)) gives #f.

But... The example rises a few questions:

  Is PLT using the reference implementation of srfi 41?

  If not, it would be a worth chaning the behaviour of stream-let to
  match the reference implementation.

  Was it intentional that this behaviour is undefined?

   If it is unintentional, maybe an error message would be better
   than matching the behaviour of the reference implementation?

Jens Axel Søgaard

Posted on the users mailing list.