From: Francois Thomasset <Francois.Thomasset@inria.fr>
To: caml-list@inria.fr
Subject: [Caml-list] where is my count: newbie's question
Date: Mon, 11 Jun 2001 12:21:00 +0200 [thread overview]
Message-ID: <200106111021.f5BAL0L08064@ionie.inria.fr> (raw)
Sorry if this is a naive question, but I can't make out the reason of the
behavior of the following function, which is a (seemingly!) slighty
modification of the gensym example:
# let fnx(x) = let count = ref 0 in
let f() =
Printf.printf "x = %d\n" x;
Printf.printf "count = %d\n" !count;
count := !count + 1; !count
in f;;
val fnx : int -> unit -> int = <fun>
I would have expected that count remembers its previous value, which would be
incremented at each call, but this is not true : !count is always 0.
Of course if I remove the int argument I retrieve the behavior I expected:
# let fnx = let count = ref 0 in
let f() =
Printf.printf "count = %d\n" !count;
count := !count + 1; !count
in f;;
val fnx : unit -> int = <fun>
# fnx();;
count = 0
- : int = 1
# fnx();;
count = 1
- : int = 2
François Thomasset.
INRIA (A3)
Tel: +33 (1) 39-63-54-75
Fax: +33 (1) 39-63-53-30 ou +33 (1) 39-63-59-95
Email: Francois.Thomasset@inria.fr
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next reply other threads:[~2001-06-11 10:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-11 10:21 Francois Thomasset [this message]
2001-06-11 11:26 ` Markus Mottl
2001-06-11 11:30 ` David Mentre
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=200106111021.f5BAL0L08064@ionie.inria.fr \
--to=francois.thomasset@inria.fr \
--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