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.

Right now, I'm just trying to play with for/fold and some control operators to 
get a feel for how a solution should work. Using racket/control, I've managed 
to get this working snippet:

(define result-stream
  (let ()
    (define (stream-loop element continue)
      (stream-cons element
                   (call-with-values
                    (thunk (call/prompt continue))
                    stream-loop)))
    (call-with-values
     (thunk
      (prompt
       (for/fold ()
                 ([i (in-naturals)])
         (let/cc continue
           (abort i continue)))))
     stream-loop)))

This will create an infinite, lazy stream bound to ‘result-stream’ containing 
all the natural numbers. It works, which is cool, but it also seems pretty 
overcomplicated.

Is there a better approach to this sort of thing that I'm missing? My intuition 
for working with control operators isn't the best, so I wouldn't be surprised 
if I was overlooking something.

Thanks,
Alexis

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