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=1.0 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 752BDBC6B for ; Fri, 25 Jan 2008 00:02:49 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAManmEdIDtbrfGdsb2JhbACCOTaNNQEBCQQECQgTBZZgh3c X-IronPort-AV: E=Sophos;i="4.25,246,1199660400"; d="scan'208";a="21769393" Received: from hu-out-0506.google.com ([72.14.214.235]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Jan 2008 00:02:48 +0100 Received: by hu-out-0506.google.com with SMTP id 40so254368hub.13 for ; Thu, 24 Jan 2008 15:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=4DNZvB7dbK+HhNIEc+lWvFARUtXjI34vhMmFb2R0U/M=; b=WdD+jkX5UZIJN2qWV8FAm768Ypu1UJgRh3ymLXiwlvKKqiYz1ITKNZEFTAfsJhss/gKyqhYJdgTpmsvRsA7qEtnEePLWRwt2zNeGV/gdkZIYFcXb3fqKjHcMfJJMgltv2LCP8HhO0/OJOBatuBHZokrvzDq8IyUl+YeeejvAl/U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=aW+ohmbvzhdLxA0hjrLTVPoA69wK+J4N+FUzyhnPoUpCEIyyRiox60VlaiOJu1OApincFqJYH03sjVx9Npo5QICtah9jycdYidlM1UbbR3y9zMpks2GDAmsc3qu0XqrVqs8rudRmNADFP8/VyZ0odqOqOjUVwuu/IksL9D9yUzA= Received: by 10.78.162.4 with SMTP id k4mr1952242hue.66.1201215768114; Thu, 24 Jan 2008 15:02:48 -0800 (PST) Received: by 10.78.179.4 with HTTP; Thu, 24 Jan 2008 15:02:48 -0800 (PST) Message-ID: Date: Thu, 24 Jan 2008 18:02:48 -0500 From: "Ashish Agarwal" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Concatenation of static strings? Cc: david.baelde@ens-lyon.org In-Reply-To: <53c655920801190255p71346ac9ka45adf0e1cef2d17@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_25605_28935324.1201215768108" References: <20080119143259.46752d11.mle+ocaml@mega-nerd.com> <53c655920801190255p71346ac9ka45adf0e1cef2d17@mail.gmail.com> X-Spam: no; 0.00; bug:01 val:01 ocaml:01 bug:01 compiler:01 val:01 contrasted:01 arrays:01 mutable:01 statically:01 'l':01 statically:01 cheers:01 beginner's:01 ocaml:01 ------=_Part_25605_28935324.1201215768108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I was hoping there would be some follow up discussion on the code below, but haven't seen anything yet. Can someone please clarify why this is not considered a bug (or is it). Given that s is locally scoped within f, I do not see why f returns different answers. > # let f () = let s = "bla" in let c = s.[0] in s.[0] <- 'c' ; c ;; > val f : unit -> char = > # f () ;; > - : char = 'b' > # f () ;; > - : char = 'c' On Jan 19, 2008 5:55 AM, David Baelde wrote: > Nice, I didn't know about the stripping of the first whitespaces. > > Speaking of static strings, the static string allocation done by OCaml > is not compatible with the mutability of strings. I've been told that > the issue was raised a long time ago, so I'm not filing this as a bug, > but since I could not find any information on the web I thought > someone here might be able to recall what motivated the decision in > former discussions. Maybe the issue is considered a little price to > pay for the optimization, since we rarely use string mutations.. > > The issue can be witnessed with the following code, on 3.10, either in > the interactive loop or with any compiler: > > # let f () = let s = "bla" in let c = s.[0] in s.[0] <- 'c' ; c ;; > val f : unit -> char = > # f () ;; > - : char = 'b' > # f () ;; > - : char = 'c' > > This is to be contrasted with arrays, which are mutable too but not > statically allocated as for strings (let f () = let s = > [|'b';'l';'a'|] in let c = s.(0) in s.(0) <- 'c' ; c). > > And for Erik, a test that tells us that concatenations are not done statically: > > # let f () = let s = "b"^"la" in let c = s.[0] in s.[0] <- 'c' ; c ;; > val f : unit -> char = > # f () ;; > - : char = 'b' > # f () ;; > - : char = 'b' > > Cheers, > > David > > > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ------=_Part_25605_28935324.1201215768108 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I was hoping there would be some follow up discussion on the code below, but haven't seen anything yet. Can someone please clarify why this is not considered a bug (or is it). Given that s is locally scoped within f, I do not see why f returns different answers.

> # let f () = let s = "bla" in let c = s.[0] in s.[0] <- 'c' ; c ;;
> val f : unit -> char = <fun>
> # f () ;;
> - : char = 'b'
> # f () ;;
> - : char = 'c'



On Jan 19, 2008 5:55 AM, David Baelde <david.baelde@gmail.com> wrote:
> Nice, I didn't know about the stripping of the first whitespaces.
>
> Speaking of static strings, the static string allocation done by OCaml
> is not compatible with the mutability of strings. I've been told that
> the issue was raised a long time ago, so I'm not filing this as a bug,
> but since I could not find any information on the web I thought
> someone here might be able to recall what motivated the decision in
> former discussions. Maybe the issue is considered a little price to
> pay for the optimization, since we rarely use string mutations..
>
> The issue can be witnessed with the following code, on 3.10, either in
> the interactive loop or with any compiler:
>
> # let f () = let s = "bla" in let c = s.[0] in s.[0] <- 'c' ; c ;;
> val f : unit -> char = <fun>
> # f () ;;
> - : char = 'b'
> # f () ;;
> - : char = 'c'
>
> This is to be contrasted with arrays, which are mutable too but not
> statically allocated as for strings (let f () = let s =
> [|'b';'l';'a'|] in let c = s.(0) in s.(0) <- 'c' ; c).
>
> And for Erik, a test that tells us that concatenations are not done statically:
>
> # let f () = let s = "b"^"la" in let c = s.[0] in s.[0] <- 'c' ; c ;;
> val f : unit -> char = <fun>
> # f () ;;
> - : char = 'b'
> # f () ;;
> - : char = 'b'
>
> Cheers,
>
> David
>
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

------=_Part_25605_28935324.1201215768108--