Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 16:01:26 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 16 February 2016 at 15:33:03 UTC, Jonathan M Davis wrote: So, having @mutable would be far better than having it be defined behavior to cast away const and mutate (assuming that the underlying data is mutable

Re: Head Const

2016-02-16 Thread bitwise via Digitalmars-d
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 15:33:03 UTC, Jonathan M Davis wrote: const guarantees that the data will not be mutated via that reference to the data. It guarantees nothing about other references to that data. For that, you need immutable. Yes, it's as weak as C++ const in most cases from

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 06:04:42 UTC, Jonathan M Davis wrote: On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 15:12:00 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 16 February 2016 at 15:10:40 UTC, Timon Gehr wrote: Legal. Ouch... :-/ const guarantees that the data will not be mutated via that reference to the data. It guarantees nothing about other references to

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 15:10:40 UTC, Timon Gehr wrote: Legal. Ouch... :-/

Re: Head Const

2016-02-16 Thread Timon Gehr via Digitalmars-d
On 16.02.2016 14:41, Ola Fosheim Grøstad wrote: On Tuesday, 16 February 2016 at 13:35:56 UTC, Dicebot wrote: matter how it is designed. Once you start considering it, you are better at simply throwing away existing const system and starting it all from scratch with D3. Logical const is harmful

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 13:35:56 UTC, Dicebot wrote: matter how it is designed. Once you start considering it, you are better at simply throwing away existing const system and starting it all from scratch with D3. Logical const is harmful as it doesn't give and serious guarantees but

Re: Head Const

2016-02-16 Thread Dicebot via Digitalmars-d
disaster of much higher destructive impact than head const. I am very opposed to it no matter how it is designed. Once you start considering it, you are better at simply throwing away existing const system and starting it all from scratch with D3. Logical const is harmful as it doesn't give an

Re: Head Const

2016-02-16 Thread ZombineDev via Digitalmars-d
On Tuesday, 16 February 2016 at 10:17:05 UTC, Jonathan M Davis wrote: On Tuesday, 16 February 2016 at 10:06:12 UTC, ZombineDev wrote: Another bonus to introducing the mutable keyword is the option to make everything immutable by default (in a future version of D) and allow the users to have

Re: Head Const

2016-02-16 Thread Marc Schütz via Digitalmars-d
On Tuesday, 16 February 2016 at 11:27:56 UTC, Dicebot wrote: On 02/16/2016 12:48 AM, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make

Re: Head Const

2016-02-16 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 16 February 2016 at 10:32:45 UTC, Timon Gehr wrote: struct S{ int[] a; void foo()headconst{ a[0]=1; // ok // arr.length=2 // error } } void main(){ headconst(S) s([0,2,3]); s.foo(); assert(s.a==[1,2,3]); } How to do this in the library?

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 12:15:03 UTC, Ola Fosheim Grøstad wrote: Common wisdom is to compile to a high level IR first. In the case of C++ it has worked out ok for clang. That does not mean that there are no benefits to using a high level IR. Let me expand on this: 1. it makes the

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 12:03:48 UTC, ZombineDev wrote: familiar with implementation details and even don't seem to have any experience in writting large programs in D, because Of course I don't. My goal for D is that it becomes a solid base language which it makes sense to build

Re: Head Const

2016-02-16 Thread ZombineDev via Digitalmars-d
On Tuesday, 16 February 2016 at 11:02:38 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 16 February 2016 at 10:17:05 UTC, Jonathan M Davis wrote: version of D. We don't know what we're going to want to do at that point, and if we're actually willing to break backwards compatibility in a serious

Re: Head Const

2016-02-16 Thread Dicebot via Digitalmars-d
On 02/16/2016 12:48 AM, Walter Bright wrote: > rears its head again :-) > > Head Const is what C++ has for const, i.e. it is not transitive, applies > to one level only. D has transitive const. > > What head const will do for us: > > 1. make it easy to interface to

Re: Head Const

2016-02-16 Thread Timon Gehr via Digitalmars-d
On 16.02.2016 11:17, Jonathan M Davis wrote: On Tuesday, 16 February 2016 at 10:06:12 UTC, ZombineDev wrote: Another bonus to introducing the mutable keyword is the option to make everything immutable by default (in a future version of D) and allow the users to have mutable objects only if they

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 10:17:05 UTC, Jonathan M Davis wrote: version of D. We don't know what we're going to want to do at that point, and if we're actually willing to break backwards compatibility in a serious way, what D2 looks like doesn't really matter much for D3. And we don't

Re: Head Const

2016-02-16 Thread ZombineDev via Digitalmars-d
On Tuesday, 16 February 2016 at 10:09:19 UTC, Jonathan M Davis wrote: On Tuesday, 16 February 2016 at 09:45:34 UTC, ZombineDev wrote: On Tuesday, 16 February 2016 at 08:03:31 UTC, Jonathan M Davis wrote: ... Given that very few optimizations can be made based solely on const (and I'm not sure

Re: Head Const

2016-02-16 Thread Timon Gehr via Digitalmars-d
On 16.02.2016 01:14, H. S. Teoh via Digitalmars-d wrote: Just out of curiosity, since we already have Rebindable in Phobos and HeadConst is being proposed, what are the disadvantages / shortcomings of a library solution that would justify adding yet another feature to the language? struct S{

Re: Head Const

2016-02-16 Thread Guillaume Piolat via Digitalmars-d
On Tuesday, 16 February 2016 at 01:04:44 UTC, Walter Bright wrote: 2. supports single assignment style of programming, even if the data is otherwise mutable Like 'final'? We did get rid of that... Maybe we should resurrect it. I'm trying to say it politely. D2 const story is more

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 10:06:12 UTC, ZombineDev wrote: Another bonus to introducing the mutable keyword is the option to make everything immutable by default (in a future version of D) and allow the users to have mutable objects only if they use the mutable keyword. While some folks

Re: Head Const

2016-02-16 Thread ZombineDev via Digitalmars-d
On Tuesday, 16 February 2016 at 09:39:31 UTC, Sönke Ludwig wrote: Am 16.02.2016 um 08:20 schrieb Ola Fosheim Grøstad: On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 09:45:34 UTC, ZombineDev wrote: On Tuesday, 16 February 2016 at 08:03:31 UTC, Jonathan M Davis wrote: ... Given that very few optimizations can be made based solely on const (and I'm not sure that the compiler currently does any of them) ... I think that the

Re: Head Const

2016-02-16 Thread ZombineDev via Digitalmars-d
On Tuesday, 16 February 2016 at 08:03:31 UTC, Jonathan M Davis wrote: ... Given that very few optimizations can be made based solely on const (and I'm not sure that the compiler currently does any of them) ... I think that the fact that we have shared can help a lot in the area of

Re: Head Const

2016-02-16 Thread Sönke Ludwig via Digitalmars-d
Am 16.02.2016 um 08:20 schrieb Ola Fosheim Grøstad: On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
On Tuesday, 16 February 2016 at 09:04:48 UTC, Daniel Murphy wrote: I'm starting to think we should give up on implementing C++ support in the language and move it to the library. eg mixin(cppFunctionBinding("unsigned long long NameSpace::myFunc(char * const && x, long double y)"); expands

Re: Head Const

2016-02-16 Thread Daniel Murphy via Digitalmars-d
On 16/02/2016 12:04 PM, Walter Bright wrote: It's currently difficult to interface with C++, and always will be, but smoothing out what we can can be a big opportunity for D. I'm starting to think we should give up on implementing C++ support in the language and move it to the library. eg

Re: Head Const

2016-02-16 Thread Walter Bright via Digitalmars-d
On 2/15/2016 10:04 PM, Jonathan M Davis wrote: Straight up head-const is utterly useless IMHO. That's what Java has. C++ has something far more complicated where any individual piece (or pieces) of a pointer type can be declared const without necessarily making the whole thing const. So, _that_

Re: Head Const

2016-02-16 Thread Ola Fosheim Grøstad via Digitalmars-d
overloaded C++ functions. Like, some C++ functions implements transitive const, others do head const combined with mutable. So it is insufficient to look at the C++ sigature... Which means D ought to have some stronger way to specifing constness for C++ signatures than C++ provides. But even

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 07:20:00 UTC, Ola Fosheim Grøstad wrote: On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head

Re: Head Const

2016-02-16 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 16 February 2016 at 07:46:11 UTC, w0rp wrote: I think if we could avoid putting head const in the language, we'd be better off. If you ever really, really need to mutate something inside a const type, you can cast away const. It will rightly look ugly, and the compiler can complain

Re: Head Const

2016-02-15 Thread w0rp via Digitalmars-d
protection from the compiler from stopping the objects in the inside from being mutated. The way I see it, C++ const is a weaker form of const which doesn't complain about mutations enough. I think if we could avoid putting head const in the language, we'd be better off. If you ever really

Re: Head Const

2016-02-15 Thread Ola Fosheim Grøstad via Digitalmars-d
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses

Re: Head Const

2016-02-15 Thread Jonathan M Davis via Digitalmars-d
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses

Re: Head Const

2016-02-15 Thread rsw0x via Digitalmars-d
On Tuesday, 16 February 2016 at 01:04:44 UTC, Walter Bright wrote: On 2/15/2016 4:15 PM, Daniel Murphy wrote: 1. make it easy to interface to C++ code that uses const, as currently it is not very practical to do so, you have to resort to pragma(mangle) I'd much rather improve pragma(mangle)

Re: Head Const

2016-02-15 Thread Chris Wright via Digitalmars-d
On Mon, 15 Feb 2016 16:57:44 -0800, H. S. Teoh via Digitalmars-d wrote: > What about besides C++ integration? 'cos I remember some people were > complaining that a library solution is bad, but I've forgotten what the > reasons were. The first problem mentioned was C++ integration, and the

Re: Head Const

2016-02-15 Thread Walter Bright via Digitalmars-d
On 2/15/2016 4:15 PM, Daniel Murphy wrote: 1. make it easy to interface to C++ code that uses const, as currently it is not very practical to do so, you have to resort to pragma(mangle) I'd much rather improve pragma(mangle) than add more C++ features to D. It's currently difficult to

Re: Head Const

2016-02-15 Thread H. S. Teoh via Digitalmars-d
On Tue, Feb 16, 2016 at 12:21:38AM +, Chris Wright via Digitalmars-d wrote: > On Mon, 15 Feb 2016 16:14:23 -0800, H. S. Teoh via Digitalmars-d wrote: > > Just out of curiosity, since we already have Rebindable in Phobos > > and HeadConst is being proposed, what are the disadvantages / > >

Re: Head Const

2016-02-15 Thread Chris Wright via Digitalmars-d
On Mon, 15 Feb 2016 16:14:23 -0800, H. S. Teoh via Digitalmars-d wrote: > Just out of curiosity, since we already have Rebindable in Phobos and > HeadConst is being proposed, what are the disadvantages / shortcomings > of a library solution that would justify adding yet another feature to > the

Re: Head Const

2016-02-15 Thread Daniel Murphy via Digitalmars-d
On 16/02/2016 9:48 AM, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses const, as currently

Re: Head Const

2016-02-15 Thread H. S. Teoh via Digitalmars-d
On Mon, Feb 15, 2016 at 11:45:26PM +, ZombineDev via Digitalmars-d wrote: [...] > >I used the term "tail const" as a mutable pointer/reference to > >const/immutable object, where transitivity starts from the object > >(not from the pointer, which is what currently happens if you type > >`const

Re: Head Const

2016-02-15 Thread Laeeth Isharc via Digitalmars-d
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses

Re: Head Const

2016-02-15 Thread ZombineDev via Digitalmars-d
solutions in this area: HeadConst [1] - PR pending, and Rebindable (tail const) [2] - already part of Phobos. Maybe if the language could express head const, it also makes sense to have tail const. [1]: https://github.com/D-Programming-Language/phobos/pull/3862 [2]: http://dlang.org/phobos

Re: Head Const

2016-02-15 Thread Walter Bright via Digitalmars-d
On 2/15/2016 3:39 PM, ZombineDev wrote: I used the term "tail const" as a mutable pointer/reference to const/immutable object, where transitivity starts from the object (not from the pointer, which is what currently happens if you type `const Object o`). Makes sense.

Re: Head Const

2016-02-15 Thread ZombineDev via Digitalmars-d
, and Rebindable (tail const) [2] - already part of Phobos. Maybe if the language could express head const, it also makes sense to have tail const. [1]: https://github.com/D-Programming-Language/phobos/pull/3862 [2]: http://dlang.org/phobos-prerelease/std_typecons.html#.Rebindable Transitive const

Re: Head Const

2016-02-15 Thread Adam D. Ruppe via Digitalmars-d
On Monday, 15 February 2016 at 23:28:28 UTC, Walter Bright wrote: Transitive const is tail const. const(char)[] foo is tail const const(Object) ref is the analog the language is missing so phobos tries to catch up

Re: Head Const

2016-02-15 Thread Walter Bright via Digitalmars-d
if the language could express head const, it also makes sense to have tail const. [1]: https://github.com/D-Programming-Language/phobos/pull/3862 [2]: http://dlang.org/phobos-prerelease/std_typecons.html#.Rebindable Transitive const is tail const.

Re: Head Const

2016-02-15 Thread ZombineDev via Digitalmars-d
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote: rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses

Head Const

2016-02-15 Thread Walter Bright via Digitalmars-d
rears its head again :-) Head Const is what C++ has for const, i.e. it is not transitive, applies to one level only. D has transitive const. What head const will do for us: 1. make it easy to interface to C++ code that uses const, as currently it is not very practical to do so, you have

[Issue 13796] New: A simple array head const struct for Phobos

2014-11-29 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13796 Issue ID: 13796 Summary: A simple array head const struct for Phobos Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement

Dynamic array head const in library code?

2014-11-28 Thread bearophile via Digitalmars-d-learn
In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later don't have to change length nor to be reassigned, but I have to

Re: Dynamic array head const in library code?

2014-11-28 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Friday, 28 November 2014 at 10:55:27 UTC, bearophile wrote: In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later

Re: Dynamic array head const in library code?

2014-11-28 Thread bearophile via Digitalmars-d-learn
Dominikus Dittes Scherkl: Why you don't use static arrays for such a purpose? I thought this is exactly what they are made for, aren't they? Currently you can't create a static array with a length known only at run-time. And passing around a fixed-size arrays has some costs. Bye,

Re: Dynamic array head const in library code?

2014-11-28 Thread John Colvin via Digitalmars-d-learn
On Friday, 28 November 2014 at 10:55:27 UTC, bearophile wrote: In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later

Re: Access to fixed memory locations, head const, ...

2009-11-30 Thread Kuba Ober
I'm contemplating using D for an embedded project where system configuration registers have fixed memory locations. One way of doing it would be to have a constant pointer to a structure with manually aligned members that match the register map, and access them like that. This becomes

Re: Access to fixed memory locations, head const, ...

2009-11-28 Thread wakko
Hi, I'm contemplating using D for an embedded project where system configuration registers have fixed memory locations. One way of doing it would be to have a constant pointer to a structure with manually aligned members that match the register map, and access them like that. This becomes

Access to fixed memory locations, head const, ...

2009-11-27 Thread Kuba Ober
Hi, I'm contemplating using D for an embedded project where system configuration registers have fixed memory locations. One way of doing it would be to have a constant pointer to a structure with manually aligned members that match the register map, and access them like that. This becomes

<    1   2