Learn to Tango with D - Errata & Questions

AEon aeon2001 at lycos.de
Sat Sep 20 08:41:57 PDT 2008


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.)


More information about the Digitalmars-d-learn mailing list