Browse thread
Constructor/reference bug?
-
John Skaller
- Nicolas Ollinger
- Jean-Christophe Filliatre
- Andreas Rossberg
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andreas Rossberg <rossberg@p...> |
| Subject: | Re: Constructor/reference bug? |
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. ::