<div dir="ltr">Agreed. I purposely returned (stream #f) because the original poster expected #f.<br><br>By the way, it is easier to write (stream 'a 'b) than (stream-cons 'a (stream-cons 'b stream-null)).<br>
<br><div class="gmail_quote">On Wed, Oct 8, 2008 at 2:40 PM, Jos Koot <span dir="ltr"><<a href="mailto:jos.koot@telefonica.net">jos.koot@telefonica.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
SRFI 41 in PLT is almost an identical copy of the reference implementation. I did not yet know it was adopted in PLT, but I am glad to see it there. It does not include procedure stream-member. This procedure is given as an example in the document. Clearly the example is incorrect.<br>
<br>
I suggest:<br>
<br>
#lang scheme<br>
(require "streams.ss")<br>
<br>
(define (stream-member eql? obj strm)<br>
(let/ec ec<div class="Ih2E3d"><br>
(stream-let loop ((strm strm))<br>
(cond<br></div>
((stream-null? strm) strm)<div class="Ih2E3d"><br>
((eql? obj (stream-car strm)) strm)<br></div>
(else (loop (stream-cdr strm)))))))<div class="Ih2E3d"><br>
<br>
(define s1 (stream-cons 'a (stream-cons 'b stream-null)))<br>
<br></div>
(stream->list (stream-member eq? 'a s1)) ; --> (a b)<br>
(stream->list (stream-member eq? 'b s1)) ; --> (b)<br>
(stream->list (stream-member eq? 'c s1)) ; --> ( ) ; signals that the element is not found.<br>
<br>
The solution given by Phil goes wrong on<br>
(stream-member eqv? #f (make-stream #f)) and<br>
(stream-member eqv? #f stream-null)<br>
because it returns (stream #f) in both cases. It does not show whether the returned value, i.e (stream #f), is the last cdr of the stream or a signal that the element has not been found. Since the result cannot be empty if the element is found it is better to return null-stream in this case.<br>
<br>
Jos<br>
----- Original Message ----- From: "Jens Axel Soegaard" <<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>><div class="Ih2E3d"><br>
To: <<a href="mailto:nowgate@yahoo.com" target="_blank">nowgate@yahoo.com</a>><br>
Cc: <<a href="mailto:plt-scheme@list.cs.brown.edu" target="_blank">plt-scheme@list.cs.brown.edu</a>><br></div>
Sent: Wednesday, October 08, 2008 8:42 PM<div class="Ih2E3d"><br>
Subject: Re: [plt-scheme] SRFI 41<br>
<br>
<br>
</div><div><div></div><div class="Wj3C7c"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
michael rice skrev:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
There's a stream-member function given in SRFI 41 that doesn't seem to work as expected.<br>
<br>
=================<br>
<br>
(require srfi/41)<br>
<br>
(define s1 (stream-cons 'a (stream-cons 'b stream-null)))<br>
<br>
(define-stream (stream-member eql? obj strm)<br>
(stream-let loop ((strm strm))<br>
(cond ((stream-null? strm) #f)<br>
((eql? obj (stream-car strm)) strm)<br>
(else (loop (stream-cdr strm))))))<br>
<br>
===================<br>
<br>
Welcome to DrScheme, version 4.1 [3m].<br>
Language: Swindle; memory limit: 128 megabytes.<br>
> (stream-member equal? 'c s1)<br>
#<stream><br>
><br>
<br>
===================<br>
<br>
Shouldn't the answer be #f?<br>
<br>
Michael<br>
<br>
<br>
</blockquote>
<br>
The documentation for srfi 41 says:<br>
<br>
(stream-let tag ((var expr) ...) body)<br>
<br>
... stream-let evaluates the expressions in its body in an environment containing<br>
the newly-bound variables, returning the value of the last expression evaluated,<br>
which must yield a stream.<br>
<br>
Since #f is not a stream, the behaviour is undefined.<br>
<br>
Note that evaluating (stream-car (stream-member equal? 'c s1)) gives #f.<br>
<br>
But... The example rises a few questions:<br>
<br>
Is PLT using the reference implementation of srfi 41?<br>
<br>
If not, it would be a worth chaning the behaviour of stream-let to<br>
match the reference implementation.<br>
<br>
Was it intentional that this behaviour is undefined?<br>
<br>
If it is unintentional, maybe an error message would be better<br>
than matching the behaviour of the reference implementation?<br>
<br>
<br>
<br>
-- <br>
Jens Axel Søgaard<br>
<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>