Version française
Home     About     Download     Resources     Contact us    
Browse thread
Concatenation of static strings?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Concatenation of static strings?
Zitat von Jon Harrop <jon@ffconsultancy.com>:

> On Thursday 24 January 2008 23:02:48 Ashish Agarwal wrote:
> > 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).
>
> This is not considered a bug. String literals are static but array
> literals
> are not.

?!

>
> > Given that s is locally scoped within f, I do not see why f returns
> > different answers.
>
> A static local remains the same between calls (so it is not
> thread-safe).
[...]

To have mutable strings, which means it's imperative, not
functional programming, is one thing.

To -- in C-langauge terms -- copy the reference,
meaning a copy of a char*, which means a pointer,
is one thing. So one can use String.copy to have
a copy of the data, which is pointed to by the pointer
(isntead of only using a pointer-copy).

Another thing is, that the local used data is
not fresh every time it is used in a newly function call.

The copy of the references is fast.
To have no newly allocated local data,
if this data is a string, IMHO is not so fine.
And I see no advantages here.
And because it's new to me (nobody is pefect ;-))
I thought this is buggy behaviour.

I looked into the reference manual and found nothing on that
topic. Such decisions IMHO should be part of the reference manual.
The thing we discussed on the Array-comparisons btw should also
be mentioned in the manual (I did not looked for it in the manual,
possibly it's already there?).


>
> This has been discussed before several times. The reason given more
> making
> strings static is performance.
[...]

I remember several discussions on mutable strings
and the string-copy problem, but I do not remember
on the problem of the allocation inside functions,
which you call static. And this two kinds of discussions
are two pairs of shoes!

If you have a pointer to theese discussions (on that "static"
thing that makes frozen local data even on several function calls)
this would be fine. It seems I have missed these discussions.

Ciao,
   Oliver