From: Brian B. <bri...@gm...> - 2005-10-25 12:38:36
|
On 25/10/05, Amit Dubey <ami...@gm...> wrote: > On 10/25/05, Brian Brunswick <bri...@gm...> wrote: > > On 25/10/05, Amit Dubey <ami...@gm...> wrote: > > > I see the problem. I think there may be another problem if first < > -(length > > > s). Is it best to fix these bugs, or change the documentation? > > > > > > > My opinion would be fix the problem, since we already have String.sub > > to throw exceptions. > > > OK, but this raises two questions: > (1) what would be the behaviour when (length s) <=3D i < 2 * (length s)= . > Similar to when 0 > i > -1 * (length s) (i.e. substact length s)? > (2) what about when i < -2 * (length s) or i >=3D 2 * (length s)? > (Where i =3D first/last) > > I'll continue inflicting my opinion on the list:-) I would say no, it shouldn't wrap again. I think its useful behaviour to have endpoints that silently truncate, and not useful to have ones that wrap around. The wrapping at zero is useful because it gives a reference relative to the end of the string, and not because it wraps. I'll wager that people practically never have code that generates some positive and some negative offsets by arithmetic for the same argument= . So we do: let i =3D if i>=3D0 then min i len else max 0 (len - i) for both first and last, and then if last<first "" else .... > What about meeting halfway and adding a function like truncate pair: > > let truncate_pair xl yl =3D > let rec aux accu_x accu_y xl yl =3D match xl,yl with > | x::xs, y::ys -> aux (x::accu_x) (y::accu_y) xs ys > | _, _ -> (rev accu_x, rev accu_y) > in > aux [] [] xl yl > > -Amit > Yes, we want that as well. I'd still be tempted to add most of the Haskell list ones too, simply on the basis that people might be familiar with them. -- Bri...@it...____Wit____Disclaimer____!Shortsig_rules! |