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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 938DE820A2 for ; Tue, 20 Aug 2013 17:53:15 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of monnier.florent@gmail.com) identity=pra; client-ip=209.85.212.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="monnier.florent@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of monnier.florent@gmail.com designates 209.85.212.178 as permitted sender) identity=mailfrom; client-ip=209.85.212.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="monnier.florent@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f178.google.com) identity=helo; client-ip=209.85.212.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="postmaster@mail-wi0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApECAHOQE1LRVdSyk2dsb2JhbABahAu/WYEcCBYOAQEBAQcLCwkUBCSCJAEBBUABGx4DDAYFCw0uIgERAQUBHAaIEAEDD5ZqjFCDAoQ5ChknDWSBFgEFDJBQhBQDl2WKKYVIFimERDo X-IPAS-Result: ApECAHOQE1LRVdSyk2dsb2JhbABahAu/WYEcCBYOAQEBAQcLCwkUBCSCJAEBBUABGx4DDAYFCw0uIgERAQUBHAaIEAEDD5ZqjFCDAoQ5ChknDWSBFgEFDJBQhBQDl2WKKYVIFimERDo X-IronPort-AV: E=Sophos;i="4.89,921,1367964000"; d="scan'208";a="24343682" Received: from mail-wi0-f178.google.com ([209.85.212.178]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Aug 2013 17:53:15 +0200 Received: by mail-wi0-f178.google.com with SMTP id j17so596362wiw.5 for ; Tue, 20 Aug 2013 08:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=DCzXyFuJ8g/da7rJY1ljp2HCxiJUf+jbFwjnpHJNflY=; b=VT1VHwcrpomCl1LXe8Ma7ev7Q6m+UKzXUl20mzi8BNRnlMswhGkfXSXclmNKvBJe3C NUrd+GiEduzH3YmTNSukhHrUflUzuOpber1d7sqvBL83RUonruoHfKMRp9hDnA8cG7FR GwsiCTxvMilrCEpGn5gLM1EEnVQJYxbN6LQECvqxAgX0iBRR3TXhuU03cLtNTGFaNRNu 1Z3Mgl/VDuFQMTjSiXUu46cWRSGbElhqs2DKpHfw4V69kirpiMmkbjYlSx1fNjJrD3GZ DuU1i32K5courizHIpu9KT4+xwzwzCnyVq/XSn6GBAJx3UiYvBZnfyO7blKH2/G5JrUb pIcg== MIME-Version: 1.0 X-Received: by 10.180.188.132 with SMTP id ga4mr1793691wic.53.1377013994696; Tue, 20 Aug 2013 08:53:14 -0700 (PDT) Received: by 10.194.16.5 with HTTP; Tue, 20 Aug 2013 08:53:14 -0700 (PDT) In-Reply-To: <1376312292.29133.3.camel@e130> References: <1376312292.29133.3.camel@e130> Date: Tue, 20 Aug 2013 17:53:14 +0200 Message-ID: From: Florent Monnier To: Caml List Content-Type: text/plain; charset=ISO-8859-1 X-Validation-by: monnier.florent@gmail.com Subject: Re: [Caml-list] String.(r)index_from 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". -- Regards