From: Pierre Weis <pierre.weis@inria.fr>
To: alex@baretta.com (Alessandro Baretta)
Cc: luc.maranget@inria.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Pattern matching and strings (and a mini-bug in Scanf)
Date: Fri, 4 Oct 2002 11:07:13 +0200 (MET DST) [thread overview]
Message-ID: <200210040907.LAA15958@pauillac.inria.fr> (raw)
In-Reply-To: <3D9B1CF4.5030706@baretta.com> from Alessandro Baretta at "Oct 2, 102 06:21:08 pm"
[...]
> I meant what I wrote. The %s conversion stops reading at the
> first whitespace character. However, ocaml does not like
> the "%[^]" which, in my opinion, is to be considered a
> mini-bug. "%[^]" should be interpreted as "the set of all
> characters except none", which is "the set of all
> characters", which can also be expressed, more verbosely, as
> "%[\000-\255]". By the same standards, "%[]" is rejected,
> when it should be interpreted as "the set containing no
> characters", or more verbosely "%[^\000-\255]"
[...]
> Alex
This is not a mini-bug, this is a carefully crafted feature and
thoroughly considered design decision :(
"%[]" is not allowed because we need to allow the matching of the
closing bracket. Hence, if ']' just follows the opening bracket (or
the ^ character, in case of negative range) it is considered as a
plain ']' (or ascii code 93) to be matched.
So "%[]]" means matching ']' (well, more precisely zero or more ']');
more generally, "%[]range]" means matching ']' or range; "%[^]range]"
means matching any character different from ']' and not belonging to
range.
Admitedly, we could have made a different decision, such as a special
escape for ']' in a range that would have made possible your
interpretation of "%[]". However, I considered that the matching of an
empty range of characters (or conversely a full range of characters)
was way less useful and frequent than matching a ']'. Hence, the more
complex expressions "%[^\000-\255]" and "%[\000-\255]" for the seldom
used ranges.
To end with, I want also to elaborate a bit on the last sentence of
the Scanf documentation because many people misunderstand it:
Note: the [scanf] facility is not intended for heavy duty
lexical analysis and parsing.
As you said ``I meant what I wrote''. I did not mean that [scanf] is
slow (it is not). I did not mean that it is not powerful (since it is
much more powerful than the corresponding C facility). I meant that it
is perfectly ok to write complex input reading functions (up to, say,
a polymorphic list scanner for instance), but [scanf] is not the right
tool to write a full-fledge Caml parser.
On the other hand, writing a polymorphic list scanner using lex and
yacc seems to me way more difficult than the 10 or 15 lines of code
you need to implement the polymorphic list scanner, if you use the
[Scanf] module facilities :)
May be this note should be removed, since, at last, it just means ``Use
the right tool for the work at hand'', which evidently goes without
saying when you are talking to people that already chose Objective
Caml to write their programs !
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-10-04 9:07 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-02 14:12 [Caml-list] Pattern matching and strings Alessandro Baretta
2002-10-02 15:02 ` Luc Maranget
2002-10-02 16:21 ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Alessandro Baretta
2002-10-02 17:15 ` Luc Maranget
2002-10-02 18:30 ` Alessandro Baretta
2002-10-02 18:32 ` Benjamin C. Pierce
2002-10-04 13:01 ` Florian Douetteau
2002-10-04 9:07 ` Pierre Weis [this message]
2002-10-04 9:31 ` Alessandro Baretta
2002-10-04 10:03 ` Pierre Weis
2002-10-04 10:23 ` Alessandro Baretta
2002-10-04 12:11 ` Remi VANICAT
2002-10-04 12:40 ` [Caml-list] Ocaml 3.06 Win2K OCAML/C link problem Ward Wheeler
2002-10-04 13:12 ` [Caml-list] Pattern matching and strings (and a mini-bug inScanf) Frederic van der Plancke
2002-10-04 19:31 ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Alessandro Baretta
2002-10-07 7:17 ` Pierre Weis
2002-10-02 20:59 ` [Caml-list] views for strings (was: Pattern matching and strings) Chris Hecker
2002-10-02 23:09 ` [Caml-list] " Alessandro Baretta
2002-10-03 8:31 ` [Caml-list] Pattern matching and strings Sven Luther
2002-10-04 12:00 ` Andreas Rossberg
2002-10-04 14:21 ` Kontra, Gergely
2002-10-04 15:14 ` Luc Maranget
2002-10-04 19:38 ` Alessandro Baretta
2002-10-05 6:34 ` [Caml-list] Camlp4 (Was: Pattern matching and strings) Daniel de Rauglaudre
2002-10-05 12:47 ` Sven LUTHER
2002-10-05 12:42 ` Daniel de Rauglaudre
2002-10-05 13:41 ` Michel Mauny
2002-10-05 13:47 ` Daniel de Rauglaudre
2002-10-05 14:09 ` Michel Mauny
2002-10-05 18:13 ` Alessandro Baretta
2002-10-05 20:30 ` [Caml-list] Future of Camlp4 Daniel de Rauglaudre
2002-10-04 19:13 ` [Caml-list] Pattern matching and strings Sven LUTHER
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=200210040907.LAA15958@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=alex@baretta.com \
--cc=caml-list@inria.fr \
--cc=luc.maranget@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