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

Cannot subtract number from iterators #1920

Open
evantypanski opened this issue Nov 8, 2024 · 1 comment · May be fixed by #1921
Open

Cannot subtract number from iterators #1920

evantypanski opened this issue Nov 8, 2024 · 1 comment · May be fixed by #1921

Comments

@evantypanski
Copy link
Contributor

In the "Changing input" section in the docs, there is a reference that seems like it implies you can subtract some number from an iterator:

For random access, you’d typically get the current position through input(), subtract from it the desired number of bytes you want to back, and then use set_input to establish that new position.

So I tried self.set_input(self.input() - 1); and got:

[error] /Users/etyp/src/spicy-redis/analyzer/resp.spicy:25:28-25:43: unsupported operator: <const iterator<stream>> - <uint<64>

which seems exactly like the docs were telling me to do, so I got a little upset.

I don't see any iterator - uint ish operators anywhere - was this ever supported, or intended to be supported? I'd hardly call it "typical" if it's not supported :) so either that should be added or the docs changed.

But, I don't have the history of this to know which one it should be. I'd just prefer if you could subtract the number of bytes, that seems nice.

evantypanski added a commit to evantypanski/spicy-redis that referenced this issue Nov 8, 2024
I must've missed the point of this section before, oops. I'd prefer not
to have the `start` var, but it's necessary because I can't subtract a
number from the iterator right now:

zeek/spicy#1920
@rsmmr
Copy link
Member

rsmmr commented Nov 11, 2024

Hmm ... I think the docs are odd/wrong here. We do have a + operator for these iterators but indeed no -. Iirc, that's on purpose because going back is often not going to work; there's a good chance that the data will have been discarded already. It's not always wrong, and in fact we'd also catch it on access and throw an InvalidIterator, but not providing - in the first place makes it harder to get surprised later at runtime.

So with that in mind, I don't know what the docs are trying to say there. :-) We should probably replace that with some version of "use input() to remember a position, then set_input() to go back there".

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 a pull request may close this issue.

2 participants