I just created a package that helps creating a stream of multiple values a
couple of weeks ago. You might find it useful:
https://docs.racket-lang.org/stream-values/

On Sat, May 2, 2020 at 3:38 PM Yury Bulka <[email protected]>
wrote:

> (sorry for the typos - obviously, it should be racket/stream)
>
> --
> Yury Bulka
> https://mamot.fr/@setthemfree
> #NotOnFacebook
>
>
>
> Yury Bulka <[email protected]> writes:
>
> > Hello everyone,
> >
> > I have a question about creating a steam that yields multiple values on
> > each iteration. Given something like:
> >
> > (require racket/strema)
> >
> > (define my-stream (for/stream ([i (in-range 1 10)])
> >                     (values "hi" i)))
> >
> > When I'm trying to:
> >
> > (let-values ([(a b) (stream-ref my-stream 0)])
> >     (printf "~v: ~v" a b))
> >
> > I'm getting:
> >
> > ; result arity mismatch;
> > ;  expected number of values not received
> > ;   expected: 1
> > ;   received: 2
> > ;   values...:
> > ;    "hi"
> > ;    2
> > ; Context:
> > ;
> /nix/store/z4mpvw1p6whq454lmjshbdr6472sdbr3-racket-7.6/share/racket/collects/racket/repl.rkt:11:26
> >
> > Similarly:
> >
> > (for ([(a b) my-stream])
> >     (printf "~v: ~v" a b))
> >
> > leads to:
> >
> > ; result arity mismatch;
> > ;  expected number of values not received
> > ;   expected: 1
> > ;   received: 2
> > ;   values...:
> > ;    "hi"
> > ;    1
> > ; Context:
> > ;  tcp-accepted:1:1 for-loop
> > ;  top-level:1:1 [running body]
> > ;
> /nix/store/z4mpvw1p6whq454lmjshbdr6472sdbr3-racket-7.6/share/racket/collects/racket/repl.rkt:11:26
> >
> > Documentation on stream-ref specifically mentions that it can have
> > multiple values:
> >
> https://docs.racket-lang.org/reference/streams.html?q=stream-ref#%28def._%28%28lib._racket%2Fstream..rkt%29._stream-ref%29%29
> >
> > What am I doing wrong here?
> >
> > P.S. The context is that I'm trying to create a function that would
> > return results from an API as a stream that can be iterated with the for
> > family of forms, and would yield multiple values per iteration.
> >
> > --
> > Yury Bulka
> > https://mamot.fr/@setthemfree
> > #NotOnFacebook
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/87ees2nerz.fsf%40privacyrequired.com
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegvfgFo1SPQq6Dh7ncrgCpHDWFBArCSf99WHkOcY5Jjv1A%40mail.gmail.com.

Reply via email to