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 2C2027EE4B for ; Tue, 8 Oct 2013 06:30:42 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.41 as permitted sender) identity=mailfrom; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-bk0-f41.google.com) identity=helo; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f41.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsgBAJ6JU1LRVdYpm2dsb2JhbABZgz9SrkyKFIhDgRcIFg4BAQEBAQYLCwkUKIIlAQEEAScZARsSCwEDAQsGBQQHDQ0hIgERAQUBChIGExKHYQEDCQYMnQKMU4MKhAsKGScDCmSJAQEFDI9BBAeEIwOYAYEvjmYYKYJlgWs6 X-IPAS-Result: AsgBAJ6JU1LRVdYpm2dsb2JhbABZgz9SrkyKFIhDgRcIFg4BAQEBAQYLCwkUKIIlAQEEAScZARsSCwEDAQsGBQQHDQ0hIgERAQUBChIGExKHYQEDCQYMnQKMU4MKhAsKGScDCmSJAQEFDI9BBAeEIwOYAYEvjmYYKYJlgWs6 X-IronPort-AV: E=Sophos;i="4.90,1054,1371074400"; d="scan'208";a="35980391" Received: from mail-bk0-f41.google.com ([209.85.214.41]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 08 Oct 2013 06:30:40 +0200 Received: by mail-bk0-f41.google.com with SMTP id na10so2999608bkb.14 for ; Mon, 07 Oct 2013 21:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=kHOsGa1WAuxCMBNGAOnJ+Sux1TrLj79U6WBLhs3yIAc=; b=EEmvSFbGoDAChWxI4EbbO3/W/cUBhkZmAqcaZ9aCo9G0qFcGSCx8gEF+xJ/EcdyxGR hh0eiiK+LS34ck/egACiYVr0pIIrl3sb1zQT2uyR5Qb4OmmDJ/mT69M3v0GeFKei8EmA UBp9FueTVfs72sZqMRrFOwpBTKEwRrI4Vt8tVH1fwiBjmHwaXz7mrmD44iDITxtqBcJp +yUs0f9OS4I/V/74TMfrNa+ocmnqN+XL52wugx4LXU/4Mw6ntSv7FQj5SRu6g0e0PvNs 8V9T+W3p2Yz6/JPngXYOzmz4TJM2wJtSzGRSjGxK/7TN8aQ5vyaIDbUmSaT+rmSK8i9j bpWw== X-Received: by 10.204.103.199 with SMTP id l7mr30548018bko.11.1381206640955; Mon, 07 Oct 2013 21:30:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.236.193 with HTTP; Mon, 7 Oct 2013 21:30:00 -0700 (PDT) In-Reply-To: <52537BE9.6080005@rftp.com> References: <525374ED.2010906@riken.jp> <52537BE9.6080005@rftp.com> From: Gabriel Scherer Date: Tue, 8 Oct 2013 06:30:00 +0200 Message-ID: To: Robert Roessler Cc: Francois Berenger , caml users Content-Type: multipart/alternative; boundary=001a113351943241b304e8333b29 Subject: Re: [Caml-list] Scanf.sscanf surprised me --001a113351943241b304e8333b29 Content-Type: text/plain; charset=ISO-8859-1 Use "%s@,%f..." to specify (with @) that the string should stop at the first comma. On Tue, Oct 8, 2013 at 5:28 AM, Robert Roessler wrote: > Francois Berenger wrote: > >> This example line and scanning format work: >> >> # let line = "active_ZINC01535869 >> 0.470,0.389,0.479,0.453,0.470,**0.631,0.562,0.590,0.677,0.558,**0.379";; >> val line : string = >> "active_ZINC01535869 >> 0.470,0.389,0.479,0.453,0.470,**0.631,0.562,0.590,0.677,0.558,**0.379" >> # Scanf.sscanf line "%s %f,%f,%f,%f,%f,%f,%f,%f,%f,%f,**%f" (fun name s1 >> s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7, >> s8, s9, s10, s11));; >> - : string * float * float * float * float * float * float * float * >> float * float * float * float >> = >> ("active_ZINC01535869", 0.47, 0.389, 0.479, 0.453, 0.47, 0.631, 0.562, >> 0.59, 0.677, 0.558, 0.379) >> >> This one doesn't: >> >> # let line = >> "active_ZINC01535869,0.470,0.**389,0.479,0.453,0.470,0.631,0.** >> 562,0.590,0.677,0.558,0.379";; >> val line : >> string = >> >> "active_ZINC01535869,0.470,0.**389,0.479,0.453,0.470,0.631,0.** >> 562,0.590,0.677,0.558,0.379" >> >> # Scanf.sscanf line "%s,%f,%f,%f,%f,%f,%f,%f,%f,%**f,%f,%f" (fun name s1 >> s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7, >> s8, s9, s10, s11));; >> Exception: End_of_file. >> >> I am quite surprised. >> I was expecting the first separator being a space or a coma >> to behave the same. >> > > The specification of scanf "%s" is "Any number of non-whitespace > characters, stopping at the first whitespace character found". > > So, perhaps not that surprising? > > Regards, > -- > Robert Roessler > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/**arc/caml-list > Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-**bugs > --001a113351943241b304e8333b29 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Use "%s@,%f..." to specify (with @) that the str= ing should stop at the first comma.


On Tue, Oct 8, 2013 at 5:28 AM, Robert= Roessler <roessler@rftp.com> wrote:
Francois Berenger wrote:
This example line and scanning format work:

# let line =3D "active_ZINC01535869
0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0= .379";;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0val line : string =3D
=A0 =A0"active_ZINC01535869
0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0= .379"
# Scanf.sscanf line "%s %f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f" = (fun name s1
s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7,
s8, s9, s10, s11));;
- : string * float * float * float * float * float * float * float *
=A0 =A0 =A0float * float * float * float
=3D
("active_ZINC01535869", 0.47, 0.389, 0.479, 0.453, 0.47, 0.631, 0= .562,
0.59, 0.677, 0.558, 0.379)

This one doesn't:

# let line =3D
"active_ZINC01535869,0.470,0.389,0.479,0.453,0.470,0.631,0.<= /u>562,0.590,0.677,0.558,0.379";;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 val line :
string =3D

"active_ZINC01535869,0.470,0.389,0.479,0.453,0.470,0.631,0.<= /u>562,0.590,0.677,0.558,0.379"

# Scanf.sscanf line "%s,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f" = (fun name s1
s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7,
s8, s9, s10, s11));;
Exception: End_of_file.

I am quite surprised.
I was expecting the first separator being a space or a coma
to behave the same.

The specification of scanf "%s" is "Any number of non-whites= pace characters, stopping at the first whitespace character found".

So, perhaps not that surprising?

Regards,
--
Robert Roessler

--001a113351943241b304e8333b29--