From: Francois Berenger <berenger@riken.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] String.(r)index_from
Date: Wed, 21 Aug 2013 09:42:38 +0900 [thread overview]
Message-ID: <52140CFE.2040208@riken.jp> (raw)
In-Reply-To: <CAE1DttB-xbZ1pJudcG0vZi0033zHfLTRWHbLrQf-EMqc3sRZXw@mail.gmail.com>
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".
>
>
prev parent reply other threads:[~2013-08-21 0:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-12 10:55 Florent Monnier
2013-08-12 12:58 ` Gerd Stolpmann
2013-08-19 18:19 ` Damien Doligez
2013-08-20 15:23 ` Florent Monnier
2013-08-20 15:53 ` Florent Monnier
2013-08-21 0:42 ` Francois Berenger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52140CFE.2040208@riken.jp \
--to=berenger@riken.jp \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox