From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A52EDBB83 for ; Mon, 5 Jun 2006 22:54:39 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k55KsdvS012986 for ; Mon, 5 Jun 2006 22:54:39 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA25543 for ; Mon, 5 Jun 2006 22:54:38 +0200 (MET DST) Received: from smtp-out-02.utu.fi (smtp-out-02.utu.fi [130.232.202.172]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k55KsbMB012975 for ; Mon, 5 Jun 2006 22:54:38 +0200 Received: from alfirk.yob.utu.fi (alfirk.yob.utu.fi [130.232.36.49]) by smtp02.mess.utu.fi (Sun Java System Messaging Server 6.2-2.05 (built Apr 28 2005)) with ESMTP id <0J0E004UKNEXW553@smtp02.mess.utu.fi> for caml-list@inria.fr; Mon, 05 Jun 2006 23:54:33 +0300 (EEST) Received: by alfirk.yob.utu.fi (Postfix, from userid 268) id 3257013FC19; Mon, 05 Jun 2006 23:54:33 +0300 (EEST) Date: Mon, 05 Jun 2006 23:54:33 +0300 From: moj@utu.fi (Matti Jokinen) Subject: Re: immutable strings In-reply-to: <196F1D996F92CD46A542EA519DB8CE4703CCA9F0@orsmsx409> To: Caml List Message-id: <20060605205433.GA14267@utu.fi> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline References: <196F1D996F92CD46A542EA519DB8CE4703CCA9F0@orsmsx409> User-Agent: Mutt/1.5.11+cvs20060126 X-Miltered: at concorde with ID 44849A0F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44849A0D.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; utu:01 matti:01 jokinen:01 genlex:01 lexer:01 genlex:01 kwd:01 stdout:01 stdout:01 matti:01 token:01 immutable:01 unsafe:01 strings:01 strings:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 > 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