Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

doc: explain lookahead behavior in sequence-generate#5338

Open
NoahStoryM wants to merge 1 commit into
racket:masterracket/racket:masterfrom
NoahStoryM:doc-seq-genNoahStoryM/racket:doc-seq-genCopy head branch name to clipboard
Open

doc: explain lookahead behavior in sequence-generate#5338
NoahStoryM wants to merge 1 commit into
racket:masterracket/racket:masterfrom
NoahStoryM:doc-seq-genNoahStoryM/racket:doc-seq-genCopy head branch name to clipboard

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.