Questions about the specification and implementation
Bradley Lucier 25 Jan 2024 19:32 UTC
Spec:
1. The spec says:
=======================
end
The argument in this place must be a exact positive integer, i.e.
it must satisfy the predicates exact?, integer? and positive?. This
indicates the index directly before which traversal will stop —
processing will occur until the the index of the vector is end. It is
the closed right side of a range.
=======================
I think you want "end" to be nonnegative. In the procedure definitions,
you can have start=0 and end=0 and return empty vectors
2. vector-map!: In the implementation all vectors do not need to be the
same length. But does vec1 have to be the shortest? Or are the rest of
the elements of vec1 simply unchanged? That's what the implementation
seems to do.
3. The spec says:
=======================
(vector-partition pred? vec) -> vector and integer
A vector the same size as vec is newly allocated and filled with
all the elements of vec that satisfy pred? in their original order
followed by all the elements that do not satisfy pred?, also in their
original order.
Two values are returned, the newly allocated vector and the index
of the leftmost element that does not satisfy pred?.
=======================
What if all elements satisfy pred?
Also, the sample implementation returns the number of elements that
satisfy pred?. So if they all satisfy pred? then the second returned
value is just the length of the vector.
I suggest it be reworded so that
Two values are returned, the newly allocated vector and the number of
elements that satisfy pred?.
Implementation:
1. Every place (integer? i) is used, shouldI suggest it be (and (exact?
i) (integer? i)) or (exact-integer? i) (if r7rs).