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 VAA08107; Wed, 22 Aug 2001 21:18:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA08052 for ; Wed, 22 Aug 2001 21:18:30 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7MJIU911829 for ; Wed, 22 Aug 2001 21:18:30 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id f7MJITm67059 ; Wed, 22 Aug 2001 21:18:29 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id VAA10990 ; Wed, 22 Aug 2001 21:18:29 +0200 (MET DST) Date: Wed, 22 Aug 2001 21:18:29 +0200 (MET DST) From: Alain Frisch To: neale-caml@woozle.org cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Str.string_match raising Invalid_argument "String.sub" in gc In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On 22 Aug 2001 neale-caml@woozle.org wrote: > # let rec f l = > let sep = Str.regexp "^[ \t\n]*\\(.+\\)" in > match l with > | [] -> [] > | [""] -> [] > | s :: rest -> if (Str.string_match sep s 0) then > let foo = print_string ("match " ^ Str.matched_group 1 s ^ "\n") in > (Str.matched_group 1 s) :: (f rest) ^^ This is wrong; with the current OCaml implementation, the right operand of (::) is called first; so (Str.matched_group 1 s) is called after subsequent calls to Str.string_match, which is obviously incorrect. You have to use explicit sequencing (let .. in ..) BTW, you could call Str.regexp only once. -- Alain Frisch ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr