streams in racket

后端 未结 4 1359
情话喂你
情话喂你 2021-01-05 06:44

Can anyone help me better understand how to write a stream?

I understand that a stream is an infinite sequence of values and the way I have learned programming them

4条回答
  •  盖世英雄少女心
    2021-01-05 07:13

    It looks like you were asking how to build your own custom streams with thunks, which others have already answered. Just in case, it's worth noting that Racket has a stream library built-in and most Racketeers would use that for streams.

    Here's an example:

    #lang racket
    (require racket/stream)
    (define reds (stream-cons "red" reds))
    (define red-blues (stream-add-between reds "blue"))
    
    ;; show ten of them
    (for ([i 10] [e (in-stream red-blues)])
      (displayln e))
    

提交回复
热议问题