From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 83F4D820A1 for ; Wed, 21 Aug 2013 02:42:44 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of berenger@riken.jp) identity=pra; client-ip=134.160.33.161; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of berenger@riken.jp designates 134.160.33.161 as permitted sender) identity=mailfrom; client-ip=134.160.33.161; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@postman.riken.jp designates 134.160.33.161 as permitted sender) identity=helo; client-ip=134.160.33.161; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="postmaster@postman.riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4CADEMFFKGoCGhh2dsb2JhbABaw2WBPA4BAQEKCwkHFiiCJAEBBThAEQsYCRYPCQMCAQIBRRMIAQGICwGtZJBcFoN+A4krjjqKKYpY X-IPAS-Result: Am4CADEMFFKGoCGhh2dsb2JhbABaw2WBPA4BAQEKCwkHFiiCJAEBBThAEQsYCRYPCQMCAQIBRRMIAQGICwGtZJBcFoN+A4krjjqKKYpY X-IronPort-AV: E=Sophos;i="4.89,923,1367964000"; d="scan'208";a="29895783" Received: from postman1.riken.jp (HELO postman.riken.jp) ([134.160.33.161]) by mail2-smtp-roc.national.inria.fr with ESMTP; 21 Aug 2013 02:42:42 +0200 Received: from postman.riken.jp (postman1.riken.jp [127.0.0.1]) by postman.riken.jp (Postfix) with SMTP id 63B3A2588001 for ; Wed, 21 Aug 2013 09:42:39 +0900 (JST) Received: from fbrs-iMac.local (usr013.bb802-01.ual.im.wakwak.ne.jp [219.121.104.207]) by postman.riken.jp (Postfix) with ESMTPA id 28B6D32A0085 for ; Wed, 21 Aug 2013 09:42:39 +0900 (JST) Message-ID: <52140CFE.2040208@riken.jp> Date: Wed, 21 Aug 2013 09:42:38 +0900 From: Francois Berenger User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: caml-list@inria.fr References: <1376312292.29133.3.camel@e130> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2013.8.21.3625 Subject: Re: [Caml-list] String.(r)index_from Hi Florent, If you find yourself doing non trivial things with the String module, maybe it means you should use another module which works at a higher level. Str for example, or some other module from extended versions of the stdlib. Regards, F. On 8/21/13 12:53 AM, Florent Monnier wrote: > 2013/08/12, Gerd Stolpmann wrote: >> IMHO, this is the right behavior. When walking over strings, it is often >> practical to consider the position after the last character as legal >> position. So far I see, this is consistent in the String module, e.g. >> you can also do String.sub "abc" 3 0. >> >> It's a bit like considering 0 as natural number. > > Hi Gerd, > > Well I can understand that there is some kind of logic there, even if > the logic is different than the one that I expected at the beginning. > But it doesn't seem to be very consistent with the functions that > perform searches from right to left: > > # let s = "012";; > val s : string = "012" > > # let n = String.length s ;; > val n : int = 3 > > # String.sub s n 0 ;; > - : string = "" > > (* OK, so why is n valid for String.sub, but not for these below? *) > > # String.rcontains_from s (n-1) '2' ;; > - : bool = true > > # String.rcontains_from s n '2' ;; > Exception: Invalid_argument "String.rcontains_from". > > # String.rindex_from s (n-1) '2' ;; > - : int = 2 > > # String.rindex_from s n '2' ;; > Exception: Invalid_argument "String.rindex_from". > >