Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple values in stream-cons + use stream-cons in stream operations #4554

Merged
merged 3 commits into from Feb 14, 2023

Conversation

sorawee
Copy link
Collaborator

@sorawee sorawee commented Jan 27, 2023

This PR supports multiple values in stream-cons. As a result, stream, stream*, and for/stream also support multiple values.

stream and stream* patterns are also adjusted to allow matching against multiple-valued elements.

We then switch stream operations which need to handle multiple values to use stream-cons, both simplifying the implementation and making these operations properly memoizing at the same time. The switch also fixes the non-constant space problem raised in https://racket.discourse.group/t/stream-filter-not-in-constant-space/1643.

@racket-discourse-github-bot

This pull request has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/stream-filter-not-in-constant-space/1643/19

@sorawee sorawee marked this pull request as ready for review February 6, 2023 12:12
The stream protocol and stream operations support multiple values.
However, stream-cons does not. The consequences are:

- Multiple values in streams can't be easily used by users.
- Internal stream operations are implemented in a convoluted way
  to support multiple values, which is error-prone.

  There are many mistakes in the current implementation,
  including but not limited to:

  - Incorrect laziness
  - Linear time memory consumption on operations that should take
    constant time

  See
  https://racket.discourse.group/t/stream-filter-not-in-constant-space/1643
  for the discussion.

This PR adds a support of multiple values to stream-cons.
We then utilize this stream-cons on the stream operations
to fix the issues mentioned above.

Note that there are still known deficiencies in the current
implementation. These deficiencies are not degradation, however, because
SRFI-41 also has them. Furthermore, the data definition of streams in
Racket makes it difficult to fix these deficiencies without a large
refactoring, so I would like to postpone fixing these issues
to the next PRs.

See https://srfi-email.schemers.org/srfi-41/msg/21844204/
for the discussion.
@mflatt mflatt merged commit ba2e0f3 into racket:master Feb 14, 2023
@sorawee sorawee deleted the multival-stream-cons branch February 14, 2023 21:16
@racket-discourse-github-bot

This pull request has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/stream-filter-not-in-constant-space/1643/21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants