www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Learn to Tango with D - Errata & Questions

reply AEon <aeon2001 lycos.de> writes:
Carefully reading and testing the examples in "Learn to Tango with D"
made me stumble across a few things I did not quite understand. A
internet search revealed:

     Errata for 'Learn to Tango with D'
     (http://www.dsource.org/projects/dallegro/wiki/TangoBookErrata)

That explained a few "confusing" things.


But there is still one entry I think is a typo, but I'd like to ask
the programmers here, if it is indeed a "bug".


On p33, Slicing, these examples are given.
---
     int x[] = [0,1,2,3,4];
     int y[] = x[1..x.length];
	
     int z[];
     z = x[1..x.length-1];

     int all = x[];   // all is a view of all of x, from the first //L13
                      // element to the last, i.e., 0, 1, 2, 3, 4.
---

To me the last line makes no sense, it should read:
	
     int all[] = x[];

and dmd v1.030 agrees. The code from the book yields a compile error:

     Error: p33_slice_test.d(13): Error: cannot implicitly convert
             expression (x[])  of type int[]  to int

So is it indeed a bug?

(I'll be posting the other questions in this thread, later on.)
Sep 20 2008
next sibling parent reply "Denis Koroskin" <2korden gmail.com> writes:
On Sat, 20 Sep 2008 19:41:57 +0400, AEon <aeon2001 lycos.de> wrote:

 Carefully reading and testing the examples in "Learn to Tango with D"
 made me stumble across a few things I did not quite understand. A
 internet search revealed:

      Errata for 'Learn to Tango with D'
      (http://www.dsource.org/projects/dallegro/wiki/TangoBookErrata)

 That explained a few "confusing" things.


 But there is still one entry I think is a typo, but I'd like to ask
 the programmers here, if it is indeed a "bug".


 On p33, Slicing, these examples are given.
 ---
      int x[] = [0,1,2,3,4];
      int y[] = x[1..x.length];
 	
      int z[];
      z = x[1..x.length-1];

      int all = x[];   // all is a view of all of x, from the first //L13
                       // element to the last, i.e., 0, 1, 2, 3, 4.
 ---

 To me the last line makes no sense, it should read:
 	
      int all[] = x[];

 and dmd v1.030 agrees. The code from the book yields a compile error:

      Error: p33_slice_test.d(13): Error: cannot implicitly convert
              expression (x[])  of type int[]  to int

 So is it indeed a bug?

 (I'll be posting the other questions in this thread, later on.)
Yes, it is a typo. Take a look here: http://www.dsource.org/projects/tango/wiki/LearnToTangoWithD
Sep 20 2008
parent AEon <aeon2001 lycos.de> writes:
Denis Koroskin wrote:

 To me the last line makes no sense, it should read:
     
      int all[] = x[];

 and dmd v1.030 agrees. 
Yes, it is a typo. Take a look here: http://www.dsource.org/projects/tango/wiki/LearnToTangoWithD
Thanks. Even though it does mention 2 extra typos, compared to http://www.dsource.org/projects/dallegro/wiki/TangoBookErrata it's strange that "my" bug has been missed so far. Will try to update the Errata page (if that is possible). AEon
Sep 20 2008
prev sibling parent reply torhu <no spam.invalid> writes:
AEon wrote:
 Carefully reading and testing the examples in "Learn to Tango with D"
 made me stumble across a few things I did not quite understand. A
 internet search revealed:
 
      Errata for 'Learn to Tango with D'
      (http://www.dsource.org/projects/dallegro/wiki/TangoBookErrata)
 
 That explained a few "confusing" things.
 
 
 But there is still one entry I think is a typo, but I'd like to ask
 the programmers here, if it is indeed a "bug".
 
When I wrote that page I just included what I considered serious errors, I didn't bother to include the obvious typos. I guess I should merge my page into the Tango team's errata page, though.
Sep 20 2008
parent AEon <aeon2001 lycos.de> writes:
torhu wrote:
 AEon wrote:
 Carefully reading and testing the examples in "Learn to Tango with D"
 made me stumble across a few things I did not quite understand. A
 internet search revealed:

      Errata for 'Learn to Tango with D'
      (http://www.dsource.org/projects/dallegro/wiki/TangoBookErrata)

 That explained a few "confusing" things.


 But there is still one entry I think is a typo, but I'd like to ask
 the programmers here, if it is indeed a "bug".
When I wrote that page I just included what I considered serious errors, I didn't bother to include the obvious typos. I guess I should merge my page into the Tango team's errata page, though.
I seem to have suggested that over in the forums: http://www.dsource.org/projects/tango/forums/topic/606 Oh well :) AEon
Sep 20 2008