From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 2C8BEBC6B for ; Mon, 11 Feb 2008 14:46:20 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAN/gr0fAXQInh2dsb2JhbACCPTSNSAEBAQgKKZZp X-IronPort-AV: E=Sophos;i="4.25,333,1199660400"; d="scan'208";a="7163757" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 11 Feb 2008 14:46:19 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1BDkJWw005340 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 11 Feb 2008 14:46:19 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPHfr0dA6bjkkGdsb2JhbACCPTSNSAEBAQEHAgYJChEHlmI X-IronPort-AV: E=Sophos;i="4.25,333,1199660400"; d="scan'208";a="22471815" Received: from wr-out-0506.google.com ([64.233.184.228]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Feb 2008 14:46:18 +0100 Received: by wr-out-0506.google.com with SMTP id c57so4472147wra.9 for ; Mon, 11 Feb 2008 05:46:17 -0800 (PST) Received: by 10.143.161.3 with SMTP id n3mr8503870wfo.114.1202737575167; Mon, 11 Feb 2008 05:46:15 -0800 (PST) Received: by 10.142.179.16 with HTTP; Mon, 11 Feb 2008 05:46:15 -0800 (PST) Message-ID: <71767b800802110546p827d48dy4fc883594c4b3f27@mail.gmail.com> Date: Mon, 11 Feb 2008 08:46:15 -0500 From: "Ralph Douglass" To: "Caml List" Subject: Re: [Caml-list] confusion about mutable strings In-Reply-To: <6f9f8f4a0802110201k5e81e65ft7dcbb9773be34f76@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12928_29666801.1202737575174" References: <71767b800802100946o4d465b79xad9b1f9515f7e69f@mail.gmail.com> <8BDAF65E-F29B-4F8C-B20E-1E0FDA521609@erratique.ch> <71767b800802101622j45fd0db4id4351b44fb1f9cf3@mail.gmail.com> <6f9f8f4a0802110201k5e81e65ft7dcbb9773be34f76@mail.gmail.com> X-Miltered: at concorde with ID 47B051AB.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; mutable:01 foo:01 iter:01 printf:01 printf:01 val:01 foo:01 ocaml:01 iter:01 val:01 ocaml:01 char:01 char:01 wrote:01 wrote:01 ------=_Part_12928_29666801.1202737575174 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Sorry, I was indeed informed today by someone at work that it was talked about a week or two ago. There is so much going on on the list that I just missed it. And now I added noise myself. Sigh. Thanks, Ralph On 2/11/08, Loup Vaillant wrote: > > 2008/2/11, Ralph Douglass : > > > > Observe the following: > > > > # let foo () = > > let bar = [|'a';'b';'c'|] in > > Array.iter (Printf.printf "%c") bar; > > bar.(0) <- 'd'; > > bar;; > > val foo : unit -> char array = > > # foo ();; > > abc- : char array = [|'d'; 'b'; 'c'|] > > # foo ();; > > abc- : char array = [|'d'; 'b'; 'c'|] > > > > Why does OCaml treat these two examples in such a different manner? Is > > there a reason why strings are magically special in this way? > > C strings are usually "magically special" in exactly the same way. It > has been talked about in another thread (dunno how to look for it). > Basically, this is a design choice meant for better performance. > > Loup > -- Ralph ------=_Part_12928_29666801.1202737575174 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Sorry, I was indeed informed today by someone at work that it was talked about a week or two ago.  There is so much going on on the list that I just missed it.  And now I added noise myself.  Sigh.

Thanks,

Ralph

On 2/11/08, Loup Vaillant <loup.vaillant@gmail.com> wrote:
2008/2/11, Ralph Douglass <ralph@grayskies.net>:
>
> Observe the following:
>
> # let foo () =
>   let bar = [|'a';'b';'c'|] in
>   Array.iter (Printf.printf "%c") bar;
>   bar.(0) <- 'd';
>   bar;;
> val foo : unit -> char array = <fun>
>  # foo ();;
> abc- : char array = [|'d'; 'b'; 'c'|]
> # foo ();;
> abc- : char array = [|'d'; 'b'; 'c'|]
>
> Why does OCaml treat these two examples in such a different manner?  Is
> there a reason why strings are magically special in this way?

C strings are usually "magically special" in exactly the same way. It
has been talked about in another thread (dunno how to look for it).
Basically, this is a design choice meant for better performance.

Loup



--
Ralph ------=_Part_12928_29666801.1202737575174--