Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Ashish Agarwal" <agarwal1975@gmail.com>
To: caml-list@yquem.inria.fr
Cc: david.baelde@ens-lyon.org
Subject: Re: [Caml-list] Concatenation of static strings?
Date: Thu, 24 Jan 2008 18:02:48 -0500	[thread overview]
Message-ID: <d8be5ae20801241502q5190bcceje287e1f224d5648a@mail.gmail.com> (raw)
In-Reply-To: <53c655920801190255p71346ac9ka45adf0e1cef2d17@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2110 bytes --]

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
>

[-- Attachment #2: Type: text/html, Size: 2945 bytes --]

  reply	other threads:[~2008-01-24 23:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19  3:32 Erik de Castro Lopo
2008-01-19  6:50 ` [Caml-list] " David Allsopp
2008-01-19  7:36   ` Erik de Castro Lopo
2008-01-19 10:55 ` David Baelde
2008-01-24 23:02   ` Ashish Agarwal [this message]
2008-01-25  1:57     ` Oliver Bandel
2008-01-25 10:47       ` Loup Vaillant
2008-01-26 13:27         ` Ashish Agarwal
2008-01-26 16:13     ` Jon Harrop
2008-01-26 19:58       ` Oliver Bandel

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=d8be5ae20801241502q5190bcceje287e1f224d5648a@mail.gmail.com \
    --to=agarwal1975@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=david.baelde@ens-lyon.org \
    /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