From: <sp...@sc...> - 2006-10-11 16:28:01
|
Bárður Árantsson wrote: > Denis Bueno wrote: >> I've been building a compiler front-end (lex -> parse -> IR) in OCaml >> and frequently have to make use of List.iter2 --- and I find it >> annoying that there is no counterpart for arrays. Hasn't anyone needed >> this before? >> >> It's not hard to write. In fact, even better, it's written [1]. I'll >> spruce it up if it doesn't meet the ExtLib standards. >> >> -Denis >> >> [1] >> (** Like {!List.iter2}, but for arrays. >> >> @raise Invalid_argument if the length of [a1] does not equal the >> length of [a2]. *) >> let iter2 f a1 a2 = >> if Array.length a1 <> Array.length a2 >> then raise (Invalid_argument "Array.iter2"); >> >> for i = 0 to Array.length a1 do > ^^^^^^^^^^^^^^^ > > That's missing a -1, isn't it? (I never use for loops :)) > >> f a1.(i) a2.(i); >> done;; >> > > Apart from that this looks fine, and I think it's relevant. (I haven't > ever needed it, but more uniformity among the standard data structure > modules is good as far as I'm concerned). > > I'll add it to CVS if there are no objections. > Added to CVS w/the above fix and a more explicit documentation comment. Cheers, -- Bardur Arantsson <bar...@TH...> If you don't believe in Jesus, then just try to move your little finger. Iasson @ http://kuro5hin.org |