<div dir="ltr">The definition of stream-member given in the text of SRFI-41 is incorrect. The problem is inconsistent typing: one branch of the cond returns #f, which is not a stream, while another branch of the cond returns strm, which is a stream. Here is a definition of stream-member? which returns either #t or #f; it uses normal define, not stream-define, and normal let, not stream-let:<br>
<br>(define (stream-member? eql? obj strm)<br> (let loop ((strm strm))<br> (cond ((stream-null? strm) #f)<br> ((eql? (stream-car strm) obj) #t)<br> (else (loop (stream-cdr strm))))))<br><br>Given that, (stream-member? equal? 'c (stream 'a 'b)) evaluates to #f, as you expect.<br>
<br>Another definition of stream-member, the one that was intended by SRFI-41, is:<br><br>(define-stream (stream-member eql? obj strm)<br> (stream-let loop ((strm strm))<br> (cond ((stream-null? strm) (stream #f))<br>
((eql? obj (stream-car strm)) strm)<br> (else (loop (stream-cdr strm))))))<br><br>That definition type-checks because both branches of the cond evaluate to a stream. Given that definition, (stream-car (stream-member equal? 'c (stream 'a 'b))) evaluates to #f, and (stream-car (stream-member equal? 'a (stream 'a 'b))) evaluates to a.<br>
<br>Note that stream-member is not defined in SRFI-41; it is just an example in the text (worse, it is an incorrect example in the text). If PLT includes stream-member in its version of SRFI-41, that is an extension of SRFI-41. If PLT wants to extend SRFI-41, it would be better to define the library in such a way that it is loaded by (require srfi/41-extended-by-PLT) or some such mechanism. By taking the liberty of extending the base definition of SRFI-41, PLT confuses users and makes code written using its extended version of SRFI-41 non-portable to other Scheme systems that adhere to SRFI-41 as it is written.<br>
<br>I will forward this note to the SRFI-41 mailing list. <br><br>Phil<br>
<br><div class="gmail_quote">On Wed, Oct 8, 2008 at 1:11 PM, michael rice <span dir="ltr"><<a href="mailto:nowgate@yahoo.com" target="_blank">nowgate@yahoo.com</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;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
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></td></tr></tbody></table><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></div><br></div>