From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA16355; Fri, 4 May 2001 16:50:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA16203 for ; Fri, 4 May 2001 16:50:11 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f44EoAD00771 for ; Fri, 4 May 2001 16:50:10 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id HAA11740; Fri, 4 May 2001 07:50:05 -0700 (PDT) Date: Fri, 4 May 2001 07:50:04 -0700 (PDT) From: Brian Rogoff To: Miles Egan cc: caml-list@inria.fr Subject: Re: [Caml-list] printable digest strings In-Reply-To: <20010504070014.A35277@caddr.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 4 May 2001, Miles Egan wrote: > This actually brings me to my next question. There doesn't seem to be a > String.map or String.iter function in the standard library, although I can > imagine they might also be handy. Am I looking in the wrong place? Nope, they're not there. You could use the compiler source, and steal the corresponding functions from arrays, since OCaml does the right thing and has array-like strings (as opposed to say, Erlang and Haskell). Here's the touch up for those two let iter f s = for i = 0 to String.length s - 1 do f(String.unsafe_get s i) done let map f s = let l = String.length s in if l = 0 then "" else begin let r = String.create l in for i = 1 to l - 1 do String.unsafe_set r i (f(String.unsafe_get s i)) done; r end You can now (OCaml 3.01) make your own String module with these functions and include the native String module to get what you want. This is another one of those cases where some overloading might be nice, since IMO there is not much point in distinguishing all of the different kinds of random access with .[], .(), .{}. -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr