From: Alessandro Baretta <alex@baretta.com>
To: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Bug somewhere...
Date: Mon, 07 Oct 2002 01:06:27 +0200 [thread overview]
Message-ID: <3DA0C1F3.5010308@baretta.com> (raw)
In-Reply-To: <3DA0BFE1.9050302@baretta.com>
Alessandro Baretta wrote:
> It's either on my brain or in the Scanf module, the former possibility
> being definitely more likely.
>
> I have written a very simple program to compute md5 checksums of a codes
> taken from a text file. Here it is:
>
> let scan_line () = Scanf.scanf "%[^\n\r]\n" (fun a -> a)
> let digest s = String.uppercase
> (Digest.to_hex(Digest.string s))
> let digest_line s = print_endline (s ^ "#" ^ (digest s))
> let _ = try while true do digest_line (scan_line ()) done
> with End_of_file -> ()
I have rewritten my program in ocamllex. This one works.
Here it is.
{
}
rule scanline = parse
| [^'\n''\r']* {Lexing.lexeme lexbuf}
| ['\n''\r']* {scanline lexbuf }
| eof {raise End_of_file}
{
let lexbuf = Lexing.from_channel stdin in
let digest s = String.uppercase
(Digest.to_hex (Digest.string s)) in
let digest_line s = print_endline (s ^ "#" ^ (digest s)) in
try while true do digest_line (scanline lexbuf) done
with End_of_file -> ()
}
> Seems very reasonable...
>
> Here's the input file:
>
> (2002) DMD.CSB.1GL.001.01
> (2002) DMD.CSB.1GL.001.02
> (2002) DMD.CSB.1GL.001.03
> (2002) DMD.CSB.1GL.001.04
> (2002) DMD.CSB.1GL.001.05
> (2002) DMD.CSB.1GL.001.06
> (2002) DMD.CSB.1GL.001.07
> (2002) DMD.CSB.1GL.001.08
> (2002) DMD.CSB.1GL.001.09
> (2002) DMD.CSB.1GL.001.10
> (2002) DMD.CSB.1GL.001.11
> (2002) DMD.CSB.1GL.001.12
> (2002) DMD.CSB.1GL.001.13
> (2002) DMD.CSB.1GL.001.14
> (2002) DMD.CSB.1GL.001.15
> (2002) DMD.CSB.1GL.001.16
> (2002) DMD.CSB.1GL.001.17
> (2002) DMD.CSB.1GL.001.18
> (2002) DMD.CSB.1GL.001.19
> (2002) DMD.CSB.1GL.001.20
And the correct output:
(2002) DMD.CSB.1GL.001.01#EA486F3F11C1D1E5BE6DDC2A444BC4E1
(2002) DMD.CSB.1GL.001.02#DA0E405C9E982D4C51F9D21A2FAB5644
(2002) DMD.CSB.1GL.001.03#9D78774667150BBF2FE473CC149A72DB
(2002) DMD.CSB.1GL.001.04#72491ED198C8BAB5A659EF4730EBF76D
(2002) DMD.CSB.1GL.001.05#AE3CF2982E265B582725AFE770F685F8
(2002) DMD.CSB.1GL.001.06#8825A66BB3C4D1CEB362631C41FF0633
(2002) DMD.CSB.1GL.001.07#AE4F3D477E43943B044E05D5A0BDD498
(2002) DMD.CSB.1GL.001.08#84E0420BB0B52931EF839FB2673116D3
(2002) DMD.CSB.1GL.001.09#144ABD1E3136EBC4BF9642599340326A
(2002) DMD.CSB.1GL.001.10#92C65BDDFB8045D96D9B3DDE2580896C
(2002) DMD.CSB.1GL.001.11#AB9A737B83B040BCD4CE310977B3667B
(2002) DMD.CSB.1GL.001.12#20C1B0322756CC61D3792A6814FA175A
(2002) DMD.CSB.1GL.001.13#20C76BA308A80C93CA2A7FFCCBCD9696
(2002) DMD.CSB.1GL.001.14#BDD11EF273D429A7460E4A010F28AF8D
(2002) DMD.CSB.1GL.001.15#D55A8BEE54618241691AD349DB5D3B0A
(2002) DMD.CSB.1GL.001.16#D655BDC9DB0C22A2A03B718125884778
(2002) DMD.CSB.1GL.001.17#4EA753AEF91A7F497689DF1E43E0D083
(2002) DMD.CSB.1GL.001.18#B37C19DBE5ED47E9F3F9C8E257BC8F3E
(2002) DMD.CSB.1GL.001.19#A35BEE6D08F95935BFFC61ACFEAC54B7
(2002) DMD.CSB.1GL.001.20#FB357D47CF387E1EBFD94C9E79A1DD6A
What's wrong with the Scanf version?
Alex
-------------------
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-06 22:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-06 22:57 Alessandro Baretta
2002-10-06 23:06 ` Alessandro Baretta [this message]
2002-10-08 20:07 ` Pierre Weis
2002-10-08 21:26 ` Eric C. Cooper
2002-10-08 23:31 ` Alessandro Baretta
2002-10-07 8:03 ` Pierre Weis
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=3DA0C1F3.5010308@baretta.com \
--to=alex@baretta.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