www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Some attributes

reply bearophile <bearophileHUGS lycos.com> writes:
Few new attributes that can be invented:

 readonly (transitive): like  pure but less restricting, the variables in outer
scopes can be read but not written. It's a way to essentially implement "const"
functions, that like class/struct members can't modify the instance but can
read it. This can be useful for pre/post conditions, and invariants.

 noheap (transitive): doesn't perform heap activity. It disallows memory
allocations, object creations, AA writes, array concat and append/extend,
std.stdlib.malloc/calloc, and the like. It can be useful for code that has to
be fast, to be sure it doesn't allocate on the heap, because they can be a
little slow (if the GC is not very good). Game developers can appreciate this.

 nocommutative, to "disable" the commutativity of an operator overloading, like
+ or *, so it becomes like the + and * of floating point values. It's useful
for example if you want to implement Clifford algebras. With the new operator
overloading regime it becomes a less easy to design this attribute.


The language can even give the tools (with some static reflection) to let a D
programmers to write such attributes.

Bye,
bearophile
Mar 17 2010
parent reply Don <nospam nospam.com> writes:
bearophile wrote:
 Few new attributes that can be invented:
  nocommutative, to "disable" the commutativity of an operator overloading,
like + or *, so it becomes like the + and * of floating point values. It's
useful for example if you want to implement Clifford algebras. With the new
operator overloading regime it becomes a less easy to design this attribute.
The new operator overloading doesn't have commutativity by default, so we don't need this (BTW + and * are commutative in floating point, it's associativity that doesn't hold).
Mar 17 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Don:
 The new operator overloading doesn't have commutativity by default,
I didn't know this (and the op overload page doesn't state it. I think future D front-end rewriters will need to know this).
(BTW + and * are commutative in floating point, it's associativity that doesn't
hold).<
And distributivity too doesn't hold. I am sorry, I have read this in the past, and I have forgotten. Thank you very much Don. Bye, bearophile
Mar 17 2010