0

I'm trying to create a stream version of map that takes a variable number of streams as argument. The problem I have is that I want it to handle streams of various size, and that it will terminate when one of them is empty. If i was dealing with lists instead of streams I would just do like this:

if (member? '() args)
   '()

But since this materializes the whole stream each time, I guess it defeats the purpose? I can't seem to think of any other way to check if one of the streams are empty than to to it like this.

user16655
  • 1,901
  • 6
  • 36
  • 60
  • 1
    What implementation are you using? – Bob Apr 21 '15 at 19:13
  • 1
    You might enjoy [SRFI-41](https://programmingpraxis.files.wordpress.com/2013/01/streams.pdf), which describes a stream version of map, as well as many other things. – user448810 Apr 21 '15 at 19:23

1 Answers1

0

The main difference between stream version and ordinary is that you need to use stream-cons, etc. You can still have a list of streams instead of a list of lists so your little check can be written:

(if (memq stream-null args)
    stream-null
    (stream-cons <??> <??>))

It does not materialize the stream since args is a list of streams. Thus every stream gets checked for being the empty stream and that's a very simple eq? test (hench I changed it to memq)

Sylwester
  • 47,942
  • 4
  • 47
  • 79