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 QAA17307 for caml-redistribution; Thu, 12 Aug 1999 16:42:02 +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 OAA13652 for ; Thu, 12 Aug 1999 14:02:32 +0200 (MET DST) Received: from uni-sb.de (uni-sb.de [134.96.252.33]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id NAA19118 for ; Thu, 12 Aug 1999 13:26:17 +0200 (MET DST) Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.252.31]) by uni-sb.de (8.9.3/1999070600) with ESMTP id NAA01840; Thu, 12 Aug 1999 13:26:04 +0200 (CEST) Received: from emerald.ps.uni-sb.de (emerald.ps.uni-sb.de [134.96.186.105]) by cs.uni-sb.de (8.9.3/1999031900) with ESMTP id NAA06074; Thu, 12 Aug 1999 13:25:53 +0200 (CEST) Received: from ps.uni-sb.de (IDENT:rossberg@localhost [127.0.0.1]) by emerald.ps.uni-sb.de (8.9.1a/8.9.1) with ESMTP id NAA04881; Thu, 12 Aug 1999 13:25:53 +0200 Sender: weis Message-ID: <37B2AF41.3894ABCE@ps.uni-sb.de> Date: Thu, 12 Aug 1999 13:25:53 +0200 From: Andreas Rossberg Organization: =?iso-8859-1?Q?Universit=E4t?= des Saarlandes X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.2.9 i686) X-Accept-Language: German, de, en MIME-Version: 1.0 To: John Skaller CC: caml-list@inria.fr Subject: Re: Constructor/reference bug? References: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit John Skaller wrote: > > 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. Evaluation order of application is not specified in OCaml: arguments may be evaluated in any order (in fact, byte code does it right-to-left, native code left-to-right, if I remember correctly). That seems to be what's happening here: (f t), the second argument to ::, is evaluated before (CTRL !lineno). Using let eliminates this problem. HTH, - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de :: be declarative. be functional. just be. ::