[
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: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Curried form different from "normal" |
On Sunday 05 February 2006 16:40, Till Varoquaux wrote:
> let non_blank_string=
> if !is_first then
> trailling:=Buffer.contents white
> else
> Buffer.add_buffer buf white;
> Buffer.reset white;
> is_first:=false;
> Buffer.add_string buf
>
> let non_blank_string s=
> if !is_first then
> trailling:=Buffer.contents white
> else
> Buffer.add_buffer buf white;
> Buffer.reset white;
> is_first:=false;
> Buffer.add_string buf s
>
> Doesn't yeld the same results (the former is buggy). Now, as I
> understand, these two functions should be exactly equivalent. I am
> misunderstanding something here?
The code preceding the call to "Buffer.add_string" is only evaluated once in
the former case (at the time of definition) whereas it is evaluated at each
invocation of the latter definition of "non_blank_string".
You should not have expected these two definitions to be "exactly equivalent"
as the former is equivalent to:
if !is_first then
trailling:=Buffer.contents white
else
Buffer.add_buffer buf white;;
Buffer.reset white;;
is_first:=false;;
let non_blank_string =
Buffer.add_string buf
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists