Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] Re: immutable strings (Re: Array 4 MB size limit)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: moj@u...
Subject: Re: immutable strings
> In practice, the obvious library calls are safe, so like Aleksey, I use
> the built-in strings for the sake of convenience and compatibility. But
> it's unsatisfactory intellectually.

Actually, there are cases of unsafe sharing even in the standard library.


# let x = "X" in
  let g = Genlex.make_lexer [x] in
  let s = Stream.of_string "X" in
  let t = g s in
  let _ = Stream.peek t in
  x.[0] <- 'Y';
  Stream.peek t;;

result:

- : Genlex.token option = Some (Genlex.Kwd "Y")


Format:

# let x = "X" in
  let f = Format.make_formatter (output stdout) (fun () -> flush stdout) in
  Format.pp_print_string f x;
  x.[0] <- 'Y';
  Format.pp_print_newline f (); Format.pp_print_flush f ();;

output:

        Y


I think this demonstrates that the problem is real: it is too easy to
forget copying.

- Matti Jokien