On 12/4/2019 11:03 AM, Dominik Pantůček wrote
> looking at vector-length[1] documentation, it returns
> (exact-nonnegative-integer?). However, as far as I can tell, it returns
> (fixnum?). Also for subsequent contracts in the vector's documentation
> all indices are assumed to be (exact-nonnegative-integer?) but usually
> it is impossible on given platform to use anything larger than (fixnum?)
> in reality
You are correct that (exact-nonnegative-integer?) doesn't limit values
to fixnum range, but the point of using it is more to exclude negative
values than to allow super large positive ones.
This question - or something substantially similar - has come up
before. Your question is about contracts - which can be used from plain
Racket - but it is noteworthy that typed/Racket provides types for
positive, negative, nonpositive, and nonnegative fixnums - but there are
no built-in tests for any of these, so a suitable contract or type
declaration has to be synthesized using multiple tests.
> For example on 64bit platforms the (fixnum?) could store numbers from (-
> (expt 2 62)) to (sub1 (expt 2 62)). Vector slots cannot be smaller than
> 64bits (machine-dependent pointers) which means 8 bytes = 3 bits of
> address. Given 64bit (VERY theoretical) size of the address space, this
> leaves the possibility of storing a single vector with (expt 2 61)
> elements into the memory.
>
> If I did not overlook anything, the contracts could be safely changed to
> (fixnum?).
It would be more correct to use (and/c fixnum? (or/c zero? positive?))
to explicitly limit the value.
> And yes, I found this issue while cleaning up my futures-sort[2] package
> discussed a few months ago here. If I assume
> (exact-nonnegative-integer?), I need to manually check for (fixnum?).
> Even though it - given the information above - does not really make much
> sense.
>
>
> Should I open a PR?
I don't remember how the previous discussions went. I'm not sure
anything ever really was resolved.
YMMV,
George