I read docs, played with examples, and (re-)discovered, that the position of #:break or #:final in the iterator clauses (of course) matters. So this, e.g. (for/fold ([j-found? #f] [pos 0]) ([ch ch-stream] [ch-idx (in-naturals 1)] #:break j-found?)
solves my problem. On Tuesday, December 13, 2022 at 8:40:06 AM UTC+1 [email protected] wrote: > I haven't asked any questions here for a long time, so hope it's OK to > cross-post here: > > > https://racket.discourse.group/ > > (which I just discovered.) > > > Cheers, > > Tim > > On Monday, December 12, 2022 at 10:28:22 PM UTC+1 [email protected] wrote: > >> hi, I'm trying to do something slightly harder than what the attached >> example tries to do, but this example suffices to show that I, evidently, >> am missing something about how for/fold and/or #:break work together. >> >> (I have used both before, but have gotten out of practice with racket of >> late and am stuck longer on this than seems reasonable.) >> >> I expect both tests to pass, but both fail (the "j" for jewel in "xxjxx") >> is seen but not "found", as it were. >> >> I'd be grateful for a bug fix and/or explanation. >> >> Cheers, >> >> Tim Hanson >> >> -------- >> >> #lang racket >> >> (require rackunit) >> >> (define (port->char-stream aport) >> (printf "(port->char-stream aport)~n") >> (define (process-next-ch-iter) >> (let ([ch (read-char aport)]) >> (printf "p->cs ch: ~a~n" ch) >> (if (eof-object? ch) >> empty-stream >> (stream-cons >> ch >> (process-next-ch-iter))))) >> >> (process-next-ch-iter)) >> >> >> (let ([my-port >> (open-input-string "xxjxx")]) >> >> (let ([ch-stream (port->char-stream my-port)]) >> (let-values ([(pos-found? pos) >> (for/fold ([j-found? #f] >> [pos 0]) >> (#:break j-found? >> ;#:final j-found? >> [ch ch-stream] >> [ch-idx (in-naturals 1)]) >> (begin >> (printf "ch: ~a~n" ch) >> (printf "ch-idx: ~a~n" ch-idx) >> (printf "(eq? ch #\\j): ~a~n" (eq? ch #\j)) >> (values >> (eq? ch #\j) >> ch-idx)))]) >> >> (check-equal? pos-found? #t) >> >> (check-equal? pos 3) >> >> (close-input-port my-port)))) >> >> >> -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com. Beyond the Racket Users Google Group, Racket Discussions take place on Discourse ( https://racket.discourse.group/ ) and Discord ( https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes place on the Racket Slack https://racket.slack.com/ ( sign up at https://racket-slack.herokuapp.com/ ), and IRC #racket https://kiwiirc.com/nextclient/irc.libera.chat/#racket --- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/2fa4a1a8-32ad-4c03-9194-e4b856fd4ae3n%40googlegroups.com.

