English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2006-06-05 (20:54)
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;;


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


# 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 ();;



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

- Matti Jokien