Hi there,
I was surprised by this behavior, but it's entirely possible there's a good
reason for it. Bringing it up to understand what that might be. In using
(in-set) or (in-mutable-set) in a for loop, it seems that if the loop is
removing and adding elements to the set it is iterating over, the sequence
might terminate even if the set is non-empty.

Example:
(let ([my-set (mutable-set 0)])
  (for ([i (in-mutable-set my-set)])
    (printf "~a\n" i)
    (when (= i 0)
      (set-remove! my-set i)
      (set-add! my-set 1))))

Outputs:
>
0

Instead of the expected:
>
0
1

Changing the code to remove the (set-remove! my-set i) line:

(let ([my-set (mutable-set 0)])
  (for ([i (in-mutable-set my-set)])
    (printf "~a\n" i)
    (when (= i 0)
      (set-add! my-set 1))))

...  produces the expected output.

On a related note, I'm not exactly clear on what a sequence is that isn't a
stream or a list or some other concrete type. Sequences appear to be an
abstract type, and yet (in-set) is an instance of it (unlike e.g. (in-list)
which is a stream..) so it must not be abstract. Perhaps this is the key to
my confusion here?

Thanks,
-Sid

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