Value vs. reference semantics, and pointers
Scott L. Burson
Scott_member at pathlink.com
Tue Mar 21 00:14:15 PST 2006
Hi,
As a newcomer to D I want to say first that it looks like a very clean and
well-thought-out design, free of the endless frustrations of C++. As a Lisp
fanatic, I am particularly glad to see that you have included local functions,
function literals, and closures, though the distinction between function
"pointers" and delegates strikes me as superfluous ... oh, I see you are already
considering eliminating it. A couple of other tidbits while I'm on this: the
word "pointer" was always misleading in this context; for example, unlike other
pointers in C, they don't support pointer arithmetic. Better, I would suggest,
to just refer to "function variables", or maybe just stick to "delegates" since
you've adopted that term. Similarly, I would discourage the use of the
ampersand to reify a function; I think the ampersand should at least be optional
(as indeed it is in C) -- I don't see anything in the docs that says it's
required, but you seem to use it in all the examples. (My own preference would
be not even to allow it, or failing that, to deprecate it.) And thirdly, your
use of the phrase "dynamic closure" is surprising to me -- in Lisp parlance,
these are _lexical_ closures, specifically distinguished from dynamic closures
(in our sense of the term), which are considered an archaic kludge, not even
implemented in modern Lisps. So I'm wondering how the word "dynamic" got in
there. But this is a very minor quibble :)
I've been skimming the material on the D Web site and want to be sure I
understand some things. I gather that structs and unions have value semantics,
while arrays and classes have reference semantics. That is, assignment to a
variable of struct or union type copies the contents, while assignment to a
variable of array or class type copies a reference to the contents. Is that
correct? You might want to clarify this in the docs, as it's pretty
fundamental.
I also have a question about the treatment of pointers. I understand that
out/inout parameters and reference semantics for classes and arrays will
eliminate the vast majority of occasions calling for explicit pointers, but
still, I'm curious. In D, can you make a pointer to a single object as in C, or
does it have to be in an array?
Cheers,
Scott
More information about the Digitalmars-d
mailing list