Re: Containers - nontrivial element access



On Wed, 03 Oct 2007 18:49:58 GMT, Jeffrey R. Carter wrote:

Dmitry A. Kazakov wrote:

This is IMO utterly wrong. The semantics of swapping element's fields is
well-defined independently on the way of access. In question in not the
semantics of, but the syntax sugar, namely an array-like indexing of the
container.

Swapping was only an example. Essentially, the OP was looking for the
ability to do

People.Element (X).Salary := S;

and have it modify the value in the data structure.

Which is no problem if Element is an array field of records having the
field Salary. Ada does not prescribe whether that would be by reference.
AFAIK, the compiler is allowed to rewrite the whole People if it wanted to.

The compiler is free to choose between the decompositions:

":=" (People.Element (X).Salary, 3)
":=" (People.Element (X), ".Salary", 3)
":=" (People, "Element", X, "Salary", 3)

This freedom is not offered to the developer of a component library.

C++ uses reference semantics, so that a modification of a field modifies
the value in the data structure. Ada uses value semantics, so that
modification of a field does not modify the value in the data structure.

? For by-value things Ada compiler just does copy-out / copy-in,
transparently.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: Is C99 the final C? (some suggestions)
    ... This would violate the division between preprocessor and compiler too ... much (the preprocessor would have to understand quite a lot of C semantics). ... ...This is legal C (as per the Standard), but it overflows the stack on ...
    (comp.lang.c)
  • Re: Legit Warnings or not
    ... vs. equality) are parts of the semantics, ... rather than to rely on the compiler. ... I want Ada to remain a universal programming ...
    (comp.lang.ada)
  • Re: Source to Source compilation - targeting C?
    ... high level language (syntax and semantics) to target C as the output? ... Does the ROSE compiler framework do this? ... you don't really need "code generation knowledge" to target C, ... and mostly "unwinding" this into C style syntax and semantics ...
    (comp.compilers)
  • Re: left-to-right (was In-Out Parameters for functions)
    ... >> The question is what gets lost if an evaluation order is fixed. ... What I would expect from a good compiler is factoring out the cycle ... There is no need to check program semantics very precisely. ... language may simply outlaw "pure" functions like: ...
    (comp.lang.ada)
  • Re: Glasgow haskell vs. Lispworks
    ... gotos with block structured programming and the harmfulness of goto ... How many languages even have formally-defined semantics that a compiler must ... And WRT to your dislike of Haskell: ...
    (comp.lang.functional)