From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA12987 for caml-redistribution; Thu, 12 Aug 1999 16:39:50 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA10718 for ; Thu, 12 Aug 1999 14:02:35 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id NAA18905 for ; Thu, 12 Aug 1999 13:16:10 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id NAA02423; Thu, 12 Aug 1999 13:16:03 +0200 (MET DST) From: Markus Mottl Message-Id: <199908121116.NAA02423@miss.wu-wien.ac.at> Subject: Re: Constructor/reference bug? To: skaller@maxtal.com.au (John Skaller) Date: Thu, 12 Aug 1999 13:16:03 +0100 (MET DST) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au> from "John Skaller" at Aug 11, 99 06:05:30 pm X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > let g x = > let lineno = ref (1,"") in > let rec f x' = match x' with > | NEWLINE p :: t -> lineno := p; f t > | COLON :: t -> CTRL !lineno :: f t > | h :: t -> h :: f t > | [] -> [] > in f x;; > > The code doesn't work as I expected: every > CTRL value refers to the same lineno, the last one. > If I change the COLON line to read: > > | COLON :: t -> let x = !lineno in CTRL x :: f t > > the code works as expected -- the CTRL refers to the > value of lineno at the time the last NEWLINE was processed. > > What's happening? Are coproduct constructors lazy? No, but OCaml evaluates all kind of expressions right-to-left which is probably not very intuitive for people who are used to read from left to right... Regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl