From: "David Baelde" <david.baelde@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Concatenation of static strings?
Date: Sat, 19 Jan 2008 11:55:11 +0100 [thread overview]
Message-ID: <53c655920801190255p71346ac9ka45adf0e1cef2d17@mail.gmail.com> (raw)
In-Reply-To: <20080119143259.46752d11.mle+ocaml@mega-nerd.com>
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
next prev parent reply other threads:[~2008-01-19 10:55 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 [this message]
2008-01-24 23:02 ` Ashish Agarwal
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=53c655920801190255p71346ac9ka45adf0e1cef2d17@mail.gmail.com \
--to=david.baelde@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