www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Provide immutable attribute for first-class citizens and namespaces?

reply "Daniel Fitzpatrick" <doubleagent03 gmail.com> writes:
A few languages out there provide immutability by default.  I'm 
on board with D not providing it by default, but would it be 
useful or worth the effort to add an  immutable attribute to 
first class citizens and namespaces eg

// All members & fn returns immutable by default in each case
 immutable module my.ns;
 immutable class foo { .. }
 immutable struct bar { .. }

Additionally,

module blah;
 const import std.algorithm; // All return refs/vals & public 
members from std.algorithm treated as immutable within blah

I hesitated to post this since I haven't done much with D, so I 
hope I'm not insulting anyone (I have great respect for you all - 
you were very helpful when I was trying to learn the language).  
No idea how hard this is.  Thoughts?
Apr 13 2012
parent reply deadalnix <deadalnix gmail.com> writes:
Le 14/04/2012 08:56, Daniel Fitzpatrick a écrit :
 A few languages out there provide immutability by default. I'm on board
 with D not providing it by default, but would it be useful or worth the
 effort to add an  immutable attribute to first class citizens and
 namespaces eg

 // All members & fn returns immutable by default in each case
  immutable module my.ns;
  immutable class foo { .. }
  immutable struct bar { .. }

 Additionally,

 module blah;
  const import std.algorithm; // All return refs/vals & public members
 from std.algorithm treated as immutable within blah

 I hesitated to post this since I haven't done much with D, so I hope I'm
 not insulting anyone (I have great respect for you all - you were very
 helpful when I was trying to learn the language). No idea how hard this
 is. Thoughts?
« immutable: » can't do the trick ? BTW, this proposal is a bit problematic without a mutable keyword.
Apr 14 2012
parent reply "Daniel Fitzpatrick" <doubleagent03 gmail.com> writes:
 « immutable: » can't do the trick ?
Do you mean to extend the immutable keyword instead of adding an attribute, or that the immutable keyword, as is, is enough? I'm fine with the former. The latter is problematic. Think turnabout - would you enjoy having to mark all of your variables 'mutable' when you wanted them like that? As it is, that would add a ton of declarations to the standard library.
 BTW, this proposal is a bit problematic without a mutable 
 keyword.
I thought about this: I wouldn't be interested in it. I would be interested in a library which provided containers with different semantics for atomic mutation. What Clojure provides is pretty spot on: http://clojure.org/refs http://clojure.org/agents http://clojure.org/atoms
Apr 14 2012
parent reply "Daniel Fitzpatrick" <doubleagent03 gmail.com> writes:
On Saturday, 14 April 2012 at 17:50:01 UTC, Daniel Fitzpatrick 
wrote:
 « immutable: » can't do the trick ?
Do you mean to extend the immutable keyword instead of adding an attribute, or that the immutable keyword, as is, is enough? I'm fine with the former. The latter is problematic. Think turnabout - would you enjoy having to mark all of your variables 'mutable' when you wanted them like that? As it is, that would add a ton of declarations to the standard library.
 BTW, this proposal is a bit problematic without a mutable 
 keyword.
I thought about this: I wouldn't be interested in it. I would be interested in a library which provided containers with different semantics for atomic mutation. What Clojure provides is pretty spot on: http://clojure.org/refs http://clojure.org/agents http://clojure.org/atoms
Okay...yes. I hadn't thought about using attributes in that way. Maybe this is a nonissue. :)
Apr 14 2012
parent "Daniel Fitzpatrick" <doubleagent03 gmail.com> writes:
http://dlang.org/attribute.html is what I'm referencing.
 Okay...yes.

 I hadn't thought about using attributes in that way.  Maybe 
 this is a nonissue.  :)
Apr 14 2012