From: Florent Monnier <monnier.florent@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] String.(r)index_from
Date: Tue, 20 Aug 2013 17:53:14 +0200 [thread overview]
Message-ID: <CAE1DttB-xbZ1pJudcG0vZi0033zHfLTRWHbLrQf-EMqc3sRZXw@mail.gmail.com> (raw)
In-Reply-To: <1376312292.29133.3.camel@e130>
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
next prev parent reply other threads:[~2013-08-20 15:53 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 [this message]
2013-08-21 0:42 ` Francois Berenger
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=CAE1DttB-xbZ1pJudcG0vZi0033zHfLTRWHbLrQf-EMqc3sRZXw@mail.gmail.com \
--to=monnier.florent@gmail.com \
--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