www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Part 1 of the Language Reference Docs Review

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
--0016e6546df00b058c0489e35a2e
Content-Type: text/plain; charset=ISO-8859-1

Hello,

This is Part 1 of the language spec documentation review which I'm doing. So
far I've covered maybe 1/3rd of the links in the spec docs.

I am going to make a bug report for this, but I was thinking it might be a
good idea if someone could review my findings first (Let me know if you want
the bug report right away and I will do one asap.). Some of these could
likely be my own mistakes, or my misinterpretation of the docs.

The first column is the link to the docs section, the next indentation is
the relevant subsection title (you'll have to do a CTRL+F to find the code
examples, there's not that many 'href' anchors in the html docs, sorry), and
the next indent are the errors/comments. When I say "example" in the text, I
mean the relevant code example from the docs.

All of these examples were tested with DMD 2.046 on XP-32bit, unfortunately
I had trouble setting up DSSS in Ubuntu (and I'm too lazy to make makefiles)
so I didn't test on that platform.

So, here's the copypasta:

http://www.digitalmars.com/d/2.0/module.html
    "Mixin Declaration"
        This should be moved to the "Declarations" section.


http://www.digitalmars.com/d/2.0/declaration.html
    "Aliases cannot be used for expressions"
        The code example compiles even though it says it is illegal.


http://www.digitalmars.com/d/2.0/type.html
    "Implicit Conversions"
        Last line in the example:
            f = E;
        E is undefined, the line should be:
            f = Foo.E;

    "Delegates"
        In the example, assigning the address of a function to a
        function pointer gives a compilation error:
            Error: cannot implicitly convert expression
            (&func) of type int delegate(int) to int function(int)


http://www.digitalmars.com/d/2.0/property.html
    ".init Property"
        "Foo.b.init" is 0, not 7.

    ".stringof Property"
        Example contains two lines refering to "test.Foo",
        but "test" isn't declared anywhere.
        The compiler output is different too.

        The lines should be replaced with:
            writefln((1+2).stringof);       // "1 + 2"
            writefln(Foo.stringof);         // "Foo"
            writefln(int.stringof);         // "int"
            writefln((int*[5][]).stringof); // "int*[5u][]"
            writefln(Enum.RED.stringof);    // "Enum
            writefln((5).stringof);         // "5"

    ".sizeof Property"
        Compilation error:
            sizeof_test.d(14): Error: 'this' is only defined in non-static
            member functions, not test

        Maybe a compiler bug? If "int x = S.a.sizeof" is put outside the
        test() function, it will compile.


http://www.digitalmars.com/d/2.0/attribute.html
    "immutable Attribute"
    "__gshared Attribute"
    "shared Attribute"
    "inout Attribute"

    There is missing documentation for these.


http://www.digitalmars.com/d/2.0/expression.html
    "A CatExpression concatenates arrays, producing a dynmaic"
        typo: dynmaic > dynamic.

    "Array Literals"
        Third example from the title:
            writeln(ct);  // writes [1 1]
            writeln(rt);  // writes [257]

        The output is instead:
            1 1
            1 0 1 0

    "is ( Type Identifier )"
        Replace any 'writefln' with 'writeln' (missing format specifiers).

    "is ( Type Identifier : TypeSpecialization )"
        Replace any 'writefln' with 'writeln'.

    "is ( Type Identifier == TypeSpecialization , TemplateParameterList )"
        Replace any 'writefln' with 'writeln'.

http://www.digitalmars.com/d/2.0/statement.html
    "Labeled Statements"
        It states:
            ''Labels are in a name space independent of declarations,
variables,
            types, etc. Even so, labels *cannot* have the same name as local
            declarations.''

        However this custom example compiles:

        void func() {
            int t;
            t: {
                int xyz;
            }
        }

        So does this one:

        void func() {
            int t;
            xyz: {
                int xyz;
            }
        }

        Perhaps this was meant to state:
            "Declarations *inside* labels cannot have the same name
            as local declarations" ?

    "foreach_reverse"
        IIRC this will be replaced with retro sometime soon? foreach_reverse
        still works though.

    "Foreach over Arrays of Characters"
        First example, these lines:
            char[] a = "\xE2\x89\xA0";    // \u2260 encoded as 3 UTF-8 bytes
            dchar[] b = "\u2260";            // prints 'a[] = 2260'

        Should be replaced with:
            char[] a = "\xE2\x89\xA0".dup;    // \u2260 encoded as 3 UTF-8
bytes
            dchar[] b = "\u2260"d.dup;          // prints 'a[] = 2260'

    "Foreach over Associative Arrays"
        The first example code gives these compiler errors:
            foreach_test.d(38): Error: function

object.AssociativeArray!(const(char)[],double).AssociativeArray.opApply
            (scope int delegate(ref const(char)[], ref double) dg) is not
callable
            using argument types (int delegate(ref double __applyArg0,
            ref char[] __applyArg1))

            foreach_test.d(38): Error: cannot implicitly convert expression
            (__foreachbody524) of type int delegate(ref double __applyArg0,
            ref char[] __applyArg1) to int delegate(ref double)

        Changing the foreach statement like so seems to work:
            double[char[]] a;

            foreach (const (char)[] s, ref double d; a)
            {
                writefln("a['%s'] = %g", s, d);
            }

    "Foreach over Structs and Classes with opApply"
        The sentence:

        "The body of the apply function iterates over the elements it
aggregates"
        Has a typo, change "it aggregates" to "in aggregates".

    "Foreach over Tuples"
        In the first example, replace any 'writefln' with 'writeln'.

        In foreach over arrays it states:
            ''The index must be of int, uint or size_t type''

        In foreach over tuples it states:
            ''The index must be of int or uint type.''

        Is there a reason why one is allowed to be of size_t type,
        and the other is not?

    "Foreach Restrictions"
        The example:
            int[] a;
            int[] b;
            foreach (int i; a)
            {
                a = null;                    // error
                a.length = a.length + 10;    // error
                a = b;                        // error
            }
            a = null;                        // ok

        None of these give compilation errors or warnings.
        Adding memmory allocation statements for a and b before
        entering the loop does not cause any compiler errors, and
        no runtime exceptions are raised.

    "Switch Statement"
        The sentence:
            ''If none of the case expressions match, and there is not a
default
            statement, a [link:std.switcherr.SwitchError] is thrown.''

        The link redirects to a 404 page.
        "std.switcherr.SwitchError" should be replaced
        with "core.exception.SwitchError".

    "Final Switch Statement"
        What is this used for? CTFE maybe? I'm curious. :)

    "Scope Guard Statement"
        In all of the examples under this section
        'writefln' should be replaced with 'writeln',
        and 'writef' with 'write'.

    "Mixin Statement"
        Replace 'writefln' with 'writeln' in the mixin string.

        The line:
            char[] t = "y = 3;";
        Replace it with:
            char[] t = "y = 3;".dup;

        Now only the documentation-relevant errors are shown when compiling.

    "Foreach Range Statement"
        This should be moved up, close to where the other foreach
definitions are.

        In the example code:
            Replace 'writefln' with 'writeln', and 'writef' with 'write'.


http://www.digitalmars.com/d/2.0/arrays.html
    "Usage"
        The lines:
            p = s;        // p points to the first element of the array s.
            p = a;        // p points to the first element of the array a.

        Give compiler errors:
            Error: cannot implicitly convert expression (s) of
            type int[3u] to int*
            Error: cannot implicitly convert expression (a) of
            type int[] to int*

        Casts work:
            p = cast(int*) s;
            p = cast(int*) a;

        But is that a good workaround? Don't ask me.. :p

    "Array Properties"
        In the first example there are missing declarations.
        Could add these before the first line:
            int* p;
            int[3] s;
            int[] a;

    "Setting Dynamic Array Length"
        From the comments in the first example, it states:
            ''// always resized in place because it is sliced
              // from a[] which has enough memory for 15 chars''

        But in this shorter example:
            char[] a = new char[50];
            char[] b = a[0..10];

            b.length = 11;
            a[3] = 'z';
            writeln(b); // writes 11 default characters

        from my tests, resizing b to any bigger length always creates a
copy,
        regardless of how big the length of a is.

        Resizing to a smaller length (e.g. 8) will keep the reference,
        and b[3] will still refer to a[3] in the example.

        Has the resizing behavior changed recently, or is that comment
inaccurate?

    "Functions as Array Properties"
        From this example code:
            int[] array;
            void foo(int[] a, int x);

            foo(array, 3);
            array.foo(3);    // means the same thing

        The last line does not compile, even when foo() is fully defined:
            Error: undefined identifier module main.foo

    "Array Bounds Checking"
        In the example code, "ArrayBoundsError" should be replaced
        with "RangeError".

    "Static Initialization of Static Arrays"
        For the example code:
            enum Color { red, blue, green };
            int value[Color.max + 1] = [ Color.blue:6, Color.green:2,
Color.red:5 ];

        The documentation states:
            ''These arrays are static when they appear in global scope.
            Otherwise, they need to be marked with const or static
            storage classes to make them static arrays.''

        In non-global scope, the array has to be marked with static in order
        to compile. const alone is not compilable. At least not in my case.

    "Special Array Types"
        The 6th example from the title:
            cast(wchar [])"abc"    // this is an array of wchar characters
            "abc"w                // so is this

        It should probably be noted that the first line returns a copy of
the
        string with type wchar[], while the second line returns a copy(?)
        of the string with type immutable(wchar)[]. But correct me if I'm
wrong with this one.

        The next example has this line:
            w = \r[0];        // w is assigned the carriage return wchar
character
        Needs to be replaced with:
            w = "\r"[0];    // w is assigned the carriage return wchar
character

    "Associative Arrays"
        Accessing a nonexistent key for an AA throws the RangeError
exception.
        Perhaps a different exception should be created for AA's, such as:
            core.exception.KeyNotInAssocArray
        ?

    "Using Classes as the KeyType"
        In the example code, any "f" in a declaration/expression needs to be
        replaced with "foo".

    "Using Structs or Unions as the KeyType"
        The line in the example:
            foreach (char c; s)
        Should be:
            foreach (char c; str)

// end

--0016e6546df00b058c0489e35a2e
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello,<br><br>This is Part 1 of the language spec documentation review whic=
h I&#39;m doing. So far I&#39;ve covered maybe 1/3rd of the links in the sp=
ec docs.<br><br>I am going to make a bug report for this, but I was thinkin=
g it might be a good idea if someone could review my findings first (Let me=
 know if you want the bug report right away and I will do one asap.). Some =
of these could likely be my own mistakes, or my misinterpretation of the do=
cs.<br>
<br>The first column is the link to the docs section, the next indentation =
is the relevant subsection title (you&#39;ll have to do a CTRL+F to find th=
e code examples, there&#39;s not that many &#39;href&#39; anchors in the ht=
ml docs, sorry), and the next indent are the errors/comments. When I say &q=
uot;example&quot; in the text, I mean the relevant code example from the do=
cs.<br>
<br>All of these examples were tested with DMD 2.046 on XP-32bit, unfortuna=
tely I had trouble setting up DSSS in Ubuntu (and I&#39;m too lazy to make =
makefiles) so I didn&#39;t test on that platform.<br><br>So, here&#39;s the=
 copypasta:<br>
<br><a href=3D"http://www.digitalmars.com/d/2.0/module.html">http://www.dig=
italmars.com/d/2.0/module.html</a><br>=A0=A0=A0 &quot;Mixin Declaration&quo=
t;<br>=A0=A0=A0=A0=A0=A0=A0 This should be moved to the &quot;Declarations&=
quot; section.<br>
=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 <br><a href=3D"http://www.d=
igitalmars.com/d/2.0/declaration.html">http://www.digitalmars.com/d/2.0/dec=
laration.html</a><br>=A0=A0=A0 &quot;Aliases cannot be used for expressions=
&quot;<br>=A0=A0=A0=A0=A0=A0=A0 The code example compiles even though it sa=
ys it is illegal.<br>
<br><br><a href=3D"http://www.digitalmars.com/d/2.0/type.html">http://www.d=
igitalmars.com/d/2.0/type.html</a><br>=A0=A0=A0 &quot;Implicit Conversions&=
quot;<br>=A0=A0=A0=A0=A0=A0=A0 Last line in the example:<br>=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 f =3D E;<br>=A0=A0=A0=A0=A0=A0=A0 E is undefined, the li=
ne should be:<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 f =3D Foo.E;<br>=A0=A0=A0 <br>=A0=A0=A0 &=
quot;Delegates&quot;<br>=A0=A0=A0=A0=A0=A0=A0 In the example, assigning the=
 address of a function to a<br>=A0=A0=A0=A0=A0=A0=A0 function pointer gives=
 a compilation error:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Error: cannot im=
plicitly convert expression <br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (&amp;func) of type int delegate(int) to =
int function(int)<br><br>=A0=A0=A0=A0=A0=A0=A0 <br><a href=3D"http://www.di=
gitalmars.com/d/2.0/property.html">http://www.digitalmars.com/d/2.0/propert=
y.html</a><br>=A0=A0=A0 &quot;.init Property&quot;<br>
=A0=A0=A0=A0=A0=A0=A0 &quot;Foo.b.init&quot; is 0, not 7.<br><br>=A0=A0=A0 =
&quot;.stringof Property&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Example contains tw=
o lines refering to &quot;test.Foo&quot;,<br>=A0=A0=A0=A0=A0=A0=A0 but &quo=
t;test&quot; isn&#39;t declared anywhere. <br>
=A0=A0=A0=A0=A0=A0=A0 The compiler output is different too.<br>=A0=A0=A0=A0=
=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 The lines should be replaced with:<br>=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writefln((1+2).stringof);=A0=A0=A0=A0=A0=
=A0 // &quot;1 + 2&quot;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writefln(Foo.=
stringof);=A0=A0=A0=A0=A0=A0=A0=A0 // &quot;Foo&quot;<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writefln(int.stringof);=A0=A0=A0=A0=A0=A0=
=A0=A0 // &quot;int&quot;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writefln((in=
t*[5][]).stringof); // &quot;int*[5u][]&quot;<br>=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0 writefln(Enum.RED.stringof);=A0=A0=A0 // &quot;Enum<br>=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 writefln((5).stringof);=A0=A0=A0=A0=A0=A0=A0=A0 //=
 &quot;5&quot;<br>
<br>=A0=A0=A0 &quot;.sizeof Property&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Compila=
tion error:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 sizeof_test.d(14): Error: =
&#39;this&#39; is only defined in non-static<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0 member functions, not test<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=
=A0=A0=A0=A0=A0=A0=A0 Maybe a compiler bug? If &quot;int x =3D S.a.sizeof&q=
uot; is put outside the<br>
=A0=A0=A0=A0=A0=A0=A0 test() function, it will compile.<br><br><br><a href=
=3D"http://www.digitalmars.com/d/2.0/attribute.html">http://www.digitalmars=
.com/d/2.0/attribute.html</a><br>=A0=A0=A0 &quot;immutable Attribute&quot;<=
br>=A0=A0=A0 &quot;__gshared Attribute&quot;<br>
=A0=A0=A0 &quot;shared Attribute&quot;<br>=A0=A0=A0 &quot;inout Attribute&q=
uot;<br>=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0 There is missing documentation =
for these.<br><br>=A0=A0=A0=A0=A0=A0=A0 <br><a href=3D"http://www.digitalma=
rs.com/d/2.0/expression.html">http://www.digitalmars.com/d/2.0/expression.h=
tml</a>=A0=A0=A0=A0=A0=A0=A0 <br>
=A0=A0=A0 &quot;A CatExpression concatenates arrays, producing a dynmaic&qu=
ot;<br>=A0=A0=A0=A0=A0=A0=A0 typo: dynmaic &gt; dynamic.<br>=A0=A0=A0 <br>=
=A0=A0=A0 &quot;Array Literals&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Third example=
 from the title:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writeln(ct);=A0 // wr=
ites [1 1]<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 writeln(rt);=A0 // writes [257]<br>=A0=A0=
=A0 <br>=A0=A0=A0=A0=A0=A0=A0 The output is instead:<br>=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 1 1<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 1 0 1 0<br>=A0=A0=
=A0 <br>=A0=A0=A0 &quot;is ( Type Identifier )&quot;<br>=A0=A0=A0=A0=A0=A0=
=A0 Replace any &#39;writefln&#39; with &#39;writeln&#39; (missing format s=
pecifiers).<br>
<br>=A0=A0=A0 &quot;is ( Type Identifier : TypeSpecialization )&quot;<br>=
=A0=A0=A0=A0=A0=A0=A0 Replace any &#39;writefln&#39; with &#39;writeln&#39;=
.<br><br>=A0=A0=A0 &quot;is ( Type Identifier =3D=3D TypeSpecialization , T=
emplateParameterList )&quot;<br>
=A0=A0=A0=A0=A0=A0=A0 Replace any &#39;writefln&#39; with &#39;writeln&#39;=
.<br><br><a href=3D"http://www.digitalmars.com/d/2.0/statement.html">http:/=
/www.digitalmars.com/d/2.0/statement.html</a><br>=A0=A0=A0 &quot;Labeled St=
atements&quot;<br>
=A0=A0=A0=A0=A0=A0=A0 It states:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &#39;=
&#39;Labels are in a name space independent of declarations, variables,<br>=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 types, etc. Even so, labels *cannot* have=
 the same name as local<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 declarations.&=
#39;&#39;<br>
<br>=A0=A0=A0=A0=A0=A0=A0 However this custom example compiles:<br><br>=A0=
=A0=A0=A0=A0=A0=A0 void func() {<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int t=
;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 t: {<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 int xyz;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }<br>=A0=
=A0=A0=A0=A0=A0=A0 }<br><br>=A0=A0=A0=A0=A0=A0=A0 So does this one:<br>=A0=
=A0=A0=A0=A0=A0=A0 <br>
=A0=A0=A0=A0=A0=A0=A0 void func() {<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 in=
t t;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 xyz: {<br>=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 int xyz;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }<br=
=A0=A0=A0=A0=A0=A0=A0 }<br>=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0=

t;Declarations *inside* labels cannot have the same name<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 as local declarations&quot; ?<br>=A0=A0= =A0=A0=A0=A0=A0 <br>=A0=A0=A0 &quot;foreach_reverse&quot;<br>=A0=A0=A0=A0= =A0=A0=A0 IIRC this will be replaced with retro sometime soon? foreach_reve= rse<br>=A0=A0=A0=A0=A0=A0=A0 still works though.<br><br>=A0=A0=A0 &quot;For= each over Arrays of Characters&quot;<br> =A0=A0=A0=A0=A0=A0=A0 First example, these lines:<br>=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 char[] a =3D &quot;\xE2\x89\xA0&quot;;=A0=A0=A0 // \u2260 enco= ded as 3 UTF-8 bytes<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 dchar[] b =3D &qu= ot;\u2260&quot;;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // prints &#39;a[] =3D 22= 60&#39;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br> =A0=A0=A0=A0=A0=A0=A0 Should be replaced with:<br>=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 char[] a =3D &quot;\xE2\x89\xA0&quot;.dup;=A0=A0=A0 // \u2260 enc= oded as 3 UTF-8 bytes<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 dchar[] b =3D &q= uot;\u2260&quot;d.dup;=A0=A0=A0=A0=A0=A0=A0=A0=A0 // prints &#39;a[] =3D 22= 60&#39;<br> <br>=A0=A0=A0 &quot;Foreach over Associative Arrays&quot;<br>=A0=A0=A0=A0= =A0=A0=A0 The first example code gives these compiler errors:<br>=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 foreach_test.d(38): Error: function<br>=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 object.AssociativeArray!(const(char)[],double).Ass= ociativeArray.opApply<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (scope int delegate(ref const(char)[], re= f double) dg) is not callable<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 using ar= gument types (int delegate(ref double __applyArg0, <br>=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 ref char[] __applyArg1))<br><br>=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 foreach_test.d(38): Error: cannot implicitly convert expression<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (__foreachbody524) of type int delegate(r= ef double __applyArg0, <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ref char[] __a= pplyArg1) to int delegate(ref double)<br><br>=A0=A0=A0=A0=A0=A0=A0 Changing= the foreach statement like so seems to work:<br>=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 double[char[]] a;<br> <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 foreach (const (char)[] s, ref double= d; a)<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 {<br>=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 writefln(&quot;a[&#39;%s&#39;] =3D %g&quot;, s, d);<b= r>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } <br>=A0=A0=A0 <br>=A0=A0=A0 &quot;For= each over Structs and Classes with opApply&quot;<br> =A0=A0=A0=A0=A0=A0=A0 The sentence:<br>=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0= =A0=A0=A0=A0 &quot;The body of the apply function iterates over the element= s it aggregates&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Has a typo, change &quot;it = aggregates&quot; to &quot;in aggregates&quot;.<br>=A0=A0=A0 <br> =A0=A0=A0 &quot;Foreach over Tuples&quot;<br>=A0=A0=A0=A0=A0=A0=A0 In the f= irst example, replace any &#39;writefln&#39; with &#39;writeln&#39;.<br>=A0= =A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 In foreach over arrays it stat= es:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &#39;&#39;The index must be of int= , uint or size_t type&#39;&#39;<br> =A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 In foreach over tuples it s= tates:<br>=A0=A0=A0=A0=A0=A0 =A0 =A0=A0 &#39;&#39;The index must be of int = or uint type.&#39;&#39;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0= =A0=A0=A0=A0 Is there a reason why one is allowed to be of size_t type,<br>= =A0=A0=A0=A0=A0=A0=A0 and the other is not?<br> <br>=A0=A0=A0 &quot;Foreach Restrictions&quot;<br>=A0=A0=A0=A0=A0=A0=A0 The= example:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int[] a;<br>=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 int[] b;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 foreach (i= nt i; a)<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 {<br>=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 a =3D null;=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0= =A0=A0=A0 // error<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 a.length =3D a.length + 10;= =A0=A0=A0 // error<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 a =3D b= ;=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // error<b= r>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = a =3D null;=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = // ok<br><br>=A0=A0=A0=A0=A0=A0=A0 None of these give compilation errors or= warnings.<br> =A0=A0=A0=A0=A0=A0=A0 Adding memmory allocation statements for a and b befo= re<br>=A0=A0=A0=A0=A0=A0=A0 entering the loop does not cause any compiler e= rrors, and<br>=A0=A0=A0=A0=A0=A0=A0 no runtime exceptions are raised.<br>= =A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0 &quot;Switch Statement&quot;<br> =A0=A0=A0=A0=A0=A0=A0 The sentence:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &#= 39;&#39;If none of the case expressions match, and there is not a default<b= r>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 statement, a [link:std.switcherr.Switch= Error] is thrown.&#39;&#39;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0= =A0=A0=A0=A0=A0 The link redirects to a 404 page. <br> =A0=A0=A0=A0=A0=A0=A0 &quot;std.switcherr.SwitchError&quot; should be repla= ced <br>=A0=A0=A0=A0=A0=A0=A0 with &quot;core.exception.SwitchError&quot;.<= br><br>=A0=A0=A0 &quot;Final Switch Statement&quot;<br>=A0=A0=A0=A0=A0=A0= =A0 What is this used for? CTFE maybe? I&#39;m curious. :)<br> <br>=A0=A0=A0 &quot;Scope Guard Statement&quot;<br>=A0=A0=A0=A0=A0=A0=A0 In= all of the examples under this section<br>=A0=A0=A0=A0=A0=A0=A0 &#39;write= fln&#39; should be replaced with &#39;writeln&#39;,<br>=A0=A0=A0=A0=A0=A0= =A0 and &#39;writef&#39; with &#39;write&#39;.<br> <br>=A0=A0=A0 &quot;Mixin Statement&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Replace = &#39;writefln&#39; with &#39;writeln&#39; in the mixin string.<br>=A0=A0=A0= =A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 The line:<br>=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 char[] t =3D &quot;y =3D 3;&quot;;<br>=A0=A0=A0=A0=A0=A0=A0 Re= place it with:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 char[] t =3D &quot;y =3D 3;&quot;.dup;<br=
=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 Now only the documentation-relevant er=

ge Statement&quot;<br>=A0=A0=A0=A0=A0=A0=A0 This should be moved up, close = to where the other foreach definitions are.<br> =A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 In the example code:<br>=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Replace &#39;writefln&#39; with &#39;writeln= &#39;, and &#39;writef&#39; with &#39;write&#39;.<br><br><br><a href=3D"htt= p://www.digitalmars.com/d/2.0/arrays.html">http://www.digitalmars.com/d/2.0= /arrays.html</a><br> =A0=A0=A0 &quot;Usage&quot;<br>=A0=A0=A0=A0=A0=A0=A0 The lines:<br>=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 p =3D s;=A0=A0=A0 =A0=A0=A0 // p points to the = first element of the array s.<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 p =3D a;= =A0=A0=A0 =A0=A0=A0 // p points to the first element of the array a.<br>=A0= =A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 Give compiler errors:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Error: cannot implicitly convert expressi= on (s) of<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 type int[3u] to int*<br>=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Error: cannot implicitly convert expression = (a) of<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 type int[] to int*<br>=A0=A0=A0= =A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 Casts work:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 p =3D cast(int*) s;<br>=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 p =3D cast(int*) a;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <b= r>=A0=A0=A0=A0=A0=A0=A0 But is that a good workaround? Don&#39;t ask me.. := p<br>=A0=A0=A0 <br>=A0=A0=A0 &quot;Array Properties&quot;<br>=A0=A0=A0=A0= =A0=A0=A0 In the first example there are missing declarations. <br> =A0=A0=A0=A0=A0=A0=A0 Could add these before the first line:<br>=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 int* p;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int[3= ] s;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int[] a;<br><br>=A0=A0=A0 &quot;S= etting Dynamic Array Length&quot;<br>=A0=A0=A0=A0=A0=A0=A0 From the comment= s in the first example, it states:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &#39;&#39;// always resized in place beca= use it is sliced<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // from a[] whi= ch has enough memory for 15 chars&#39;&#39;<br>=A0=A0=A0=A0=A0=A0=A0 <br>= =A0=A0=A0=A0=A0=A0=A0 But in this shorter example:<br>=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 char[] a =3D new char[50];<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 char[] b =3D a[0..10];=A0 <br><br>=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 b.length =3D 11;=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 a[3] =3D &#39;z&#39;;=A0= =A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 writeln(b); // writes 11 default characters<br><br>=A0=A0=A0=A0=A0=A0= =A0 from my tests, resizing b to any bigger length always creates a copy, <= br> =A0=A0=A0=A0=A0=A0=A0 regardless of how big the length of a is.<br>=A0=A0= =A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 Resizing to a smaller length (e.g= . 8) will keep the reference,<br>=A0=A0=A0=A0=A0=A0=A0 and b[3] will still = refer to a[3] in the example.<br>=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0= =A0=A0 Has the resizing behavior changed recently, or is that comment inacc= urate?<br> <br>=A0=A0=A0 &quot;Functions as Array Properties&quot;<br>=A0=A0=A0=A0=A0= =A0=A0 From this example code:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int[] a= rray;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 void foo(int[] a, int x);<br><br=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 foo(array, 3);<br>=A0=A0=A0=A0=A0=A0=A0=

<br>=A0=A0=A0=A0=A0=A0=A0 The last line does not compile, even when foo() i= s fully defined:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Error: undefined iden= tifier module main.foo<br><br>=A0=A0=A0 &quot;Array Bounds Checking&quot;<b= r>=A0=A0=A0=A0=A0=A0=A0 In the example code, &quot;ArrayBoundsError&quot; s= hould be replaced <br> =A0=A0=A0=A0=A0=A0=A0 with &quot;RangeError&quot;.<br>=A0=A0=A0 <br>=A0=A0= =A0 &quot;Static Initialization of Static Arrays&quot;<br>=A0=A0=A0=A0=A0= =A0=A0 For the example code:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 enum Colo= r { red, blue, green };<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int value[Colo= r.max + 1] =3D [ Color.blue:6, Color.green:2, Color.red:5 ];<br> <br>=A0=A0=A0=A0=A0=A0=A0 The documentation states:<br>=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 &#39;&#39;These arrays are static when they appear in globa= l scope. <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Otherwise, they need to be m= arked with const or static <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 storage cl= asses to make them static arrays.&#39;&#39;<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 In non-global s= cope, the array has to be marked with static in order<br>=A0=A0=A0=A0=A0=A0= =A0 to compile. const alone is not compilable. At least not in my case.<br>= <br>=A0=A0=A0 &quot;Special Array Types&quot;<br>=A0=A0=A0=A0=A0=A0=A0 The = 6th example from the title:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cast(wchar [])&quot;abc&quot;=A0=A0=A0 //= this is an array of wchar characters<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = &quot;abc&quot;w=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 // so is this<br>= =A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=A0 It should probably be noted= that the first line returns a copy of the <br> =A0=A0=A0=A0=A0=A0=A0 string with type wchar[], while the second line retur= ns a copy(?) <br>=A0=A0=A0=A0=A0=A0=A0 of the string with type immutable(wc= har)[]. But correct me if I&#39;m wrong with this one.<br><br>=A0=A0=A0=A0= =A0=A0=A0 The next example has this line:<br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 w =3D \r[0];=A0=A0=A0 =A0=A0=A0 // w is a= ssigned the carriage return wchar character<br>=A0=A0=A0=A0=A0=A0=A0 Needs = to be replaced with:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 w =3D &quot;\r&qu= ot;[0];=A0=A0=A0 // w is assigned the carriage return wchar character<br><b= r> =A0=A0=A0 &quot;Associative Arrays&quot;<br>=A0=A0=A0=A0=A0=A0=A0 Accessing= a nonexistent key for an AA throws the RangeError exception.<br>=A0=A0=A0= =A0=A0=A0=A0 Perhaps a different exception should be created for AA&#39;s, = such as:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 core.exception.KeyNotInAssocA= rray<br> =A0=A0=A0=A0=A0=A0=A0 ?<br>=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0 &quot;Using = Classes as the KeyType&quot;<br>=A0=A0=A0=A0=A0=A0=A0 In the example code, = any &quot;f&quot; in a declaration/expression needs to be<br>=A0=A0=A0=A0= =A0=A0=A0 replaced with &quot;foo&quot;.<br><br>=A0=A0=A0 &quot;Using Struc= ts or Unions as the KeyType&quot;<br> =A0=A0=A0=A0=A0=A0=A0 The line in the example:<br>=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 foreach (char c; s)<br>=A0=A0=A0=A0=A0=A0=A0 Should be:<br>=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 foreach (char c; str)<br><br>// end<br><br> --0016e6546df00b058c0489e35a2e--
Jun 25 2010
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
UPDATE:
I've tested my findings with the newer DMD v2.047, the results are almost the
same except these 3 differences (marked with **)

http://www.digitalmars.com/d/2.0/property.html
    ".stringof Property"
        Example contains two lines refering to "test.Foo",
        but "test" isn't declared anywhere.
        The compiler output is different too.
       
        The lines should be replaced with:
            writefln((1+2).stringof);       // "1 + 2"
            writefln(Foo.stringof);         // "Foo"
            writefln(int.stringof);         // "int"
            writefln((int*[5][]).stringof); // "int*[5u][]"
**          writefln(Enum.RED.stringof);    // "cast(Enum)0
            writefln((5).stringof);         // "5"


http://www.digitalmars.com/d/2.0/statement.html
    "Foreach over Associative Arrays"
        The first example code gives these compiler errors:
**         Error: function            
object.AssociativeArray!(const(char)[],double).AssociativeArray.opApply 
            (scope int delegate(ref const(char)[], ref double) dg) is not
            callable using argument types (int delegate(ref char[] 
            __applyArg0, ref double __applyArg1))

**         Error: cannot implicitly convert expression
            (__foreachbody606) of type int delegate(ref char[] __applyArg0,
            ref double __applyArg1) to int delegate(ref double)
Jun 25 2010
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Okay, I've done some more reviewing and covered these:

structs,
classes,
interfaces,
enums,
const,
functions,
contracts.

I've not yet touched op-overloading, templates and a bunch of others.

Anyways, I've noticed this Tracker in the bug-reports:
http://d.puremagic.com/issues/show_bug.cgi?id=677

That one's for D1 (and it seems abandoned). I was thinking of making one for
D2, and linking each language spec issue to the Depends On field.

Btw., who is in charge of editing the spec page? I'd love to volunteer if the
person needs an extra hand with the edits..
Jul 01 2010
prev sibling parent Leandro Lucarella <luca llucax.com.ar> writes:
Andrej Mitrovic, el  1 de julio a las 14:21 me escribiste:
 Okay, I've done some more reviewing and covered these:
 
 structs,
 classes,
 interfaces,
 enums,
 const,
 functions,
 contracts.
 
 I've not yet touched op-overloading, templates and a bunch of others.
 
 Anyways, I've noticed this Tracker in the bug-reports:
 http://d.puremagic.com/issues/show_bug.cgi?id=677
 
 That one's for D1 (and it seems abandoned).

What do you mean by abandoned? By Walter? Because I don't think it's abandoned by the users/reporters... -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- - is there a perl version of php?... cause i have cgi-bin access with perl and want to use php scripts.
Jul 01 2010