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 SAA02010; Thu, 23 Aug 2001 18:25:06 +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 SAA02066 for ; Thu, 23 Aug 2001 18:25:05 +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 f7NGP4X02368 for ; Thu, 23 Aug 2001 18:25:04 +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 f7NGP4m50915 ; Thu, 23 Aug 2001 18:25:04 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id SAA05885 ; Thu, 23 Aug 2001 18:25:04 +0200 (MET DST) Date: Thu, 23 Aug 2001 18:25:04 +0200 (MET DST) From: Alain Frisch To: Neale Pickett 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 23 Aug 2001, Neale Pickett wrote: > I contest that this is obvious. s is a different string each time f is > called, and so even though I do call Str.string_match multiple times, > it's with a different s. The manual for the Str libary says only that I > must pass in the same s as was given to string_match, which implies that > s is somehow keyed to its matches. It sounds as though I shouldn't do > the following: > > Str.string_match sep s 0; > Str.string_match sep s' 0; > print_string (Str.matched_group 1 s); > > If this is the case, why does Str.matched_group even bother requiring > the original string? Indeed, you shouldn't. The manual says: << val matched_string: string -> string matched_string s returns the substring of s that was matched by the latest string_match, search_forward or search_backward. The user must make sure that the parameter s is the same string that was passed to the matching or searching function. >> Note the "latest". The approach you suggest (that the library keeps a reference to the last matched string) is acceptable. I guess it was not implemented like that because this would prevent garbage collection of the last matched string. (maybe a "release_internal_buffer" function would have been better) -- Alain ------------------- 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