[Issue 6253] Refuse definition too of impossible associative arrays

2012-04-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253



--- Comment #8 from bearophile_h...@eml.cc 2012-04-17 13:35:45 PDT ---
One more comment:

http://forum.dlang.org/thread/mailman.1834.1334688099.4860.digitalmar...@puremagic.com#post-wnepqlefxamfbhddpaqs:40forum.dlang.org


This bug report is based on this idea:
http://en.wikipedia.org/wiki/Principle_of_least_astonishment

If I define:
Foo[] a;
I expect those Foo items to be mutable.

If I see:
int[Foo]
I expect those Foo keys to be mutable.

If I see:
immutable(Foo)[] a;
I expect those Foos to be immutable.

If I see:
int[immutable Foo]
I expect those Foo keys to be immutable.

If I see a int[Foo] and I get immutable Foo keys, I am astonished.

Not doing what I am saying here will add another special case to D language.
Avoiding many special cases is a reasons to choose D over C++.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-03-20 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253



--- Comment #7 from Stewart Gordon s...@iname.com 2012-03-20 15:45:53 PDT ---
(In reply to comment #5)
 Does (In reply to comment #4)
 AA keys don't have to be immutable, they just have to be a type 
 that implicitly converts to immutable.  This is the same 
 requirement for parameters of strongly pure functions.
 
 Does this mean AA keys should be stored as immutable internally?

Yes.  A given key in the AA should never change on any level.  Having the key
type fully immutable (even if declared merely as tail-immutable) would enable
it to be passed around by reference as immutable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-03-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253


hst...@quickfur.ath.cx changed:

   What|Removed |Added

 CC||hst...@quickfur.ath.cx


--- Comment #5 from hst...@quickfur.ath.cx 2012-03-19 20:45:56 PDT ---
Does (In reply to comment #4)
 AA keys don't have to be immutable, they just have to be a type that 
 implicitly
 converts to immutable.  This is the same requirement for parameters of 
 strongly
 pure functions.

Does this mean AA keys should be stored as immutable internally?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-03-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253



--- Comment #6 from yebblies yebbl...@gmail.com 2012-03-20 16:48:54 EST ---
(In reply to comment #5)
 Does (In reply to comment #4)
  AA keys don't have to be immutable, they just have to be a type that 
  implicitly
  converts to immutable.  This is the same requirement for parameters of 
  strongly
  pure functions.
 
 Does this mean AA keys should be stored as immutable internally?

I'd say yes, tail-immutable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-02-18 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253



--- Comment #3 from bearophile_h...@eml.cc 2012-02-18 05:11:07 PST ---
A partially contrary point of view by Ben Davis:

 Static arrays have value semantics, so char[4] is no more mutable than
 int would be. So if I'm required to write

 Chunk[immutable(char[4])]

 then I should also be required to write

 Chunk[immutable(int)]

 which clearly isn't the case.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-02-18 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

 CC||yebbl...@gmail.com


--- Comment #4 from yebblies yebbl...@gmail.com 2012-02-19 00:27:56 EST ---
AA keys don't have to be immutable, they just have to be a type that implicitly
converts to immutable.  This is the same requirement for parameters of strongly
pure functions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-01-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253


Stewart Gordon s...@iname.com changed:

   What|Removed |Added

 CC||s...@iname.com


--- Comment #2 from Stewart Gordon s...@iname.com 2012-01-07 06:38:51 PST ---
 (In reply to comment #0)
 This program:
 
 void main() {
 bool[int[]] aa;
 aa[[1, 2]] = true; // line 3
 }
 
 With DMD 2.053 gives a compile time-error:
 test.d(3): Error: associative arrays can only be assigned values 
 with immutable keys, not int[]

If all the elements of an array literal bind to immutable types, then 
so ought to whole array literal.

 I think this is bad, and not intuitive.  I suggest to make DMD 
 refuse this definition too:
 bool[int[]] aa;

Agreed.

 And accept this, and similar:
 bool[const(int)[]] aa;

Which should actually declare aa to be a bool[immutable(int)[]], 
given that that's the only thing it will allow you to put in.

BTW the current behaviour (DMD 2.056) is actually rather weird:
--
pragma(msg, (bool[int[]]).stringof);
pragma(msg, (bool[const(int)[]]).stringof);
pragma(msg, (bool[immutable(int)[]]).stringof);
pragma(msg, (bool[const(int[])]).stringof);
pragma(msg, (bool[immutable(int[])]).stringof);
--
C:\Users\Stewart\Documents\Programming\D\d2\testsdmd -c aa_array_param_type.d
bool[const(int)[]]
bool[const(int)[]]
bool[immutable(int)[]]
bool[const(int)[]]
bool[immutable(int[])]
--

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6253] Refuse definition too of impossible associative arrays

2012-01-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6253



--- Comment #1 from bearophile_h...@eml.cc 2012-01-03 14:19:45 PST ---
Two other persons agree:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learnarticle_id=31374

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---