On 20/05/2015 04:24, Alexis King wrote:

I'm trying to implement a for/stream loop using for/fold/derived that will 
return a lazy stream, as would be expected. One way to do this is by using 
delimited control, which is what I'm currently trying. If there's an easier 
way, let me know, but I'd still like to figure this out as a pedagogical 
exercise.

If I understand correctly what you are trying to do, the simplest solution seems to be a generator.

=================================
#lang racket

(require racket/generator)

(define result-stream
  (in-generator
   (for ([i (in-naturals 10)])
     (yield i))))

(for ([n result-stream])
  (printf "~s\n" n))
=================================

This example is a bit pointless because result-stream could just as well be replaced by (in-naturals 10), but I hope it is clear how this could be generalized to a meaningful application.

I use this a lot, to the point of considering defining something like for/sequence to have nicer syntax for this.

Konrad.

--
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