Thread overview
tail const ?
Oct 29, 2014
sclytrack
Oct 30, 2014
Simon A
Oct 30, 2014
sclytrack
Oct 30, 2014
sclytrack
Nov 01, 2014
Dicebot
October 29, 2014
As Stewart Gordon mentioned before (2012)

What about adding tailConst to the D programming language?


tailConst MyStruct a;

All fields of the MyStruct would be tailConst and ...



tailConst MyClass b;

would make the the pointer mutable but all the fields of b const.



...tailImmutable, ...
October 30, 2014
I don't know about syntax, but D sure needs first-class support of tail immutability.

Take this code for example:

---

immutable class C
{
	void foo()
	{
		//
	}
}

void main()
{
	auto c = new C();
	c.foo();
}

---

Compile it and get

Error: immutable method C.foo is not callable using a mutable object

Why?  Because foo() is immutable and demands an immutable this reference.  The C instance c is only tail immutable, which doesn't really count for anything.  (So, "new C()" instead of "new immutable(C)()" is legal but pretty much unusable, it seems.)

But why should *any* function require an immutable reference, as opposed to a tail immutable reference?  (Similarly for shared vs tail shared.)
October 30, 2014
On Thursday, 30 October 2014 at 10:28:42 UTC, Simon A wrote:
> I don't know about syntax, but D sure needs first-class support of tail immutability.


struct A
{

}
October 30, 2014
On Thursday, 30 October 2014 at 10:28:42 UTC, Simon A wrote:
> I don't know about syntax, but D sure needs first-class support of tail immutability.
>

struct A
{
  float * a;

  void foo() tailconst
  {
     writeln(typeof(a).stringof);  //outputs "const(float) *"
  }
}


class B
{
  float * a;

  void foo() tailconst
  {
     writeln(typeof(this).stringof);  //outputs "tailconst(B)"
     writeln(typeof(a).stringof);     //outputs "const float *"
  }
}

tailconst for struct and classes.

How about this?


*sorry about the previous almost empty post.


November 01, 2014
http://dlang.org/phobos/std_typecons.html#.Rebindable