As part of something I'm working on I want to convert a stream of values 
into a stream of pairs of values, e.g.

  1 2 3 4

  (1 2) (3 4)

The following seems to work fine:

(define (pairwise-stream astream)
  (if (stream-empty? astream)
        (stream-first astream)
        (stream-first (stream-rest astream)))
        (stream-rest (stream-rest astream))))))

but I'd like my 2nd or 3rd test to detect a problem with a stream of odd 
length and haven't figured out how yet. Here's my attempt (lengths 0 and 2 
work fine, length 1 shows a contract violation, but my test doesn't detect 

  (pairwise-stream empty-stream))
 (stream->list empty-stream))

; hmmm, how to detect this correctly?
; exn:fail:contract?
; (stream-first
;  (pairwise-stream (stream-cons 1 empty-stream))))

 (stream->list (pairwise-stream (stream-cons 1 (stream-cons 2 
 (stream->list (stream-cons (cons 1 2) empty-stream)))

I'd be grateful for advice.



You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to