[plt-scheme] how do you use stream-partition?

From: Jos Koot (jos.koot at telefonica.net)
Date: Sat Mar 15 09:49:49 EDT 2008

dhermans source code:

(define (stream-partition pred stream)
   (stream-delay
     (if (stream-null? stream)
         (values stream-null stream-null)
         (let ([x (stream-car stream)])
           (let-values ([(in out) (stream-partition pred (stream-cdr 
stream))])
             (if (pred x)
                 (values (stream-cons x in) out)
                 (values in (stream-cons x out))))))))

does indeed return one value, the stream produced by stream-delay.
I dont know whether or not this is intentional, but it can't be right.
The stream-delayed expression does not return a stream it returns two 
streams.
Jos Koot


----- Original Message ----- 
From: "Doug Orleans" <dougorleans at gmail.com>
To: "PLT-Scheme Mailing List" <plt-scheme at list.cs.brown.edu>
Sent: Saturday, March 15, 2008 12:40 AM
Subject: [plt-scheme] how do you use stream-partition?


>I want to use stream-partition from dherman's stream.plt, which uses
> SRFI-40 streams, but I can't figure out what to do with the result:
>
>  Welcome to MzScheme v3.99.0.10 [3m], Copyright (c) 2004-2008 PLT Scheme 
> Inc.
>  Reading .mzschemerc...
>  > (require srfi/40)
>  > (define (integers-starting-from n)
>      (stream-cons n (integers-starting-from (+ n 1))))
>  > (require (planet "stream.ss" ("dherman" "stream.plt" 1 0)))
>  > (stream->list (stream-take 5 (integers-starting-from 0)))
>  (0 1 2 3 4)
>  > (define-values (evens odds)
>      (stream-partition even? (integers-starting-from 0)))
>  define-values: context (defining "evens", ...) expected 2 values, 
> received 1 value: #<stream>
>
>   === context ===
>  /usr/local/plt/collects/scheme/private/misc.ss:63:7
>
>  > (stream? (stream-partition even? (integers-starting-from 0)))
>  #t
>  > (stream-pair? (stream-partition even? (integers-starting-from 0)))
>  context (lexical binding) expected 2 values, received 1 value: #<stream>
>
>   === context ===
>  /usr/local/plt/collects/srfi/40/stream.ss:82:2: stream-pair?
>  /usr/local/plt/collects/scheme/private/misc.ss:63:7
>
> Neither module provides a stream-force, and all the stream functions
> expect a delayed single value, so what can I do with this stream?
>
> --dougorleans at gmail.com
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.