caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: moj@utu.fi (Matti Jokinen)
To: Caml List <caml-list@inria.fr>
Subject: Re: immutable strings
Date: Mon, 05 Jun 2006 23:54:33 +0300	[thread overview]
Message-ID: <20060605205433.GA14267@utu.fi> (raw)
In-Reply-To: <196F1D996F92CD46A542EA519DB8CE4703CCA9F0@orsmsx409>

> 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


  parent reply	other threads:[~2006-06-05 20:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-28 23:20 [Caml-list] Re: immutable strings (Re: Array 4 MB size limit) Harrison, John R
2006-05-29  2:36 ` Martin Jambon
2006-05-31 12:53 ` Jean-Christophe Filliatre
2006-06-05 20:54 ` Matti Jokinen [this message]
2006-06-07  0:36   ` [Caml-list] Re: immutable strings Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060605205433.GA14267@utu.fi \
    --to=moj@utu.fi \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).