Browse thread
Concatenation of static strings?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | David Baelde <david.baelde@g...> |
| Subject: | Re: [Caml-list] Concatenation of static strings? |
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