Skip to content

doc: explain lookahead behavior in sequence-generate - #5338

Open
NoahStoryM wants to merge 1 commit into
racket:masterfrom
NoahStoryM:doc-seq-gen
Open

NoahStoryM wants to merge 1 commit into
racket:masterfrom
NoahStoryM:doc-seq-gen

Conversation

@NoahStoryM

Copy link
Copy Markdown
Contributor

Checklist

  • Bugfix
  • Feature
  • tests included
  • documentation

Description of change

Problem

The current documentation for sequence-generate doesn't explain that the more? function may consume elements from the underlying sequence to determine if more elements are available, caching them for subsequent get calls. This can cause unexpected behavior when mixing sequence-generate usage with direct sequence access.

Example

Welcome to Racket v8.17 [cs].
> (define inport (open-input-bytes (bytes 1 2 3 4 5 6 7 8 9 10)))
> (define-values (more? get) (sequence-generate inport))
> (more?)
#t
> (get)
1
> (more?)
#t
> (sequence-ref inport 0)
3
> (get)
2
> (more?)
#t
> (for/first ([i inport]) i)
5
> (get)
4
> (define-values (more2? get2) (sequence-generate inport))
> (more?)
#t
> (list (get2) (get))
'(7 6)
> (more2?)
#t
> (more2?)
#t
> (list (get) (get2))
'(9 8)
> (more?)
#t
> (more2?)
#f
> (more?)
#t
> (more2?)
#f

@shhyou shhyou added the documentation Issues related to README and documentation (typos, rewording, new docs, etc) label Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Issues related to README and documentation (typos, rewording, new docs, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants