http://d.puremagic.com/issues/show_bug.cgi?id=3971

           Summary: Syntax & semantics for array assigns
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2010-03-15 14:55:47 PDT ---
This is written in the page about arrays:
http://www.digitalmars.com/d/2.0/arrays.html

s[] = t;      // the 3 elements of t[3] are copied into s[3]
s[] = t[];    // the 3 elements of t[3] are copied into s[3]
s[] = 3;      // same as s[0] = 3, s[1] = 3, s[2] = 3
p[0..2] = 3;  // same as p[0] = 3, p[1] = 3


It's not good to have two different syntaxes to do the same thing, or two
similar syntaxes with a different computational complexity.

So I suggest to modify the array assign syntax this way:


a[] = b[];  static  dynamic
static      OK1     OK1
dynamic     OK1     OK1

a = b[];    static  dynamic
static      Err     Err
dynamic     Err     Err

a[] = b;    static  dynamic
static      Err     Err
dynamic     Err     Err

a = b;      static  dynamic
static      Err2    Err
dynamic     Err     OK2

int i; a=i; static  dynamic
            Err     Err

int i;
a[] = i;    static  dynamic
            OK3     OK3

Key:
  Err =  Syntax error
  OK1 =  Copies all items from an array to the oter.
  OK2 =  Copies just the stuct of the dynamic array, array body not copied.
  OK3 =  Copies the value to all the items of the array.
  Err2 = Syntax error, becase there is no reference to copy, better to keep
tidy the language.


You can see that this too is disallowed:
int a, b;
a = b;

This breaks generic code, but it's not good when the same syntax can be O(1)
(because the same syntax used on dynamic arrays is a O(1)) or O(n), and the too
is different.

If you have comments please add them.

I like that matrix because it contains all cases, so it's easy to see and
design the situation, even if you don't agree with its contents.

The accepted final version of that matrix can even be added back to the arrays
page.

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

Reply via email to