[containers-users] Vector.slice_seq

peter frey pjfrey at sympatico.ca
Thu Mar 1 19:40:34 GMT 2018


Pasted from source code:

utop # Vector.slice_seq (Vector.of_list [0;1;2;3;4]) 1 3 |> CCList.of_seq;;
- : int list = [1; 2; 3]
─( 14:27:21 )─< command 41 >─────────────────────────────────────{ 
counter: 0 }─

Same thing with length 5:

utop # Vector.slice_seq (Vector.of_list [0;1;2;3;4]) 1 5 |> CCList.of_seq;;
Exception: Assert_failure ("src/core/CCVector.ml", 656, 4).

Source:

let slice_seq v start len =
   assert (start >= 0 && len >= 0);
   fun k ->
     assert (start+len < v.size);                 should be <= v.size ???
     for i = start to start+len-1 do
       let x = Array.unsafe_get v.vec i in
       k x
     done

with length 5 the slice is not a proper slice; but as with strings, a 
string is a (not proper) sub_string of itself; so a slice of the whole 
vector would also be expected to be a slice?

Peter




More information about the Containers-users mailing list