[fpc-pascal] PChar & AnsiString

spir ☣ denis.spir at gmail.com
Tue Jun 1 14:28:52 CEST 2010


On Tue, 1 Jun 2010 13:05:16 +0200 (CEST)
Michael Van Canneyt <michael at freepascal.org> wrote:

[...]

Thank you for all answers (all is now clear for me :-).

> > * If a programmer explicitely assigns an existing string to a new variable, the intent is precisely copy-semantics, to make them independent for further changes. If there is no change, there is also no reason for such an assignment.  
> 
> This is not correct. Many strings are simply referenced several times.

May I ask in which typical cases? (I can easily find examples of strings _used_ several times, eg concatenated into larger strings and/or output, but this does not make new references.)
Can only think at the special case of loop variables:
    for i:=0 to persons.count do begin
        name := persons[i].name;
        -- do something with name w/o changing it --
    end;

I find this question (from a larger point of view than strings only) very interesting. Some newer languages, such as Clojure, introduce reference semantics while basically preserving basic value immutability: a different approach. (I do not mean one is better than the other; instead try to understand why either is prefered by some language designers.)


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com



More information about the fpc-pascal mailing list