From c745674d1951bf36ae3b2db152570253081a0fad Mon Sep 17 00:00:00 2001 From: Apress Date: Tue, 11 Oct 2016 04:52:26 +0100 Subject: [PATCH] First commit --- 9781590599600.jpg | Bin 0 -> 10832 bytes Chapter01/greetings.d | 9 ++++++++ Chapter01/hello1.d | 6 +++++ Chapter01/hello2.d | 10 +++++++++ Chapter01/hello3.d | 6 +++++ Chapter02/parameters.d | 26 +++++++++++++++++++++ Chapter02/properties.d | 17 ++++++++++++++ Chapter02/scope.d | 34 ++++++++++++++++++++++++++++ Chapter03/example1.d | 1 + Chapter03/example10.d | 8 +++++++ Chapter03/example11.d | 5 +++++ Chapter03/example12.d | 10 +++++++++ Chapter03/example13.d | 4 ++++ Chapter03/example14.d | 4 ++++ Chapter03/example15.d | 4 ++++ Chapter03/example16.d | 5 +++++ Chapter03/example17.d | 7 ++++++ Chapter03/example18.d | 11 +++++++++ Chapter03/example19.d | 2 ++ Chapter03/example2.d | 1 + Chapter03/example20.d | 5 +++++ Chapter03/example21.d | 11 +++++++++ Chapter03/example22.d | 5 +++++ Chapter03/example23.d | 5 +++++ Chapter03/example24.d | 6 +++++ Chapter03/example25.d | 4 ++++ Chapter03/example26.d | 8 +++++++ Chapter03/example27.d | 1 + Chapter03/example28.d | 5 +++++ Chapter03/example29.d | 9 ++++++++ Chapter03/example3.d | 1 + Chapter03/example30.d | 11 +++++++++ Chapter03/example31.d | 14 ++++++++++++ Chapter03/example32.d | 7 ++++++ Chapter03/example33.d | 20 +++++++++++++++++ Chapter03/example34.d | 1 + Chapter03/example35.d | 9 ++++++++ Chapter03/example36.d | 8 +++++++ Chapter03/example37.d | 18 +++++++++++++++ Chapter03/example38.d | 7 ++++++ Chapter03/example39.d | 15 +++++++++++++ Chapter03/example4.d | 1 + Chapter03/example40.d | 7 ++++++ Chapter03/example41.d | 6 +++++ Chapter03/example42.d | 6 +++++ Chapter03/example5.d | 2 ++ Chapter03/example6.d | 3 +++ Chapter03/example7.d | 1 + Chapter03/example8.d | 3 +++ Chapter03/example9.d | 3 +++ Chapter04/example01.d | 20 +++++++++++++++++ Chapter04/example02.d | 20 +++++++++++++++++ Chapter04/example03.d | 25 +++++++++++++++++++++ Chapter04/example04.d | 26 +++++++++++++++++++++ Chapter04/example05/A.d | 9 ++++++++ Chapter04/example05/B.d | 10 +++++++++ Chapter04/example05/C.d | 8 +++++++ Chapter04/example05/D.d | 9 ++++++++ Chapter04/example05/E.d | 7 ++++++ Chapter04/example05/Main.d | 15 +++++++++++++ Chapter04/example06.d | 15 +++++++++++++ Chapter04/example07.d | 16 +++++++++++++ Chapter04/example08.d | 30 +++++++++++++++++++++++++ Chapter04/example09.d | 30 +++++++++++++++++++++++++ Chapter05/ObjectList.d | 34 ++++++++++++++++++++++++++++ Chapter05/TemplateList.d | 37 ++++++++++++++++++++++++++++++ Chapter05/example01.d | 22 ++++++++++++++++++ Chapter05/example02.d | 12 ++++++++++ Chapter05/example03.d | 18 +++++++++++++++ Chapter05/example04.d | 25 +++++++++++++++++++++ Chapter05/example05.d | 21 +++++++++++++++++ Chapter05/example06.d | 45 +++++++++++++++++++++++++++++++++++++ Chapter05/example07.d | 15 +++++++++++++ Chapter05/example08.d | 25 +++++++++++++++++++++ Chapter05/example09.d | 12 ++++++++++ Chapter05/example10.d | 19 ++++++++++++++++ Chapter05/example11.d | 15 +++++++++++++ Chapter05/example12.d | 15 +++++++++++++ Chapter06/example1.d | 8 +++++++ Chapter06/example10.d | 9 ++++++++ Chapter06/example11.d | 7 ++++++ Chapter06/example12.d | 9 ++++++++ Chapter06/example13.d | 5 +++++ Chapter06/example14.d | 6 +++++ Chapter06/example15.d | 8 +++++++ Chapter06/example16.d | 5 +++++ Chapter06/example17.d | 12 ++++++++++ Chapter06/example18.d | 5 +++++ Chapter06/example19.d | 5 +++++ Chapter06/example2.d | 5 +++++ Chapter06/example20.d | 8 +++++++ Chapter06/example21.d | 5 +++++ Chapter06/example22.d | 6 +++++ Chapter06/example23.d | 5 +++++ Chapter06/example24.d | 8 +++++++ Chapter06/example3.d | 8 +++++++ Chapter06/example4.d | 8 +++++++ Chapter06/example5.d | 8 +++++++ Chapter06/example6.d | 8 +++++++ Chapter06/example7.d | 11 +++++++++ Chapter06/example8.d | 9 ++++++++ Chapter06/example9.d | 8 +++++++ Chapter07/filescan.d | 21 +++++++++++++++++ Chapter07/name.d | 8 +++++++ Chapter07/path.d | 19 ++++++++++++++++ Chapter08/arraybag.d | 22 ++++++++++++++++++ Chapter08/arrayseq.d | 38 +++++++++++++++++++++++++++++++ Chapter08/fibers.d | 23 +++++++++++++++++++ Chapter08/hashset.d | 35 +++++++++++++++++++++++++++++ Chapter08/logFile.d | 13 +++++++++++ Chapter08/logLevels.d | 22 ++++++++++++++++++ Chapter08/loggerCreation.d | 8 +++++++ Chapter08/thread01.d | 37 ++++++++++++++++++++++++++++++ Chapter08/thread02.d | 37 ++++++++++++++++++++++++++++++ LICENSE.txt | 27 ++++++++++++++++++++++ README.md | 15 +++++++++++++ contributing.md | 14 ++++++++++++ 117 files changed, 1442 insertions(+) create mode 100644 9781590599600.jpg create mode 100644 Chapter01/greetings.d create mode 100644 Chapter01/hello1.d create mode 100644 Chapter01/hello2.d create mode 100644 Chapter01/hello3.d create mode 100644 Chapter02/parameters.d create mode 100644 Chapter02/properties.d create mode 100644 Chapter02/scope.d create mode 100644 Chapter03/example1.d create mode 100644 Chapter03/example10.d create mode 100644 Chapter03/example11.d create mode 100644 Chapter03/example12.d create mode 100644 Chapter03/example13.d create mode 100644 Chapter03/example14.d create mode 100644 Chapter03/example15.d create mode 100644 Chapter03/example16.d create mode 100644 Chapter03/example17.d create mode 100644 Chapter03/example18.d create mode 100644 Chapter03/example19.d create mode 100644 Chapter03/example2.d create mode 100644 Chapter03/example20.d create mode 100644 Chapter03/example21.d create mode 100644 Chapter03/example22.d create mode 100644 Chapter03/example23.d create mode 100644 Chapter03/example24.d create mode 100644 Chapter03/example25.d create mode 100644 Chapter03/example26.d create mode 100644 Chapter03/example27.d create mode 100644 Chapter03/example28.d create mode 100644 Chapter03/example29.d create mode 100644 Chapter03/example3.d create mode 100644 Chapter03/example30.d create mode 100644 Chapter03/example31.d create mode 100644 Chapter03/example32.d create mode 100644 Chapter03/example33.d create mode 100644 Chapter03/example34.d create mode 100644 Chapter03/example35.d create mode 100644 Chapter03/example36.d create mode 100644 Chapter03/example37.d create mode 100644 Chapter03/example38.d create mode 100644 Chapter03/example39.d create mode 100644 Chapter03/example4.d create mode 100644 Chapter03/example40.d create mode 100644 Chapter03/example41.d create mode 100644 Chapter03/example42.d create mode 100644 Chapter03/example5.d create mode 100644 Chapter03/example6.d create mode 100644 Chapter03/example7.d create mode 100644 Chapter03/example8.d create mode 100644 Chapter03/example9.d create mode 100644 Chapter04/example01.d create mode 100644 Chapter04/example02.d create mode 100644 Chapter04/example03.d create mode 100644 Chapter04/example04.d create mode 100644 Chapter04/example05/A.d create mode 100644 Chapter04/example05/B.d create mode 100644 Chapter04/example05/C.d create mode 100644 Chapter04/example05/D.d create mode 100644 Chapter04/example05/E.d create mode 100644 Chapter04/example05/Main.d create mode 100644 Chapter04/example06.d create mode 100644 Chapter04/example07.d create mode 100644 Chapter04/example08.d create mode 100644 Chapter04/example09.d create mode 100644 Chapter05/ObjectList.d create mode 100644 Chapter05/TemplateList.d create mode 100644 Chapter05/example01.d create mode 100644 Chapter05/example02.d create mode 100644 Chapter05/example03.d create mode 100644 Chapter05/example04.d create mode 100644 Chapter05/example05.d create mode 100644 Chapter05/example06.d create mode 100644 Chapter05/example07.d create mode 100644 Chapter05/example08.d create mode 100644 Chapter05/example09.d create mode 100644 Chapter05/example10.d create mode 100644 Chapter05/example11.d create mode 100644 Chapter05/example12.d create mode 100644 Chapter06/example1.d create mode 100644 Chapter06/example10.d create mode 100644 Chapter06/example11.d create mode 100644 Chapter06/example12.d create mode 100644 Chapter06/example13.d create mode 100644 Chapter06/example14.d create mode 100644 Chapter06/example15.d create mode 100644 Chapter06/example16.d create mode 100644 Chapter06/example17.d create mode 100644 Chapter06/example18.d create mode 100644 Chapter06/example19.d create mode 100644 Chapter06/example2.d create mode 100644 Chapter06/example20.d create mode 100644 Chapter06/example21.d create mode 100644 Chapter06/example22.d create mode 100644 Chapter06/example23.d create mode 100644 Chapter06/example24.d create mode 100644 Chapter06/example3.d create mode 100644 Chapter06/example4.d create mode 100644 Chapter06/example5.d create mode 100644 Chapter06/example6.d create mode 100644 Chapter06/example7.d create mode 100644 Chapter06/example8.d create mode 100644 Chapter06/example9.d create mode 100644 Chapter07/filescan.d create mode 100644 Chapter07/name.d create mode 100644 Chapter07/path.d create mode 100644 Chapter08/arraybag.d create mode 100644 Chapter08/arrayseq.d create mode 100644 Chapter08/fibers.d create mode 100644 Chapter08/hashset.d create mode 100644 Chapter08/logFile.d create mode 100644 Chapter08/logLevels.d create mode 100644 Chapter08/loggerCreation.d create mode 100644 Chapter08/thread01.d create mode 100644 Chapter08/thread02.d create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 contributing.md diff --git a/9781590599600.jpg b/9781590599600.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e21abc1fd998fe17ab330cde8f8662a13d29b6e0 GIT binary patch literal 10832 zcmch7cT`i|({2zXbOh;LDbjmy0hQ1M1nE_!g8>2QU<5>@caYv|=nz5&0jUDgkzS=E zy{24zfBk;ny6um9l38c%Gn2_Y&&i%WdvY){m}S5{HLxlefQ5wxczOE*VCDc%0C>2# zK-{}{Kp+qwACG{Df|!VqkcgK2J}Ctw9WxUn9RmXk8~-DghrFx|44e{Nyn;faqN2=? zq~s)pW%)%!h5tCg!pFxaA|#?ACZ-X7!0)Id=3qZi%&>QO8%0PnwytjP*_x4 zQd(162d_soG&Xg1b${#W?du;H8=sh*nx6SNyRy2rzVT~wYkTMD_~i8L{NnQJ`VTHF z0QTQt{S(>$gp2GJ*Bu-jY#iVpTv&HJZv~qS=k5a`TyjNi;47E=4}}BpC?3b=RDZ>1 z7124QeC;|)K*c7y!hZAz+F!{2&wvH~KOy@kuz%s21rT9l-QGNGG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X$zQ>z+FZb7p(#bMK#>JW`gVV9e zj5~wgIwu0wZGpS}$RRc#_XL499!au>4NJh$_;Jy`oueK4LBD)iEm*6Z!r(zw8hCYv z{_|J4BlW*JlQi-P0B!Z4Eqg)#+s8*DnAJG341SZAQ~Y@*g4;+KclVNXLse}7iiIrU z4kO^q{qVmM5wRe)qi;oz%bWHRV|z9TX=t6lkS4?)M_0mK3+>n7qr7lMP?}|_f8sBK z%ZBhl|1vygK~_8Y9mm#EgpVKf*qkaTrD;}6{9%QG<8s8&bfEH@**hV!zzs*Op6f3Y zg&U=|jO+=eH#+nM<0dAN`#*qJFMo#OVJANRS+X`>V5W0EX2f3};rSLGq=YSXOun} zZD>mr&?L>(3TPP>=Pt>bQR?sL+*Klx=sHbx1l|_XO#*B)4CrZYfH%C?7==lAp8Zr% zpf|xT`tI+h6}2cC%GoY-;4PM6s+P`RaE5}K4Fo@;HBEVccs=?UwQ`o*U{n@DVHqWJ z%j^cCfI{2FP4IYbESj&CGdDa$g!J}&I}GD&`2Tj9(h|}Yb*inz(Vvil`T0Kp0i1X@ literal 0 HcmV?d00001 diff --git a/Chapter01/greetings.d b/Chapter01/greetings.d new file mode 100644 index 0000000..12c9379 --- /dev/null +++ b/Chapter01/greetings.d @@ -0,0 +1,9 @@ +module greetings; + +import tango.io.Stdout; + +void hello (char[][] names) +{ + foreach (name; names) + Stdout.formatln ("hello {}", name); +} \ No newline at end of file diff --git a/Chapter01/hello1.d b/Chapter01/hello1.d new file mode 100644 index 0000000..a6ee554 --- /dev/null +++ b/Chapter01/hello1.d @@ -0,0 +1,6 @@ +import tango.io.Stdout; + +void main() +{ + Stdout ("hello world").newline; +} \ No newline at end of file diff --git a/Chapter01/hello2.d b/Chapter01/hello2.d new file mode 100644 index 0000000..3af05ee --- /dev/null +++ b/Chapter01/hello2.d @@ -0,0 +1,10 @@ +import tango.io.Stdout; + +void main (char[][] args) +{ + if (args.length < 2) + Stdout ("usage is: hello name [name] ... [name]").newline; + else + foreach (name; args[1..$]) + Stdout.formatln ("hello {}", name); +} diff --git a/Chapter01/hello3.d b/Chapter01/hello3.d new file mode 100644 index 0000000..ac5127c --- /dev/null +++ b/Chapter01/hello3.d @@ -0,0 +1,6 @@ +import greetings; + +void main(char[][] args) +{ + hello (args[1..$]); +} \ No newline at end of file diff --git a/Chapter02/parameters.d b/Chapter02/parameters.d new file mode 100644 index 0000000..b675cea --- /dev/null +++ b/Chapter02/parameters.d @@ -0,0 +1,26 @@ +import tango.io.Stdout; + +void main() +{ + int x = 1; + int y = 2; + int z = 3; + + Stdout.formatln("In main, x: {} y: {} z: {}", x, y, z); + + // Call some function. + someFunction(x, y, z); + + Stdout.formatln("In main again, x: {} y: {} z: {}", x, y, z); +} + +void someFunction(int x, out int y, ref int z) +{ + Stdout.formatln("In someFunction, x: {} y: {} z: {}", x, y, z); + + x = 10; + y = 20; + z = 30; + + Stdout.formatln("In someFunction again, x: {} y: {} z: {}", x, y, z); +} \ No newline at end of file diff --git a/Chapter02/properties.d b/Chapter02/properties.d new file mode 100644 index 0000000..03d0a0d --- /dev/null +++ b/Chapter02/properties.d @@ -0,0 +1,17 @@ +import tango.io.Stdout; + +void main() +{ + Stdout.formatln("int.init is {}", int.init); + Stdout.formatln("int.sizeof is {}", int.sizeof); + Stdout.formatln("int.alignof is {}", int.alignof); + Stdout.formatln("int.mangleof is '{}'", int.mangleof); + Stdout.formatln("int.stringof is '{}'", int.stringof); + + int x; + Stdout.formatln("x.init is {}", x.init); + Stdout.formatln("x.sizeof is {}", x.sizeof); + Stdout.formatln("x.alignof is {}", x.alignof); + Stdout.formatln("x.mangleof is '{}'", x.mangleof); + Stdout.formatln("x.stringof is '{}'", x.stringof); +} \ No newline at end of file diff --git a/Chapter02/scope.d b/Chapter02/scope.d new file mode 100644 index 0000000..c5d41ed --- /dev/null +++ b/Chapter02/scope.d @@ -0,0 +1,34 @@ +// This is module scope. Here, we declare x and initialize it with a constant +// expression. +int x = 1; + +void main() +{ // A new block scope starts here--a child of the module scope. + + // y is declared inside main's block scope, meaning it is local to main. + // It can see x, but x can't see it. + int y = x; + + if(1 < 2) + { // A new block scope starts here--a child of main's scope. + + // Because x is visible in main's scope, it is also visible here. And + // because main's scope is this scope's parent, y is visible, too. + // However, z is visible neither in main's scope nor in the module + // scope. + int z = x + y; + + } // The end of the if block scope + +} // The end of main's block scope + +void someFunc() +{ // A new block scope starts here--a child of the module scope and a + // sibling of main's scope. + + // This y is declared inside someFunc's scope. It can see x, but x can't + // see it. Also, neither it nor the y in main's scope are visible to each + // other. + int y = x; + +} // The end of someFunc's block scope \ No newline at end of file diff --git a/Chapter03/example1.d b/Chapter03/example1.d new file mode 100644 index 0000000..04fae98 --- /dev/null +++ b/Chapter03/example1.d @@ -0,0 +1 @@ +module Time; diff --git a/Chapter03/example10.d b/Chapter03/example10.d new file mode 100644 index 0000000..d76485d --- /dev/null +++ b/Chapter03/example10.d @@ -0,0 +1,8 @@ +module Parser; + +int state; + +class Parser { + int state; + int outerState() { return .state; } +} diff --git a/Chapter03/example11.d b/Chapter03/example11.d new file mode 100644 index 0000000..638db89 --- /dev/null +++ b/Chapter03/example11.d @@ -0,0 +1,5 @@ +uint square (int x) { return x*x; } + +unittest { + assert (square(4) == 16); +} diff --git a/Chapter03/example12.d b/Chapter03/example12.d new file mode 100644 index 0000000..81e7f96 --- /dev/null +++ b/Chapter03/example12.d @@ -0,0 +1,10 @@ +struct Time { + uint hour; + int timeZone; + bool usingAM; + + int time() { + if (usingAM && hour > 12) return hour - 12; + else return hour; + } +} diff --git a/Chapter03/example13.d b/Chapter03/example13.d new file mode 100644 index 0000000..4783d85 --- /dev/null +++ b/Chapter03/example13.d @@ -0,0 +1,4 @@ +struct S { + align(4) int a; + align(4) int b; +} diff --git a/Chapter03/example14.d b/Chapter03/example14.d new file mode 100644 index 0000000..07078c0 --- /dev/null +++ b/Chapter03/example14.d @@ -0,0 +1,4 @@ +align(1) struct S { + int a; + int b; +} diff --git a/Chapter03/example15.d b/Chapter03/example15.d new file mode 100644 index 0000000..c651e46 --- /dev/null +++ b/Chapter03/example15.d @@ -0,0 +1,4 @@ +union Error { + int errorCode; + char[] errorMessage; +} diff --git a/Chapter03/example16.d b/Chapter03/example16.d new file mode 100644 index 0000000..d6dff3f --- /dev/null +++ b/Chapter03/example16.d @@ -0,0 +1,5 @@ +import example12; + +static Time t1 = { hour:7, timeZone:-2 }; + +static Time t2 = { 7, -2 }; diff --git a/Chapter03/example17.d b/Chapter03/example17.d new file mode 100644 index 0000000..5381395 --- /dev/null +++ b/Chapter03/example17.d @@ -0,0 +1,7 @@ +import example12; + +void main() { + Time t; + t.hour = 3; + Time at = t; +} diff --git a/Chapter03/example18.d b/Chapter03/example18.d new file mode 100644 index 0000000..c62dc47 --- /dev/null +++ b/Chapter03/example18.d @@ -0,0 +1,11 @@ +struct Time { + int hour; + + static Time opAssign(int time) { + Time t; + t.hour = time; + return t; + } +} + +Time t = Time(3); diff --git a/Chapter03/example19.d b/Chapter03/example19.d new file mode 100644 index 0000000..dd15557 --- /dev/null +++ b/Chapter03/example19.d @@ -0,0 +1,2 @@ +void setTime(Time t); +setTime( Time(1, 2) ); diff --git a/Chapter03/example2.d b/Chapter03/example2.d new file mode 100644 index 0000000..4680f9e --- /dev/null +++ b/Chapter03/example2.d @@ -0,0 +1 @@ +module tango.time.Time; diff --git a/Chapter03/example20.d b/Chapter03/example20.d new file mode 100644 index 0000000..6a5bceb --- /dev/null +++ b/Chapter03/example20.d @@ -0,0 +1,5 @@ +import tango.time.Time; + +void main() { + Time * dt = new Time; +} diff --git a/Chapter03/example21.d b/Chapter03/example21.d new file mode 100644 index 0000000..60458ca --- /dev/null +++ b/Chapter03/example21.d @@ -0,0 +1,11 @@ +class Time { + uint h; + int tz; + + uint hour() { return h; } + + this(uint hour, int timeZone) { + this.h = hour; + this.tz = timeZone; + } +} diff --git a/Chapter03/example22.d b/Chapter03/example22.d new file mode 100644 index 0000000..2d37189 --- /dev/null +++ b/Chapter03/example22.d @@ -0,0 +1,5 @@ +import tango.io.File; + +void main() { + File f = new File("tango/io/File.d"); +} diff --git a/Chapter03/example23.d b/Chapter03/example23.d new file mode 100644 index 0000000..947cc8a --- /dev/null +++ b/Chapter03/example23.d @@ -0,0 +1,5 @@ +import tango.io.File; + +void main() { + scope f = new File("tango/io/File.d"); +} diff --git a/Chapter03/example24.d b/Chapter03/example24.d new file mode 100644 index 0000000..c792786 --- /dev/null +++ b/Chapter03/example24.d @@ -0,0 +1,6 @@ +class Time { + private uint month; // 0 is January, 11 December + invariant() { + assert ( month < 12 ); + } +} diff --git a/Chapter03/example25.d b/Chapter03/example25.d new file mode 100644 index 0000000..8d3227a --- /dev/null +++ b/Chapter03/example25.d @@ -0,0 +1,4 @@ +void main() { + auto o = new Object; + assert (o); +} diff --git a/Chapter03/example26.d b/Chapter03/example26.d new file mode 100644 index 0000000..a974109 --- /dev/null +++ b/Chapter03/example26.d @@ -0,0 +1,8 @@ +import tango.io.FilePath; + +class FileConduit : DeviceConduit { + private PathView path_; + PathView path() { return path_; } +} + +class DeviceConduit { } diff --git a/Chapter03/example27.d b/Chapter03/example27.d new file mode 100644 index 0000000..0d4c299 --- /dev/null +++ b/Chapter03/example27.d @@ -0,0 +1 @@ +final class FilePath { } diff --git a/Chapter03/example28.d b/Chapter03/example28.d new file mode 100644 index 0000000..73090a7 --- /dev/null +++ b/Chapter03/example28.d @@ -0,0 +1,5 @@ +abstract class Conduit { + + abstract uint write (void [] src); + +} diff --git a/Chapter03/example29.d b/Chapter03/example29.d new file mode 100644 index 0000000..c79b203 --- /dev/null +++ b/Chapter03/example29.d @@ -0,0 +1,9 @@ +import tango.io.model.IConduit; + +class MyProducer { + void[] buffer; + void produce(InputStream data) { + data.read(buffer); + data.clear.close; + } +} diff --git a/Chapter03/example3.d b/Chapter03/example3.d new file mode 100644 index 0000000..26d8eb7 --- /dev/null +++ b/Chapter03/example3.d @@ -0,0 +1 @@ +import tango.time.Time; diff --git a/Chapter03/example30.d b/Chapter03/example30.d new file mode 100644 index 0000000..095653a --- /dev/null +++ b/Chapter03/example30.d @@ -0,0 +1,11 @@ +class Pipe : DeviceConduit { + alias DeviceConduit.copy copy; + alias DeviceConduit.read read; +} + +class DeviceConduit { + + void copy () {} + void read () {} + +} diff --git a/Chapter03/example31.d b/Chapter03/example31.d new file mode 100644 index 0000000..ff2cfdb --- /dev/null +++ b/Chapter03/example31.d @@ -0,0 +1,14 @@ +class FileConduit : DeviceConduit { + private void closeFile() { } + + override void close() { + super.close(); + closeFile(); + } +} + +class DeviceConduit { + + void close() { } + +} diff --git a/Chapter03/example32.d b/Chapter03/example32.d new file mode 100644 index 0000000..7a63940 --- /dev/null +++ b/Chapter03/example32.d @@ -0,0 +1,7 @@ +class DataInput : InputStream +{ + public DataInput clear() + { + super.clear; + } +} diff --git a/Chapter03/example33.d b/Chapter03/example33.d new file mode 100644 index 0000000..7f31c1e --- /dev/null +++ b/Chapter03/example33.d @@ -0,0 +1,20 @@ +import tango.io.Conduit; + +class SocketConduit : Conduit { + private static SocketConduit freelist; + private SocketConduit next; + + package static synchronized SocketConduit allocate () + { + SocketConduit s; + + if (freelist) + { + s = freelist; + freelist = s.next; + } + else + { } + return s; + } +} diff --git a/Chapter03/example34.d b/Chapter03/example34.d new file mode 100644 index 0000000..72fb2d6 --- /dev/null +++ b/Chapter03/example34.d @@ -0,0 +1 @@ +SocketConduit sc = SocketConduit.allocate(); diff --git a/Chapter03/example35.d b/Chapter03/example35.d new file mode 100644 index 0000000..4a64ec3 --- /dev/null +++ b/Chapter03/example35.d @@ -0,0 +1,9 @@ +class SC : C { + private int i; + this (int i) { this(i, true); } + this (int i, bool b) { super (i, b); } +} + +class C { + this (int i, bool b) { } +} diff --git a/Chapter03/example36.d b/Chapter03/example36.d new file mode 100644 index 0000000..c630ef6 --- /dev/null +++ b/Chapter03/example36.d @@ -0,0 +1,8 @@ +class Outer { + class Nested { } +} + +void main() { + Outer o = new Outer; + Outer.Nested nested = o.new Nested; +} diff --git a/Chapter03/example37.d b/Chapter03/example37.d new file mode 100644 index 0000000..d7f029d --- /dev/null +++ b/Chapter03/example37.d @@ -0,0 +1,18 @@ +interface EventHandler { void handle(Event); } + +class Event { + void printDetails(); +} + +class Events { + void registerHandler(EventHandler eh) { } +} + +void main() { + auto e = new Events; + e.registerHandler( + new class EventHandler { + void handle(Event e) { e.printDetails(); } + } + ); +} diff --git a/Chapter03/example38.d b/Chapter03/example38.d new file mode 100644 index 0000000..9dc81b3 --- /dev/null +++ b/Chapter03/example38.d @@ -0,0 +1,7 @@ +import tango.io.FilePath; + +class File { + private PathView path_; + void path(PathView p) { path_ = p; } + PathView path() { return path_; } +} diff --git a/Chapter03/example39.d b/Chapter03/example39.d new file mode 100644 index 0000000..e5abd59 --- /dev/null +++ b/Chapter03/example39.d @@ -0,0 +1,15 @@ +import tango.io.Stdout; +import tango.io.FilePath; + +class File { + private FilePath path_; + void path(FilePath newpath) { path_ = newpath; } + FilePath path() { return path_; } +} + +void main() { + File f = new File; + f.path = new FilePath("tango/io/FilePath.d"); + + Stdout (f.path); +} diff --git a/Chapter03/example4.d b/Chapter03/example4.d new file mode 100644 index 0000000..5e6fcf4 --- /dev/null +++ b/Chapter03/example4.d @@ -0,0 +1 @@ +public import tango.time.Time; diff --git a/Chapter03/example40.d b/Chapter03/example40.d new file mode 100644 index 0000000..1f6c231 --- /dev/null +++ b/Chapter03/example40.d @@ -0,0 +1,7 @@ +interface IConduit { } + +interface InputStream { + IConduit conduit (); + uint read (void[] dst); + void clear (); +} diff --git a/Chapter03/example41.d b/Chapter03/example41.d new file mode 100644 index 0000000..9746b63 --- /dev/null +++ b/Chapter03/example41.d @@ -0,0 +1,6 @@ +import tango.io.DeviceConduit; + +class FileConduit : DeviceConduit, DeviceConduit.Seek{ + + long seek(long offset, Anchor anchor) { return 0; } +} diff --git a/Chapter03/example42.d b/Chapter03/example42.d new file mode 100644 index 0000000..e0a002e --- /dev/null +++ b/Chapter03/example42.d @@ -0,0 +1,6 @@ +import tango.io.Stdout; + +void main() { + Stdout("Output: ", 2).newline; + Stdout.opCall("Output: ", 2).newline; +} diff --git a/Chapter03/example5.d b/Chapter03/example5.d new file mode 100644 index 0000000..e697479 --- /dev/null +++ b/Chapter03/example5.d @@ -0,0 +1,2 @@ +import tango.io.FilePath, + tango.io.FileConduit; diff --git a/Chapter03/example6.d b/Chapter03/example6.d new file mode 100644 index 0000000..5fea118 --- /dev/null +++ b/Chapter03/example6.d @@ -0,0 +1,3 @@ +import Int = tango.text.convert.Integer; + +// Use as Int.format(val) diff --git a/Chapter03/example7.d b/Chapter03/example7.d new file mode 100644 index 0000000..7998a2e --- /dev/null +++ b/Chapter03/example7.d @@ -0,0 +1 @@ +import tango.text.Util : strip, trim; diff --git a/Chapter03/example8.d b/Chapter03/example8.d new file mode 100644 index 0000000..eb554be --- /dev/null +++ b/Chapter03/example8.d @@ -0,0 +1,3 @@ +import TextUtils = tango.text.Util : clean = strip; + +// Use as TextUtils.clean() diff --git a/Chapter03/example9.d b/Chapter03/example9.d new file mode 100644 index 0000000..04319fc --- /dev/null +++ b/Chapter03/example9.d @@ -0,0 +1,3 @@ +static import tango.text.Util; + +// Use as tango.text.Util.strip(); diff --git a/Chapter04/example01.d b/Chapter04/example01.d new file mode 100644 index 0000000..87330cb --- /dev/null +++ b/Chapter04/example01.d @@ -0,0 +1,20 @@ +import tango.io.Stdout; + +int autoFunc( int x ) +{ + auto int y; + + Stdout.formatln( "y is {}, setting to {}", y, x ); + y = x; + return y; +} + +void main() +{ + int ret; + + ret = autoFunc( 1 ); + Stdout.formatln( "autoFunc returned the value of y, which is set to {}", ret ); + ret = autoFunc( 2 ); + Stdout.formatln( "autoFunc returned the value of y, which is set to {}", ret ); +} diff --git a/Chapter04/example02.d b/Chapter04/example02.d new file mode 100644 index 0000000..03a4100 --- /dev/null +++ b/Chapter04/example02.d @@ -0,0 +1,20 @@ +import tango.io.Stdout; + +int staticFunc( int x ) +{ + static int y; + + Stdout.formatln( "y is {}, setting to {}", y, x ); + y = x; + return y; +} + +void main() +{ + int ret; + + ret = staticFunc( 1 ); + Stdout.formatln( "autoFunc returned the value of y, which is set to {}", ret ); + ret = staticFunc( 2 ); + Stdout.formatln( "autoFunc returned the value of y, which is set to {}", ret ); +} diff --git a/Chapter04/example03.d b/Chapter04/example03.d new file mode 100644 index 0000000..a811b15 --- /dev/null +++ b/Chapter04/example03.d @@ -0,0 +1,25 @@ +module MyModule; +import tango.io.Stdout; + +struct MyStruct +{ + static this() + { + Stdout .formatln( "A" ); + } +} + +static this() +{ + Stdout .formatln( "B" ); +} + +class MyClass +{ + static this() + { + Stdout .formatln( "C" ); + } +} + +void main() {} diff --git a/Chapter04/example04.d b/Chapter04/example04.d new file mode 100644 index 0000000..d6be679 --- /dev/null +++ b/Chapter04/example04.d @@ -0,0 +1,26 @@ +module MyModule; + +import tango.io.Stdout; + +struct MyStruct +{ + static ~this() + { + Stdout.formatln( "A" ); + } +} + +static ~this() +{ + Stdout.formatln( "B" ); +} + +class MyClass +{ + static ~this() + { + Stdout.formatln( "C" ); + } +} + +void main() {} diff --git a/Chapter04/example05/A.d b/Chapter04/example05/A.d new file mode 100644 index 0000000..df229ef --- /dev/null +++ b/Chapter04/example05/A.d @@ -0,0 +1,9 @@ +module A; +import C; + +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "A" ); +} diff --git a/Chapter04/example05/B.d b/Chapter04/example05/B.d new file mode 100644 index 0000000..a689159 --- /dev/null +++ b/Chapter04/example05/B.d @@ -0,0 +1,10 @@ +module B; +import C; +import D; + +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "B" ); +} diff --git a/Chapter04/example05/C.d b/Chapter04/example05/C.d new file mode 100644 index 0000000..46a9a0b --- /dev/null +++ b/Chapter04/example05/C.d @@ -0,0 +1,8 @@ +module C; + +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "C" ); +} diff --git a/Chapter04/example05/D.d b/Chapter04/example05/D.d new file mode 100644 index 0000000..8d4c729 --- /dev/null +++ b/Chapter04/example05/D.d @@ -0,0 +1,9 @@ +module D; +import E; + +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "D" ); +} diff --git a/Chapter04/example05/E.d b/Chapter04/example05/E.d new file mode 100644 index 0000000..2accd54 --- /dev/null +++ b/Chapter04/example05/E.d @@ -0,0 +1,7 @@ +module E; +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "E" ); +} diff --git a/Chapter04/example05/Main.d b/Chapter04/example05/Main.d new file mode 100644 index 0000000..bdef06d --- /dev/null +++ b/Chapter04/example05/Main.d @@ -0,0 +1,15 @@ +module Main; +import A; +import B; + +import tango.io.Stdout; + +static this() +{ + Stdout.formatln( "Main" ); +} + +void main() +{ + Stdout.formatln( "Hello, World!" ); +} diff --git a/Chapter04/example06.d b/Chapter04/example06.d new file mode 100644 index 0000000..43167aa --- /dev/null +++ b/Chapter04/example06.d @@ -0,0 +1,15 @@ +import tango.io.Stdout; + +void alter( char[7] param ) +{ + param[] = "7654321"; +} + +void main() +{ + char[7] message = "1234567"; + + Stdout.formatln( "{}", message ); + alter( message ); + Stdout.formatln( "{}", message ); +} diff --git a/Chapter04/example07.d b/Chapter04/example07.d new file mode 100644 index 0000000..5211141 --- /dev/null +++ b/Chapter04/example07.d @@ -0,0 +1,16 @@ +import tango.io.Stdout; + +char[] getMessage() +{ + char[5] buf = "hello"; + char[] ret = buf; + + return ret; +} + +void main() +{ + char[] msg = getMessage(); + + Stdout.formatln( "{}", msg ); +} diff --git a/Chapter04/example08.d b/Chapter04/example08.d new file mode 100644 index 0000000..4bbcc21 --- /dev/null +++ b/Chapter04/example08.d @@ -0,0 +1,30 @@ +// This is an example of a program that exhibits undefined behavior and so a +// program crash or garbled output is expected. + +import tango.io.Stdout; + +alias void delegate() Operation; + +void perform( Operation op ) +{ + op(); +} + +Operation func() +{ + int x = 0; + + void putAndIncrement() + { + Stdout.formatln( "x is {}", x++ ); + } + + perform( &putAndIncrement ); + return &putAndIncrement; +} + +void main() +{ + Operation op = func(); + perform( op ); +} diff --git a/Chapter04/example09.d b/Chapter04/example09.d new file mode 100644 index 0000000..8d19fe2 --- /dev/null +++ b/Chapter04/example09.d @@ -0,0 +1,30 @@ +// This is an example of a program that exhibits undefined behavior and so a +// program crash or garbled output is expected. + +import tango.io.Stdout; + +alias void delegate() Operation; + +void perform( Operation op ) +{ + op(); +} + +Operation func() +{ + char[] message = "hello"; + + void putMessage() + { + Stdout.formatln( message ); + } + + perform( &putMessage ); + return &putMessage; +} + +void main() +{ + Operation op = func(); + perform( op ); +} diff --git a/Chapter05/ObjectList.d b/Chapter05/ObjectList.d new file mode 100644 index 0000000..3ce593e --- /dev/null +++ b/Chapter05/ObjectList.d @@ -0,0 +1,34 @@ +module ObjectList; + +class List +{ + void insert( Object o ) + { + head = new Node( o, head ); + } + + int opApply( int delegate( inout Object ) dg ) + { + for( Node n = head; n; n = n.next ) + { + if( auto r = dg( n.elem ) ) + return r; + } + return 0; + } + +private: + static class Node + { + Object elem; + Node next; + + this( Object e, Node n ) + { + elem = e; + next = n; + } + } + + Node head; +} diff --git a/Chapter05/TemplateList.d b/Chapter05/TemplateList.d new file mode 100644 index 0000000..39fd298 --- /dev/null +++ b/Chapter05/TemplateList.d @@ -0,0 +1,37 @@ +module TemplateList; + +template List( T ) +{ + class List + { + void insert( T val ) + { + head = new Node( val, head ); + } + + int opApply( int delegate( inout T ) dg ) + { + for( Node n = head; n; n = n.next ) + { + if( auto r = dg( n.elem ) ) + return r; + } + return 0; + } + + private: + static class Node + { + T elem; + Node next; + + this( T e, Node n ) + { + elem = e; + next = n; + } + } + + Node head; + } +} diff --git a/Chapter05/example01.d b/Chapter05/example01.d new file mode 100644 index 0000000..18a4203 --- /dev/null +++ b/Chapter05/example01.d @@ -0,0 +1,22 @@ +import ObjectList; +import tango.io.Stdout; + +void main() +{ + class Integer + { + int val; + + this( int v ) + { + val = v; + } + } + + auto list = new List; + for( int i = 3; i; --i ) + list.insert( new Integer( i ) ); + + foreach( elem; list ) + Stdout.formatln( "{}", (cast(Integer) elem).val ); +} diff --git a/Chapter05/example02.d b/Chapter05/example02.d new file mode 100644 index 0000000..b36ea61 --- /dev/null +++ b/Chapter05/example02.d @@ -0,0 +1,12 @@ +import TemplateList; +import tango.io.Stdout; + +void main() +{ + auto list = new List!(int); + for( int i = 3; i; --i ) + list.insert( i ); + + foreach( elem; list ) + Stdout.formatln( "{}", elem ); +} diff --git a/Chapter05/example03.d b/Chapter05/example03.d new file mode 100644 index 0000000..a62c282 --- /dev/null +++ b/Chapter05/example03.d @@ -0,0 +1,18 @@ +import TemplateList; +import tango.io.Stdout; + +void printContents( T )( T list ) +{ + foreach( elem; list ) + Stdout.formatln( "{}", elem ); +} + +void main() +{ + auto list = new List!(int); + + for( int i = 3; i; --i ) + list.insert( i ); + + printContents!(List!(int))( list ); +} diff --git a/Chapter05/example04.d b/Chapter05/example04.d new file mode 100644 index 0000000..a149ded --- /dev/null +++ b/Chapter05/example04.d @@ -0,0 +1,25 @@ +void func( T )( T val ) +{ + pragma( msg, "func( T )( T val )" ); +} + +void func(T, U = void )( T[] val ) +{ + pragma( msg, "func( T )( T[] val )" ); +} + +void func( T, U = void, V = void )( T* val ) +{ + pragma( msg, "func( T )( T* val )" ); +} + +void main() +{ + int i; + int* p; + int[] a; + + func( i ); + func( p ); + func( a ); +} diff --git a/Chapter05/example05.d b/Chapter05/example05.d new file mode 100644 index 0000000..ad4d9fc --- /dev/null +++ b/Chapter05/example05.d @@ -0,0 +1,21 @@ +template List( T ) +{ + pragma( msg, "List( T )" ); +} + +template List( T : int ) +{ + pragma( msg, "List( T : int )" ); +} + +template List( T : T[] ) +{ + pragma( msg, "List( T : T[] )" ); +} + +void main() +{ + alias List!(char) A; + alias List!(int) B; + alias List!(char[]) C; +} diff --git a/Chapter05/example06.d b/Chapter05/example06.d new file mode 100644 index 0000000..21caf3c --- /dev/null +++ b/Chapter05/example06.d @@ -0,0 +1,45 @@ +enum Color +{ + RED, + BLUE +} + +template Choice( int i : 1 ) +{ + pragma( msg, "Choice: int = 1" ); +} + +template Choice( int i : 2 ) +{ + pragma( msg, "Choice: int = 2" ); +} + +template Choice( bool b : true ) +{ + pragma( msg, "Choice: bool = true" ); +} + +template Choice( float f ) +{ + pragma( msg, "Choice: float = ?" ); +} + +template Choice( Color c : Color.BLUE ) +{ + pragma( msg, "Choice: Color = BLUE" ); +} + +template Choice( char[] s ) +{ + pragma( msg, "Choice: s = " ~ s ); +} + +void main() +{ + alias Choice!(1) A; + alias Choice!(2) B; + alias Choice!(3.0) C; + alias Choice!(true) D; + alias Choice!(Color.BLUE) E; + alias Choice!("Hello, D!") F; +} diff --git a/Chapter05/example07.d b/Chapter05/example07.d new file mode 100644 index 0000000..a1826c0 --- /dev/null +++ b/Chapter05/example07.d @@ -0,0 +1,15 @@ +template Choice( T, size_t size : 4 = T.sizeof ) +{ + pragma( msg, "Choice: size = 4" ); +} + +template Choice( T, size_t size : 8 = T.sizeof ) +{ + pragma( msg, "Choice: size = 8" ); +} + +void main() +{ + alias Choice!(int) A; + alias Choice!(long) B; +} diff --git a/Chapter05/example08.d b/Chapter05/example08.d new file mode 100644 index 0000000..5ff0611 --- /dev/null +++ b/Chapter05/example08.d @@ -0,0 +1,25 @@ +import tango.io.Stdout; + +template ChooseType( bool b ) +{ + alias long ChooseType; +} + +template ChooseType( bool b : true ) +{ + alias short ChooseType; +} + +template isSizeLessThan4( T ) +{ + const bool isSizeLessThan4 = T.sizeof < 4; +} + +void main() +{ + alias ChooseType!(isSizeLessThan4!(int)) WhenGreaterThan4; + alias ChooseType!(isSizeLessThan4!(byte)) WhenLessThan4; + + Stdout.formatln( "WhenGreaterThan4.sizeof = {}", WhenGreaterThan4.sizeof ); + Stdout.formatln( "WhenLessThan4.sizeof = {}", WhenLessThan4.sizeof ); +} diff --git a/Chapter05/example09.d b/Chapter05/example09.d new file mode 100644 index 0000000..5dbc038 --- /dev/null +++ b/Chapter05/example09.d @@ -0,0 +1,12 @@ +import tango.io.Stdout; + +template isPointer( T ) +{ + const bool isPointer = is( typeof(*T) ); +} + +void main() +{ + Stdout.formatln( "isPointer!(int) = {}", isPointer!(int) ); + Stdout.formatln( "isPointer!(char*) = {}", isPointer!(char*) ); +} diff --git a/Chapter05/example10.d b/Chapter05/example10.d new file mode 100644 index 0000000..08458f5 --- /dev/null +++ b/Chapter05/example10.d @@ -0,0 +1,19 @@ +import tango.io.Stdout; + +template convertsToAnInt( T ) +{ + const bool convertsToAnInt = is( T : int ); +} + +template isExactlyAnInt( T ) +{ + const bool isExactlyAnInt = is( T == int ); +} + +void main() +{ + Stdout.formatln( "convertsToAnInt!(byte) = {}", convertsToAnInt!(byte) ); + Stdout.formatln( "convertsToAnInt!(char*) = {}", convertsToAnInt!(char*) ); + Stdout.formatln( "isExactlyAnInt!(int) = {}", isExactlyAnInt!(int) ); + Stdout.formatln( "isExactlyAnInt!(byte) = {}", isExactlyAnInt!(byte) ); +} diff --git a/Chapter05/example11.d b/Chapter05/example11.d new file mode 100644 index 0000000..58a3dbf --- /dev/null +++ b/Chapter05/example11.d @@ -0,0 +1,15 @@ +template WhileNotZero( int i ) +{ + pragma( msg, "Hello, D!" ); + alias WhileNotZero!(i - 1) Dummy; +} + +template WhileNotZero( int i : 0 ) +{ + // Terminate loop +} + +void main() +{ + alias WhileNotZero!(3) LoopThreeTimes; +} diff --git a/Chapter05/example12.d b/Chapter05/example12.d new file mode 100644 index 0000000..f09e735 --- /dev/null +++ b/Chapter05/example12.d @@ -0,0 +1,15 @@ +import tango.io.Stdout; + +int multiply( int x, int y ) +{ + int result = 0; + for( int i = 0; i < y; ++i ) + result += x; + return result; +} + +void main() +{ + static const result = multiply( 2, 3 ); + Stdout.formatln( "2 * 3 is {}", result ); +} diff --git a/Chapter06/example1.d b/Chapter06/example1.d new file mode 100644 index 0000000..a5d3881 --- /dev/null +++ b/Chapter06/example1.d @@ -0,0 +1,8 @@ +import tango.text.Util; +import tango.io.Console; + +void main() { + char[] original = "A string to have some letters replaced"; + auto result = replace (original.dup, 'r' , 'l'); + Cout (result).newline; +} diff --git a/Chapter06/example10.d b/Chapter06/example10.d new file mode 100644 index 0000000..047ba6b --- /dev/null +++ b/Chapter06/example10.d @@ -0,0 +1,9 @@ +import Integer = tango.text.convert.Integer; +import tango.io.Console; + +void main() { + auto text = Integer.format (new char[32], 12345L, + Integer.Style.HexUpper, + Integer.Flags.Prefix); + Cout (text).newline; +} diff --git a/Chapter06/example11.d b/Chapter06/example11.d new file mode 100644 index 0000000..adf9876 --- /dev/null +++ b/Chapter06/example11.d @@ -0,0 +1,7 @@ +import Float = tango.text.convert.Float; +import tango.io.Console; + +void main() { + auto text = Float.format (new char[64], 223.1456667, 5, 2); + Cout (text).newline; +} diff --git a/Chapter06/example12.d b/Chapter06/example12.d new file mode 100644 index 0000000..2ca484d --- /dev/null +++ b/Chapter06/example12.d @@ -0,0 +1,9 @@ +import TimeStamp = tango.text.convert.TimeStamp; +import tango.io.Console; + +void main() { + auto date = "Sun, 06 Nov 1994 08:49:37 GMT"; + auto msSinceJan1st0001 = TimeStamp.parse (date); + auto text = TimeStamp.format (new char[64], msSinceJan1st0001); + Cout (text).newline; +} diff --git a/Chapter06/example13.d b/Chapter06/example13.d new file mode 100644 index 0000000..a2e2423 --- /dev/null +++ b/Chapter06/example13.d @@ -0,0 +1,5 @@ +import tango.io.Stdout; + +void main() { + Stdout.format ("Printing the value {} to the {}", 5, "console").newline; +} diff --git a/Chapter06/example14.d b/Chapter06/example14.d new file mode 100644 index 0000000..3ddc86f --- /dev/null +++ b/Chapter06/example14.d @@ -0,0 +1,6 @@ +import tango.io.Stdout; + +void main() { + Stdout.format ("Printing the value {0} to the {1}", 5, "console").newline; + Stdout.format ("Printing the value {1} to the {0}", "console", 5).newline; +} diff --git a/Chapter06/example15.d b/Chapter06/example15.d new file mode 100644 index 0000000..ff49f44 --- /dev/null +++ b/Chapter06/example15.d @@ -0,0 +1,8 @@ +import tango.io.Stdout; + +void main() { + char[] s = "I"; // subject + char[] o = "Bill"; // object + Stdout.format ("{0} can see {1}.", s, o).newline; + Stdout.format ("{1} {0} can see.", s, o).newline; +} diff --git a/Chapter06/example16.d b/Chapter06/example16.d new file mode 100644 index 0000000..937e650 --- /dev/null +++ b/Chapter06/example16.d @@ -0,0 +1,5 @@ +import tango.io.Stdout; + +void main() { + Stdout.format ("Printing the value {0} and then the same again {0}", 5).newline; +} diff --git a/Chapter06/example17.d b/Chapter06/example17.d new file mode 100644 index 0000000..18dcbe7 --- /dev/null +++ b/Chapter06/example17.d @@ -0,0 +1,12 @@ +import tango.io.Stdout; + +void main() { + char[] myFName = "Johnny"; + Stdout.formatln("First Name = |{0,15}|", myFName); + Stdout.formatln("Last Name = |{0,15}|", "Foo de Bar"); + + Stdout.formatln("First Name = |{0,-15}|", myFName); + Stdout.formatln("Last Name = |{0,-15}|", "Foo de Bar"); + + Stdout.formatln("First name = |{0,5}|", myFName); +} diff --git a/Chapter06/example18.d b/Chapter06/example18.d new file mode 100644 index 0000000..28ab984 --- /dev/null +++ b/Chapter06/example18.d @@ -0,0 +1,5 @@ +import tango.io.Stdout; + +void main() { + Stdout.formatln ("I have {:G} birds on the roof", 100); +} diff --git a/Chapter06/example19.d b/Chapter06/example19.d new file mode 100644 index 0000000..5f0ad6e --- /dev/null +++ b/Chapter06/example19.d @@ -0,0 +1,5 @@ +import tango.io.Stdout; + +void main() { + Stdout.formatln ("A hexadecimal number follows: {0:X9}", 0xafe0000); +} diff --git a/Chapter06/example2.d b/Chapter06/example2.d new file mode 100644 index 0000000..c107eb8 --- /dev/null +++ b/Chapter06/example2.d @@ -0,0 +1,5 @@ +import tango.text.Util; + +void main() { + locatePatternPrior ("ababababaaaab", "aba", 8); +} diff --git a/Chapter06/example20.d b/Chapter06/example20.d new file mode 100644 index 0000000..4fe11c7 --- /dev/null +++ b/Chapter06/example20.d @@ -0,0 +1,8 @@ +import tango.text.convert.Layout; +import tango.io.Console; + +void main() { + auto layout = new Layout!(char); // Need to specify encoding you are going to use + auto result = layout("A format {}", "string"); + Cout (result).newline; +} diff --git a/Chapter06/example21.d b/Chapter06/example21.d new file mode 100644 index 0000000..088f43c --- /dev/null +++ b/Chapter06/example21.d @@ -0,0 +1,5 @@ +import tango.text.locale.Locale; + +void main () { + auto locale = new Locale; +} diff --git a/Chapter06/example22.d b/Chapter06/example22.d new file mode 100644 index 0000000..1f73c14 --- /dev/null +++ b/Chapter06/example22.d @@ -0,0 +1,6 @@ +import tango.text.locale.Locale; +import tango.io.Stdout; + +void main() { + Stdout.layout = new Locale; +} diff --git a/Chapter06/example23.d b/Chapter06/example23.d new file mode 100644 index 0000000..9b6667f --- /dev/null +++ b/Chapter06/example23.d @@ -0,0 +1,5 @@ +import tango.text.locale.Locale; + +void main() { + auto locale = new Locale(Culture.getCulture("fr-FR")); +} diff --git a/Chapter06/example24.d b/Chapter06/example24.d new file mode 100644 index 0000000..ec3f695 --- /dev/null +++ b/Chapter06/example24.d @@ -0,0 +1,8 @@ +import tango.io.Console; +import tango.time.WallClock; +import tango.text.locale.Locale; + +void main() { + auto layout = new Locale; + Cout (layout ("{:ddd, dd MMMM yyyy HH':'mm':'ss z}", WallClock.now)).newline; +} diff --git a/Chapter06/example3.d b/Chapter06/example3.d new file mode 100644 index 0000000..c69828f --- /dev/null +++ b/Chapter06/example3.d @@ -0,0 +1,8 @@ +import tango.text.Util; +import tango.io.Console; + +void main() { + foreach (segment; patterns("one, two, three", ", ")) { + Cout (segment).newline; + } +} diff --git a/Chapter06/example4.d b/Chapter06/example4.d new file mode 100644 index 0000000..3cfd972 --- /dev/null +++ b/Chapter06/example4.d @@ -0,0 +1,8 @@ +import tango.text.Util; +import tango.io.Console; + +void main() { + foreach (segment; quotes ("one two 'three four' five", " ")) { + Cout (segment).newline; + } +} diff --git a/Chapter06/example5.d b/Chapter06/example5.d new file mode 100644 index 0000000..a8a6f64 --- /dev/null +++ b/Chapter06/example5.d @@ -0,0 +1,8 @@ +import tango.io.FileConduit, + tango.io.Console; +import tango.text.stream.LineIterator; + +void main() { + foreach (line; new LineIterator!(char) ( new FileConduit ("filename") )) + Cout (line).newline; +} diff --git a/Chapter06/example6.d b/Chapter06/example6.d new file mode 100644 index 0000000..7fa2eb5 --- /dev/null +++ b/Chapter06/example6.d @@ -0,0 +1,8 @@ +import tango.text.Text; + +void main() { + auto text = new Text!(char)("The couple danced the rumba"); + text.select("couple"); + text.replace("party").prepend("large ").select("rumba"); + text.replace("tango"); +} diff --git a/Chapter06/example7.d b/Chapter06/example7.d new file mode 100644 index 0000000..b50db82 --- /dev/null +++ b/Chapter06/example7.d @@ -0,0 +1,11 @@ +import tango.text.Text; +import Util = tango.text.Util; +import tango.io.Console; + +void main() { + auto source = new Text!(char)("one\ntwo\nthree"); + + foreach (line; Util.lines(source.slice)) { + Cout (line).newline; + } +} diff --git a/Chapter06/example8.d b/Chapter06/example8.d new file mode 100644 index 0000000..444de32 --- /dev/null +++ b/Chapter06/example8.d @@ -0,0 +1,9 @@ +import tango.text.Text; +import Util = tango.text.Util; + +void main() { + auto dst = new Text!(char); + foreach (element; Util.patterns ("all cows eat grass", "eat", "chew")) { + dst.append (element); + } +} diff --git a/Chapter06/example9.d b/Chapter06/example9.d new file mode 100644 index 0000000..55bc12c --- /dev/null +++ b/Chapter06/example9.d @@ -0,0 +1,8 @@ +import tango.text.convert.Integer; +import tango.io.Console; + +void main() { + char[10] output; + auto result = format (output, 15); + Cout (result).newline; +} diff --git a/Chapter07/filescan.d b/Chapter07/filescan.d new file mode 100644 index 0000000..917ec69 --- /dev/null +++ b/Chapter07/filescan.d @@ -0,0 +1,21 @@ +import tango.io.Stdout, + tango.io.FileScan; + +void main() +{ + char[] root = "."; + auto scan = (new FileScan)(root, ".d"); + + Stdout.formatln ("Scanning '{}'", root); + Stdout.format ("\n{} Folders\n", scan.folders.length); + foreach (folder; scan.folders) + Stdout.format ("{}\n", folder); + + Stdout.format ("\n{0} Files\n", scan.files.length); + foreach (file; scan.files) + Stdout.format ("{}\n", file); + + Stdout.formatln ("\n{} Errors", scan.errors.length); + foreach (error; scan.errors) + Stdout (error).newline; +} diff --git a/Chapter07/name.d b/Chapter07/name.d new file mode 100644 index 0000000..e0ea5ac --- /dev/null +++ b/Chapter07/name.d @@ -0,0 +1,8 @@ +import tango.io.Console; + +void main() +{ + Cout ("What is your name? ").flush; + auto name = Cin.copyln; + Cout ("Hello ")(name).newline; +} diff --git a/Chapter07/path.d b/Chapter07/path.d new file mode 100644 index 0000000..464e43f --- /dev/null +++ b/Chapter07/path.d @@ -0,0 +1,19 @@ +import tango.io.Console, + tango.io.FilePath; + +void main (char[][] args) +{ + auto path = new FilePath ("/dev/tango/io/FilePath.d"); + Cout (path).newline; + Cout (path.folder).newline; + Cout (path.file).newline; + Cout (path.name).newline; + Cout (path.suffix).newline; + Cout (path.ext).newline.newline; + + Cout (path.set("tango/io/Console.d")).newline; + Cout (path.folder("other")).newline; + Cout (path.file("myfile.x.y")).newline; + Cout (path.name("test")).newline; + Cout (path.suffix("txt")).newline; +} diff --git a/Chapter08/arraybag.d b/Chapter08/arraybag.d new file mode 100644 index 0000000..196ec66 --- /dev/null +++ b/Chapter08/arraybag.d @@ -0,0 +1,22 @@ +import tango.io.Stdout; +import tango.util.collection.ArrayBag; + +class MyClass +{ + void print() + { + Stdout("Hello ArrayBag").newline; + } +} + +void main() +{ + // Fill an array bag with 10 instances of MyClass + ArrayBag!(MyClass) bag = new ArrayBag!(MyClass); + for(int i=0; i<10; ++i) + bag.add(new MyClass); + + // Iterate the bag and perform a common operation + foreach(mc; bag) + mc.print(); +} \ No newline at end of file diff --git a/Chapter08/arrayseq.d b/Chapter08/arrayseq.d new file mode 100644 index 0000000..6d9c84b --- /dev/null +++ b/Chapter08/arrayseq.d @@ -0,0 +1,38 @@ +import tango.io.Stdout; +import tango.util.collection.ArraySeq; + +// Given a number n, generates the next number in the +// Fibonacci sequence +int fibonacci(int n) +{ + if(n == 0) return 0; + else if(n == 1) return 1; + else return fibonacci(n-1) + fibonacci(n-2); +} + +void main() +{ + // Create an array sequence to store integers + ArraySeq!(int) seq = new ArraySeq!(int); + + // We are using a fixed set of numbers, so set the capacity to 10 + seq.capacity = 10; + + // Populate the collection + for(int i=0; i<10; ++i) + seq.append(fibonacci(i)); + + // Print the sequence to the console + foreach(i; seq) + Stdout(i).newline; + + // Now test the numbers 0 - 19 to see if they are in the collection. + // Print PASS if a number is in the collection, and FAIL if it isn't. + for(int i=0; i<20; ++i) + { + if(seq.contains(i)) + Stdout.formatln("{}: PASS", i); + else + Stdout.formatln("{}: FAIL", i); + } +} \ No newline at end of file diff --git a/Chapter08/fibers.d b/Chapter08/fibers.d new file mode 100644 index 0000000..cf0fd40 --- /dev/null +++ b/Chapter08/fibers.d @@ -0,0 +1,23 @@ +import tango.io.Stdout; +import tango.core.Thread; + +void main() +{ + void printDg() + { + for(int i=0; i<10; ++i) + { + Stdout.formatln("i = {}", i); + Stdout("Yielding fiber.").newline; + Fiber.yield(); + Stdout("Back in the fiber").newline; + } + } + + Fiber f = new Fiber(&printDg); + for(int i=0; i<10; ++i) + { + Stdout("Calling fiber.").newline; + f.call(); + } +} \ No newline at end of file diff --git a/Chapter08/hashset.d b/Chapter08/hashset.d new file mode 100644 index 0000000..0c321dd --- /dev/null +++ b/Chapter08/hashset.d @@ -0,0 +1,35 @@ +import tango.io.Stdout; +import tango.util.collection.HashSet; + +// Given a number n, generates the next number in the +// Fibonacci sequence +int fibonacci(int n) +{ + if(n == 0) return 0; + else if(n == 1) return 1; + else return fibonacci(n-1) + fibonacci(n-2); +} + +void main() +{ + // Create a hash set to store integers + HashSet!(int) set = new HashSet!(int); + + // Populate the set with the first 10 numbers in the Fibonacci sequence + for(int i=0; i<10; ++i) + set.add(fibonacci(i)); + + // Print the sequence to the console + foreach(i; set) + Stdout(i).newline; + + // Now test the numbers 0 - 19 to see if they are in the set. + // Print PASS if a number is in the set, and FAIL if it isn't. + for(int i=0; i<20; ++i) + { + if(set.contains(i)) + Stdout.formatln("{}: PASS", i); + else + Stdout.formatln("{}: FAIL", i); + } +} \ No newline at end of file diff --git a/Chapter08/logFile.d b/Chapter08/logFile.d new file mode 100644 index 0000000..f9d90f6 --- /dev/null +++ b/Chapter08/logFile.d @@ -0,0 +1,13 @@ +import tango.util.log.Log; +import tango.util.log.FileAppender; +import tango.util.log.EventLayout; +import tango.io.FilePath; + +void main() +{ + auto fa = new FileAppender(new FilePath("log.txt"), new SimpleTimerLayout); + Log.getRootLogger.addAppender(fa); + + Logger logger = Log.getLogger("MyLogger"); + logger.info("Hello file appender!"); +} \ No newline at end of file diff --git a/Chapter08/logLevels.d b/Chapter08/logLevels.d new file mode 100644 index 0000000..335b9eb --- /dev/null +++ b/Chapter08/logLevels.d @@ -0,0 +1,22 @@ +import tango.util.log.Configurator; +import tango.util.log.Log; + +void main() +{ + Logger logger = Log.getLogger("MyLogger"); + + // Turn off Trace messages + logger.level = Logger.Level.Info; + + logger.trace("I'm a trace message, but you can't see me!"); + logger.info("I'm an info message!"); + logger.warn("I'm a warn message!"); + logger.error("I'm an error message!"); + logger.fatal("I'm a fatal message!"); + logger.append(Logger.Level.Fatal, "I'm a fatal message, too!"); + + // Turn Trace messages back on + logger.level = Logger.level.Trace; + + logger.trace("Hey, you can see trace messages now!"); +} \ No newline at end of file diff --git a/Chapter08/loggerCreation.d b/Chapter08/loggerCreation.d new file mode 100644 index 0000000..f3edf07 --- /dev/null +++ b/Chapter08/loggerCreation.d @@ -0,0 +1,8 @@ +import tango.util.log.Configurator; +import tango.util.log.Log; + +void main() +{ + Logger logger = Log.getLogger("MyLogger"); + logger.info("Hello world"); +} \ No newline at end of file diff --git a/Chapter08/thread01.d b/Chapter08/thread01.d new file mode 100644 index 0000000..f3781e9 --- /dev/null +++ b/Chapter08/thread01.d @@ -0,0 +1,37 @@ +import tango.io.Stdout; +import tango.core.Thread; + + +void main() +{ + + + + + void printDg() + { + Thread thisThread = Thread.getThis; + + for(int i=0; i<10; ++i) + { + Stdout.formatln("{}: {}", thisThread.name, i); + + } + + Stdout.formatln("{} is going to sleep!", thisThread.name); + Thread.sleep(1.0); // Sleep for 1 second + Stdout.formatln("{} is awake.", Thread.name); + } + + Thread thread1 = new Thread(&printDg); + thread1.name = "Thread #1"; + + Thread thread2 = new Thread(&printDg); + thread2.name = "Thread #2"; + + thread1.start(); + thread2.start(); + + thread_joinAll(); + Stdout("Both threads have exited").newline; +} \ No newline at end of file diff --git a/Chapter08/thread02.d b/Chapter08/thread02.d new file mode 100644 index 0000000..1195d84 --- /dev/null +++ b/Chapter08/thread02.d @@ -0,0 +1,37 @@ +import tango.io.Stdout; +import tango.core.Thread; + +class MyThread : Thread +{ + int id; + + this(int id) + { + super(&run); + this.id = id; + } + + void run() + { + for(int i=0; i<10; ++i) + { + Stdout.formatln("Thread {}: {}", id, i); + } + + Stdout.formatln("Thread #{} is going to sleep!", id); + Thread.sleep(1.0); // Sleep for 1 second + Stdout.formatln("Thread #{} has awakened and will now exit.", id); + } +} + +void main() +{ + Thread thread1 = new MyThread(1); + Thread thread2 = new MyThread(2); + + thread1.start(); + thread2.start(); + + thread_joinAll(); + Stdout("Both threads have exited").newline; +} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..feb0c79 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2007 Kris Bell, Lars Ivar Igesund, Sean Kelly, and Erik Parker + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c97bd3 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*Learn to Tango with D*](http://www.apress.com/9781590599600) by Kris Bell, Lars Ivar Igesund, Sean Kelly, and Erik Parker (Apress, 2007). + +![Cover image](9781590599600.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file