[racket] Sequence to Sequence

From: Deren Dohoda (deren.dohoda at gmail.com)
Date: Tue May 13 21:02:05 EDT 2014

Having a little problem getting something working with sequences.

What I'd like to do is have two sequences, call them seq-a and seq-b, which
are appended to each other like (in-sequences ...), except that when seq-a
runs out it passes information to seq-b in order for seq-b to know how to
start.

I thought that I could be sneaky and have the procedure returned by
sequence-generate* return a value even though the sequence had ostensibly
ended, but the docs aren't lying: it's an error to evaluate that procedure
after the sequence has ended.

Next I tried making the main sequence struct a subtype of another struct.
But this fails in surprising ways. Simple example to show the problem:
;;;;;;;;;;;;
(struct addable (x))

(struct adder addable (y)
  #:property prop:sequence
  (λ(p)
    (make-do-sequence
     (λ()
       (values (λ(pos) (adder-y pos))
               (λ(pos)
                 (adder (+ (adder-y pos) (adder-x pos))
                           (adder-x pos)))
               p
               #f #f #f)))))
;;;;;;;;;;;;
adder-x: unbound identifier in module in: adder-x

Unexpected. I thought this could be fixed by replacing
(adder-x pos)
with
(addable-x pos) since this works:

> (struct posn (x y))
> (struct 3d posn (z))
> (posn-x (3d 'x 'y 'z))
'x

This gives no errors but it breaks in unexpected ways.
;;;;
> (struct addable (x))
> (struct adder addable (y)
    #:property prop:sequence
    (λ(p)
      (make-do-sequence
       (λ()
         (values
           (λ(pos) (adder-y pos))
           (λ(pos)
             (adder (+ (adder-y pos)
                       (addable-x pos))
                    (addable-x pos)))
           p
           #f #f #f)))))
> (for ((t (adder 0 2))
        (i (in-range 10)))
    (printf "~a " t))
2 0 2 2 4 6 10 16 26 42

So there seems to be no hope that way.

Any chance there is a way to pass information between two subsequences so
that the overall iteration doesn't notice anything happening behind the
scenes? Is mutation the only hope?

Deren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140513/55c19133/attachment.html>

Posted on the users mailing list.