From 6529748da383c52c6cd1487b86b051b15047d48e Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:30:16 -0400 Subject: [PATCH 01/20] Prompt addition of D --- .d.html.markdown.swp | Bin 0 -> 12288 bytes d.html.markdown | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .d.html.markdown.swp create mode 100644 d.html.markdown diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp new file mode 100644 index 0000000000000000000000000000000000000000..f310c87d09d4381c3283e1642e5faa599ef78ed7 GIT binary patch literal 12288 zcmeI2y>A>v7{(`vf{!>vq(TDe^+m`wzTG=JiGu7nQour3K%9bLA;ogd$WZ4HT4=2!Rj0z3;4a zy6JUaS$m1jr)L?ClZ@T}m%q9=^*Ouv2xD4i+u`>A9lhE~Eu2ewX7_eu-wFmht0t>U zp}p%U!L8nvdQ?hXd*PDYWUiB^17E7NIN| zx;0Iw9=&>JbK|H;AQFfKB7sOC5{LvMfk+?{xF-ns>KMC@OzxXxvobj!J93_Uji*Q; z5{LvMfk+?{hy)^mNFWl31R{Y*AQHF>3Gke;4<2CbqX!W@{{P?m{r?C4|Njm85&9as z3EhC+hOR?TLEoQX%tDVrUrjMqK)ap)BE=R=JB3jG3o4E3RP=sdIlb)nDJsbYi{C0C@1#6gqwQ<<)J~cKdb3UTBMZ~T9|8w_l*@i8(gzuM_4Cj)fd`wz>(;zF8Ay=Rg-9eQ~nC`~DYZ|nmlPMOgjn?gYW!m4 zbH)O zH#h&zRnzh3>U(x4Vyq*WQpO@LUdw)eb?1TZn`Fs1gVgVOf#W4!4r` zlyFCx9<3Cn&H@)nSnV$3bb-#{G(R7l?iiU<$)%ocLXc&JVv+NC3Q4of5X7@a=h91~ zxdL0jQ^r(|hQ@9acO-Tzk$I7)dmXkHK%g1yR_bDN3neIAa1B4< zlB6S3jh!)e%Wz&bHEnA%L@~IZai}%+{}ySQGITk9j^uSNTuK|#4~Q#89>d6>zNU|B zK|?-jlM-Pn5c*OUTz@UjBWX|@`o;F*^@LX9X#D=Sk0d2d7;TzRy`GgcM@-@v$} zb1NiWQkWkuT~@cr4-L7x!bpdW$i7YJOa)t+F^Vxx@WUNPQQSy-zT0jr^%Q>{nNXiQ zPne6sm0V|HnwYCIB;#lRx56gI=Ak!hjTns{7o`wdSec=Aw$6NwKpLY5gLWh*FOXtb zBk%|`Loi~cD2*MV2{bQ6*je31lPT=ThC?UHo&v5=^~#`&;1+%72c_^bL!PDyDN%t@ zSaoCXj#!w197D=FtI@GK8;#9y3)ezPSB~x48X1Jb6ud;0`qq>v%y43}k0sqCGeN-0 zT6vjNu#(FHBeA?|1m5HVbinBlTA<&wa#%R)>sQ+Qw7A0BHihM7Xqz@66Mpyxw#O{M?< literal 0 HcmV?d00001 diff --git a/d.html.markdown b/d.html.markdown new file mode 100644 index 00000000..9f322423 --- /dev/null +++ b/d.html.markdown @@ -0,0 +1,61 @@ +--- +language: d +filename: learnd.d +contributors: + - ["Nick Papanastasiou", "www.nickpapanastasiou.github.io"] +lang: en +--- + +If you're like me and spend way to much time on the internet, odds are you've heard +about [D](http://dlang.org/). The D programming language is a modern, general-purpose, +multi-paradigm language with fantastic support for OOP, functional programming, metaprogramming, +and easy concurrency and parallelism, and runs the gamut from low-level features such as +memory management, inline assembly, and pointer arithmetic, to high-level constructs +such as higher-order functions and generic structures and functions via templates, all with +a pleasant syntax, and blazing fast performance! + +D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool +dudes. With all that out of the way, let's look at some examples! + +'''d +// You know what's coming... +import std.stdio; + +// args is optional +void main(string[] args) { + writeln("Hello, World!"); +} + +// Conditionals and loops work as expected. +import std.stdio; + +void main() { + for(int i = 0; i < 5; i++) { + writeln(i); + } + + auto n = 1; // use auto for type inferred variables + + while(n < 10_000) { + n += n; + } + + do { + n -= (n / 2); + } while(n > 0); + + // For and while are nice, but in D-land we prefer foreach + foreach(i; 1..int.max) { // The .. creates a continuous range + if(n % 2 == 0) + writeln(i); + } + + foreach_reverse(i; short.max) { + if(n % 2 == 1) + writeln(i); + else + writeln("No!"); + } +} + +''' From de5d895079abaa81d83734a332f993a7fced8282 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:30:44 -0400 Subject: [PATCH 02/20] Prompt addition of D --- .d.html.markdown.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp deleted file mode 100644 index f310c87d09d4381c3283e1642e5faa599ef78ed7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2y>A>v7{(`vf{!>vq(TDe^+m`wzTG=JiGu7nQour3K%9bLA;ogd$WZ4HT4=2!Rj0z3;4a zy6JUaS$m1jr)L?ClZ@T}m%q9=^*Ouv2xD4i+u`>A9lhE~Eu2ewX7_eu-wFmht0t>U zp}p%U!L8nvdQ?hXd*PDYWUiB^17E7NIN| zx;0Iw9=&>JbK|H;AQFfKB7sOC5{LvMfk+?{xF-ns>KMC@OzxXxvobj!J93_Uji*Q; z5{LvMfk+?{hy)^mNFWl31R{Y*AQHF>3Gke;4<2CbqX!W@{{P?m{r?C4|Njm85&9as z3EhC+hOR?TLEoQX%tDVrUrjMqK)ap)BE=R=JB3jG3o4E3RP=sdIlb)nDJsbYi{C0C@1#6gqwQ<<)J~cKdb3UTBMZ~T9|8w_l*@i8(gzuM_4Cj)fd`wz>(;zF8Ay=Rg-9eQ~nC`~DYZ|nmlPMOgjn?gYW!m4 zbH)O zH#h&zRnzh3>U(x4Vyq*WQpO@LUdw)eb?1TZn`Fs1gVgVOf#W4!4r` zlyFCx9<3Cn&H@)nSnV$3bb-#{G(R7l?iiU<$)%ocLXc&JVv+NC3Q4of5X7@a=h91~ zxdL0jQ^r(|hQ@9acO-Tzk$I7)dmXkHK%g1yR_bDN3neIAa1B4< zlB6S3jh!)e%Wz&bHEnA%L@~IZai}%+{}ySQGITk9j^uSNTuK|#4~Q#89>d6>zNU|B zK|?-jlM-Pn5c*OUTz@UjBWX|@`o;F*^@LX9X#D=Sk0d2d7;TzRy`GgcM@-@v$} zb1NiWQkWkuT~@cr4-L7x!bpdW$i7YJOa)t+F^Vxx@WUNPQQSy-zT0jr^%Q>{nNXiQ zPne6sm0V|HnwYCIB;#lRx56gI=Ak!hjTns{7o`wdSec=Aw$6NwKpLY5gLWh*FOXtb zBk%|`Loi~cD2*MV2{bQ6*je31lPT=ThC?UHo&v5=^~#`&;1+%72c_^bL!PDyDN%t@ zSaoCXj#!w197D=FtI@GK8;#9y3)ezPSB~x48X1Jb6ud;0`qq>v%y43}k0sqCGeN-0 zT6vjNu#(FHBeA?|1m5HVbinBlTA<&wa#%R)>sQ+Qw7A0BHihM7Xqz@66Mpyxw#O{M?< From ab637d83f235a1766cbfc4c8a1d84cde4a670820 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:30:16 -0400 Subject: [PATCH 03/20] Prompt addition of D --- .d.html.markdown.swp | Bin 0 -> 12288 bytes d.html.markdown | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .d.html.markdown.swp create mode 100644 d.html.markdown diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp new file mode 100644 index 0000000000000000000000000000000000000000..f310c87d09d4381c3283e1642e5faa599ef78ed7 GIT binary patch literal 12288 zcmeI2y>A>v7{(`vf{!>vq(TDe^+m`wzTG=JiGu7nQour3K%9bLA;ogd$WZ4HT4=2!Rj0z3;4a zy6JUaS$m1jr)L?ClZ@T}m%q9=^*Ouv2xD4i+u`>A9lhE~Eu2ewX7_eu-wFmht0t>U zp}p%U!L8nvdQ?hXd*PDYWUiB^17E7NIN| zx;0Iw9=&>JbK|H;AQFfKB7sOC5{LvMfk+?{xF-ns>KMC@OzxXxvobj!J93_Uji*Q; z5{LvMfk+?{hy)^mNFWl31R{Y*AQHF>3Gke;4<2CbqX!W@{{P?m{r?C4|Njm85&9as z3EhC+hOR?TLEoQX%tDVrUrjMqK)ap)BE=R=JB3jG3o4E3RP=sdIlb)nDJsbYi{C0C@1#6gqwQ<<)J~cKdb3UTBMZ~T9|8w_l*@i8(gzuM_4Cj)fd`wz>(;zF8Ay=Rg-9eQ~nC`~DYZ|nmlPMOgjn?gYW!m4 zbH)O zH#h&zRnzh3>U(x4Vyq*WQpO@LUdw)eb?1TZn`Fs1gVgVOf#W4!4r` zlyFCx9<3Cn&H@)nSnV$3bb-#{G(R7l?iiU<$)%ocLXc&JVv+NC3Q4of5X7@a=h91~ zxdL0jQ^r(|hQ@9acO-Tzk$I7)dmXkHK%g1yR_bDN3neIAa1B4< zlB6S3jh!)e%Wz&bHEnA%L@~IZai}%+{}ySQGITk9j^uSNTuK|#4~Q#89>d6>zNU|B zK|?-jlM-Pn5c*OUTz@UjBWX|@`o;F*^@LX9X#D=Sk0d2d7;TzRy`GgcM@-@v$} zb1NiWQkWkuT~@cr4-L7x!bpdW$i7YJOa)t+F^Vxx@WUNPQQSy-zT0jr^%Q>{nNXiQ zPne6sm0V|HnwYCIB;#lRx56gI=Ak!hjTns{7o`wdSec=Aw$6NwKpLY5gLWh*FOXtb zBk%|`Loi~cD2*MV2{bQ6*je31lPT=ThC?UHo&v5=^~#`&;1+%72c_^bL!PDyDN%t@ zSaoCXj#!w197D=FtI@GK8;#9y3)ezPSB~x48X1Jb6ud;0`qq>v%y43}k0sqCGeN-0 zT6vjNu#(FHBeA?|1m5HVbinBlTA<&wa#%R)>sQ+Qw7A0BHihM7Xqz@66Mpyxw#O{M?< literal 0 HcmV?d00001 diff --git a/d.html.markdown b/d.html.markdown new file mode 100644 index 00000000..9f322423 --- /dev/null +++ b/d.html.markdown @@ -0,0 +1,61 @@ +--- +language: d +filename: learnd.d +contributors: + - ["Nick Papanastasiou", "www.nickpapanastasiou.github.io"] +lang: en +--- + +If you're like me and spend way to much time on the internet, odds are you've heard +about [D](http://dlang.org/). The D programming language is a modern, general-purpose, +multi-paradigm language with fantastic support for OOP, functional programming, metaprogramming, +and easy concurrency and parallelism, and runs the gamut from low-level features such as +memory management, inline assembly, and pointer arithmetic, to high-level constructs +such as higher-order functions and generic structures and functions via templates, all with +a pleasant syntax, and blazing fast performance! + +D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool +dudes. With all that out of the way, let's look at some examples! + +'''d +// You know what's coming... +import std.stdio; + +// args is optional +void main(string[] args) { + writeln("Hello, World!"); +} + +// Conditionals and loops work as expected. +import std.stdio; + +void main() { + for(int i = 0; i < 5; i++) { + writeln(i); + } + + auto n = 1; // use auto for type inferred variables + + while(n < 10_000) { + n += n; + } + + do { + n -= (n / 2); + } while(n > 0); + + // For and while are nice, but in D-land we prefer foreach + foreach(i; 1..int.max) { // The .. creates a continuous range + if(n % 2 == 0) + writeln(i); + } + + foreach_reverse(i; short.max) { + if(n % 2 == 1) + writeln(i); + else + writeln("No!"); + } +} + +''' From 0a9b7ebb07c00778ec5e03ffb76a706e8f805dda Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:30:44 -0400 Subject: [PATCH 04/20] Prompt addition of D --- .d.html.markdown.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp deleted file mode 100644 index f310c87d09d4381c3283e1642e5faa599ef78ed7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2y>A>v7{(`vf{!>vq(TDe^+m`wzTG=JiGu7nQour3K%9bLA;ogd$WZ4HT4=2!Rj0z3;4a zy6JUaS$m1jr)L?ClZ@T}m%q9=^*Ouv2xD4i+u`>A9lhE~Eu2ewX7_eu-wFmht0t>U zp}p%U!L8nvdQ?hXd*PDYWUiB^17E7NIN| zx;0Iw9=&>JbK|H;AQFfKB7sOC5{LvMfk+?{xF-ns>KMC@OzxXx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), 3 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index 9f322423..a6245a99 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -1,5 +1,5 @@ --- -language: d +language: D filename: learnd.d contributors: - ["Nick Papanastasiou", "www.nickpapanastasiou.github.io"] @@ -17,7 +17,7 @@ a pleasant syntax, and blazing fast performance! D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool dudes. With all that out of the way, let's look at some examples! -'''d +```d // You know what's coming... import std.stdio; @@ -58,4 +58,4 @@ void main() { } } -''' +``` From c5ac70f706802e9642c7ddc81caf88482a0eb2c6 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:50:05 -0400 Subject: [PATCH 06/20] D stuff --- d.html.markdown | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/d.html.markdown b/d.html.markdown index a6245a99..be9f8fb0 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -50,12 +50,47 @@ void main() { writeln(i); } - foreach_reverse(i; short.max) { + foreach_reverse(i; 1..short.max) { if(n % 2 == 1) writeln(i); else writeln("No!"); } } +``` + +We can define new types and functions with `struct`, `class`, `union`, and `enum`. Structs and unions +are passed to functions by value (i.e. copied) and classes are passed by reference. Futhermore, +we can use templates to parameterize all of these on both types and values! + +``` +// Here, T is a type parameter. Think from C++/C#/Java +struct(T) LinkedList { + T data = null; + LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think +} + +class BinTree(T) { + T data = null; + + BinTree!T left; + BinTree!T right; +} + +enum Day { + Sunday, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, +} + +// Use alias to create abbreviations for types + +alias IntList = LinkedList!int; + +alias NumTree = BinTree!double; ``` From f8da3b96ff93723f5e61aff24da7aa9e1c65f4a8 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Sun, 7 Jun 2015 22:52:34 -0400 Subject: [PATCH 07/20] fucking syntax highlighting --- d.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d.html.markdown b/d.html.markdown index be9f8fb0..f3836c2c 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -63,7 +63,7 @@ We can define new types and functions with `struct`, `class`, `union`, and `enum are passed to functions by value (i.e. copied) and classes are passed by reference. Futhermore, we can use templates to parameterize all of these on both types and values! -``` +```d // Here, T is a type parameter. Think from C++/C#/Java struct(T) LinkedList { T data = null; From 8f24f723e0b7cccde9dfcef2e2aa87d7eeb3822b Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 11:54:16 -0400 Subject: [PATCH 08/20] more D --- .d.html.markdown.swp | Bin 0 -> 12288 bytes d.html.markdown | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp new file mode 100644 index 0000000000000000000000000000000000000000..5cd11360548257ea0d2dbcb3ab4e21d6e315ba42 GIT binary patch literal 12288 zcmeI2O^h5z701hvknrIo;2g+_HUe#!OxbpOci*zzNA@F%Xh}&Cx*M2Wv6^|Sf!s>X3oB!KqSbA-h z_r0Opd#igt$sP7LU0kNh7QSzk%KyyFP8c8U-2!8U-2!8U-2!8U-2!8U-2!8U-2!8U-2!-hm3p zM2NrO$Nrn|#^CY)|M~C#zuzy!pTY0I&%rJ5S@0?FGI$L9>OLWI@DTXXQ6a|Qac~0s z`U66I8GH%c0vQ+r2`+<6U=4f(906~>Ux=^gbbe3w{G`gX`cEpaa^V1>ShC5Ptwa13v)Y1YZZY!7Jb^pbvg=uMnRBp9VL< zS+EQ~48DJl5Z?vg0p9>$0Jp#lBwz?6cp5wjPJ>m@1`mRJ!5i-p;&0%u;HTgx;M?Hy z;B(+v@C-NyPJlLOfn(r<-~sT*yM_2Mcn!P?z6HJpz6xFeS3n0m1nvQMgCjtI@7;y* zf*uHS{|=1ZX2}1u0%KJaDko_Z^3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!!-Ynq3bkp5McB%*;y0_i zh&jXci8n^+&_FKkDRT%am_-;C6Kq0s3_o2MQqQnPoP<@8_ayiU_{c8XxI_Tk7`rm= z23r_ol+hj=A8yD?EUmmN9Lp556so*&)4IX$sxrUJ^Y{3F$j7G4N`e zID)27k7X#c5ZRnZmoH!G?h7Fe@7~5(8#rvb1W)8*gQzxtH#WCAlcLDh`u&7$L@poq zmv}i+w7J;B!3e_gg>Y3l*1|9y()6-2&zwi;zc8YiD<4Gx3j0z796Rqbg}(?%mNMm8 zE;KHMtt{t01h)z^;u7qsxq5LQ*hNq9?t4P`{nhIU9^M)$8_GhDZnQ7qJ$bq!Gt4L! zZm(V0?oxX?oksiyeYSWZ8e=lcVWeGqOK=g*H7cXa{hAn|U|Q@p*N`lD(LRY_Z?5(l IGzhl;2{2wh*#H0l literal 0 HcmV?d00001 diff --git a/d.html.markdown b/d.html.markdown index f3836c2c..10a2be29 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -19,6 +19,8 @@ dudes. With all that out of the way, let's look at some examples! ```d // You know what's coming... +module hello; + import std.stdio; // args is optional @@ -65,7 +67,7 @@ we can use templates to parameterize all of these on both types and values! ```d // Here, T is a type parameter. Think from C++/C#/Java -struct(T) LinkedList { +struct LinkedList(T) { T data = null; LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think } @@ -90,7 +92,33 @@ enum Day { // Use alias to create abbreviations for types alias IntList = LinkedList!int; - alias NumTree = BinTree!double; +// We can create function templates as well! + +T max(T)(T a, T b) { + if(a < b) + return b; + + return a; +} + +// Use the ref keyword to pass by referece +void swap(T)(ref T a, ref T b) { + auto temp = a; + + a = b; + b = a; +} + +// With templates, we can also parameterize on values, not just types +class Matrix(T = int, uint m, uint n) { + T[m] rows; + T[n] columns; +} ``` + +Speaking of classes, let's talk about properties for a second. A property +is roughly a function that may act like an lvalue, so we can +have the syntax of POD structures (`structure.x = 7`) with the semantics of +getter and setter methods (`object.setX(7)`)! From 4b35798f832878f65308f1d8b1764580d8039bc4 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 11:54:25 -0400 Subject: [PATCH 09/20] more D --- .d.html.markdown.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp deleted file mode 100644 index 5cd11360548257ea0d2dbcb3ab4e21d6e315ba42..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O^h5z701hvknrIo;2g+_HUe#!OxbpOci*zzNA@F%Xh}&Cx*M2Wv6^|Sf!s>X3oB!KqSbA-h z_r0Opd#igt$sP7LU0kNh7QSzk%KyyFP8c8U-2!8U-2!8U-2!8U-2!8U-2!8U-2!8U-2!-hm3p zM2NrO$Nrn|#^CY)|M~C#zuzy!pTY0I&%rJ5S@0?FGI$L9>OLWI@DTXXQ6a|Qac~0s z`U66I8GH%c0vQ+r2`+<6U=4f(906~>Ux=^gbbe3w{G`gX`cEpaa^V1>ShC5Ptwa13v)Y1YZZY!7Jb^pbvg=uMnRBp9VL< zS+EQ~48DJl5Z?vg0p9>$0Jp#lBwz?6cp5wjPJ>m@1`mRJ!5i-p;&0%u;HTgx;M?Hy z;B(+v@C-NyPJlLOfn(r<-~sT*yM_2Mcn!P?z6HJpz6xFeS3n0m1nvQMgCjtI@7;y* zf*uHS{|=1ZX2}1u0%KJaDko_Z^3`Fgiit}+b++B`c@-BC+Mns1T-si0iHY1*R7@24 znJwfVxe;Btyh*;u%eW|W#ZT>@M0>PBC%2bqs*6eWluD&7bnNk<(4KNvjwfbDl18PC z3+*g!lLe&`ZE-XLUfRTN7ru4YQ^XglT+#726re3y(W9`#g6vqN&| z%7U`oWhyT;#x-(q5-!HhCJ~*PUz!QAy}d1N3c_b_!){UROqp80Ubm!M808eF!3tfJ zMXvWc19+xw(WMf9DXqWl61^z;eYzg}RcU4@EOl}c3ZgibPON5dK4ta25rx#e78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E;KHMtt{t01h)z^;u7qsxq5LQ*hNq9?t4P`{nhIU9^M)$8_GhDZnQ7qJ$bq!Gt4L! zZm(V0?oxX?oksiyeYSWZ8e=lcVWeGqOK=g*H7cXa{hAn|U|Q@p*N`lD(LRY_Z?5(l IGzhl;2{2wh*#H0l From e5fa463b3477813bb11d590beaf7ed8b49e9c733 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 12:18:45 -0400 Subject: [PATCH 10/20] So much D --- d.html.markdown | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index 10a2be29..f547cc56 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -53,10 +53,11 @@ void main() { } foreach_reverse(i; 1..short.max) { - if(n % 2 == 1) + if(n % 2 == 1) { writeln(i); - else + } else { writeln("No!"); + } } } ``` @@ -122,3 +123,73 @@ Speaking of classes, let's talk about properties for a second. A property is roughly a function that may act like an lvalue, so we can have the syntax of POD structures (`structure.x = 7`) with the semantics of getter and setter methods (`object.setX(7)`)! + +```d +// Consider a class parameterized on a types T, U + +class MyClass(T, U) { + T _data; + U _other; + +} + +// We define "setter" methods as follows + +class MyClass(T, U) { + T _data; + U _other; + + @property void data(T t) { + _data = t; + } + + @property void other(U u) { + _other = u; + } +} + +// And "getter" methods like so +class MyClass(T, U) { + T _data; + U _other; + + // Constructors are always named `this` + this(T t, U u) { + data = t; + other = u; + } + + // getters + @property T data() { + return _data; + } + + @property U other() { + return _other; + } + + // setters + @property void data(T t) { + _data = t; + } + + @property void other(U u) { + _other = u; + } +} +// And we use them in this manner + +void main() { + auto mc = MyClass!(int, string); + + mc.data = 7; + mc.other = "seven"; + + writeln(mc.data); + writeln(mc.other); +} +``` + +With properties, we can add any amount of validation to +our getter and setter methods, and keep the clean syntax of +accessing members directly! From cd207d1590897b9d410eb7e91992a6b11d36cd50 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 12:21:11 -0400 Subject: [PATCH 11/20] So much D --- d.html.markdown | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index f547cc56..d816a312 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -6,7 +6,7 @@ contributors: lang: en --- -If you're like me and spend way to much time on the internet, odds are you've heard +If you're like me and spend way too much time on the internet, odds are you've heard about [D](http://dlang.org/). The D programming language is a modern, general-purpose, multi-paradigm language with fantastic support for OOP, functional programming, metaprogramming, and easy concurrency and parallelism, and runs the gamut from low-level features such as @@ -113,10 +113,13 @@ void swap(T)(ref T a, ref T b) { } // With templates, we can also parameterize on values, not just types -class Matrix(T = int, uint m, uint n) { +class Matrix(uint m, uint n, T = int) { T[m] rows; T[n] columns; } + +auto mat = new Matrix!(3, 3); + ``` Speaking of classes, let's talk about properties for a second. A property From cc5729245ff988ebd92fddb6bcb2678be0d64cec Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 12:42:10 -0400 Subject: [PATCH 12/20] I looooove the D --- d.html.markdown | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index d816a312..0ffe3508 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -109,7 +109,7 @@ void swap(T)(ref T a, ref T b) { auto temp = a; a = b; - b = a; + b = temp; } // With templates, we can also parameterize on values, not just types @@ -118,7 +118,7 @@ class Matrix(uint m, uint n, T = int) { T[n] columns; } -auto mat = new Matrix!(3, 3); +auto mat = new Matrix!(3, 3); // We've defaulted T to int ``` @@ -196,3 +196,47 @@ void main() { With properties, we can add any amount of validation to our getter and setter methods, and keep the clean syntax of accessing members directly! + +Other object-oriented goodness for all your enterprise needs +include `interface`s, `abstract class`es, +and `override`ing methods. + +We've seen D's OOP facilities, but let's switch gears. D offers +functional programming with first-class functions, `pure` +functions, and immutable data. In addition, all of your favorite +functional algorithms (map, filter, reduce and friends) can be +found in the wonderful `std.algorithm` module! + +```d +import std.algorithm; + +void main() { + // We want to print the sum of a list of squares of even ints + // from 1 to 100. Easy! + + // Just pass lambda expressions as template parameters! + auto num = iota(1, 101).filter!(x => x % 2 == 0) + .map!(y => y ^^ 2) + .reduce!((a, b) => a + b); + + writeln(num); +} +``` + +Notice how we got to build a nice Haskellian pipeline to compute num? +That's thanks to a D innovation know as Uniform Function Call Syntax. +With UFCS, we can choose whether to write a function call as a method +or free function all. In general, if we have a function + +```d +f(A, B, C, ...) +``` + +Then we may write + +```d +A.f(B, C, ...) +``` + +and the two are equivalent! No more fiddling to remember if it's +str.length or length(str)! From 455875cd919d829874156ea97887e514e2b06493 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 14:07:14 -0400 Subject: [PATCH 13/20] improvements to D --- d.html.markdown | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index 0ffe3508..4b993a2d 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -47,12 +47,13 @@ void main() { } while(n > 0); // For and while are nice, but in D-land we prefer foreach - foreach(i; 1..int.max) { // The .. creates a continuous range + // The .. creates a continuous range, excluding the end + foreach(i; 1..1000000) { if(n % 2 == 0) writeln(i); } - foreach_reverse(i; 1..short.max) { + foreach_reverse(i; 1..int.max) { if(n % 2 == 1) { writeln(i); } else { @@ -62,7 +63,7 @@ void main() { } ``` -We can define new types and functions with `struct`, `class`, `union`, and `enum`. Structs and unions +We can define new types with `struct`, `class`, `union`, and `enum`. Structs and unions are passed to functions by value (i.e. copied) and classes are passed by reference. Futhermore, we can use templates to parameterize all of these on both types and values! @@ -75,7 +76,8 @@ struct LinkedList(T) { class BinTree(T) { T data = null; - + + // If there is only one template parameter, we can omit parens BinTree!T left; BinTree!T right; } @@ -104,7 +106,9 @@ T max(T)(T a, T b) { return a; } -// Use the ref keyword to pass by referece +// Use the ref keyword to ensure pass by referece. +// That is, even if a and b are value types, they +// will always be passed by reference to swap void swap(T)(ref T a, ref T b) { auto temp = a; @@ -136,22 +140,7 @@ class MyClass(T, U) { } -// We define "setter" methods as follows - -class MyClass(T, U) { - T _data; - U _other; - - @property void data(T t) { - _data = t; - } - - @property void other(U u) { - _other = u; - } -} - -// And "getter" methods like so +// And "getter" and "setter" methods like so class MyClass(T, U) { T _data; U _other; @@ -197,7 +186,7 @@ With properties, we can add any amount of validation to our getter and setter methods, and keep the clean syntax of accessing members directly! -Other object-oriented goodness for all your enterprise needs +Other object-oriented goodies at our disposal include `interface`s, `abstract class`es, and `override`ing methods. @@ -208,12 +197,13 @@ functional algorithms (map, filter, reduce and friends) can be found in the wonderful `std.algorithm` module! ```d -import std.algorithm; +import std.algorithm : map, filter, reduce; +import std.range : iota; // builds an end-exclusive range void main() { // We want to print the sum of a list of squares of even ints // from 1 to 100. Easy! - + // Just pass lambda expressions as template parameters! auto num = iota(1, 101).filter!(x => x % 2 == 0) .map!(y => y ^^ 2) From f30876d3f659d2c28ebe97bd4416d4dd514e5d22 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 14:13:38 -0400 Subject: [PATCH 14/20] So much D in my life --- d.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/d.html.markdown b/d.html.markdown index 4b993a2d..36153500 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -205,6 +205,7 @@ void main() { // from 1 to 100. Easy! // Just pass lambda expressions as template parameters! + // You can pass any old function you like, but lambdas are convenient here. auto num = iota(1, 101).filter!(x => x % 2 == 0) .map!(y => y ^^ 2) .reduce!((a, b) => a + b); From 2db99047ef98ec636b78e29b72f46dc347b37d38 Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Wed, 10 Jun 2015 14:31:02 -0400 Subject: [PATCH 15/20] Update d.html.markdown --- d.html.markdown | 7 ------- 1 file changed, 7 deletions(-) diff --git a/d.html.markdown b/d.html.markdown index 36153500..3a5a6c9b 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -133,13 +133,6 @@ getter and setter methods (`object.setX(7)`)! ```d // Consider a class parameterized on a types T, U - -class MyClass(T, U) { - T _data; - U _other; - -} - // And "getter" and "setter" methods like so class MyClass(T, U) { T _data; From 8bb2c3db63b87582764dca2641c8d84b39ed017f Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Tue, 16 Jun 2015 17:10:57 -0400 Subject: [PATCH 16/20] UFCS corrections; shorter intro --- .d.html.markdown.swp | Bin 0 -> 20480 bytes d.html.markdown | 53 ++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 31 deletions(-) create mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp new file mode 100644 index 0000000000000000000000000000000000000000..017dbf4e104bd614d8bb7c284148247a01d5c679 GIT binary patch literal 20480 zcmeI4Ym8(^b$~B^fWhn7u^p6`QO!8^_ORV|W_B%YnAu&t-oe-g?;5s;1+CZH)qShG zujfA6_c1+<1tv<6Y`~H81A$`85b_WplmH$nvRSutv9Or?1-nIUe^GWB@ zS2<4P_crA8^L@H`>PIF`Titl;x$b?Z6u7t+_wvw0S-Kb)okUxHGztAE&rI6#;$FJw zxx*|B+)yVQUObMTtHAnNErD7BFH8b?)^Gj#1m z@&8j7I?jKPsyTnU%LC2%gB15zIk&WDem?>NUGgA`U_1?J&m*a7FmS@75^9Ov8c5AZ>_84kcs zxDZ|r=fR^dr!Mem_&sAbbFZFo4&?PPh`DJlAoafJfn5@Fn;n{3(12 zJ_+xDH^61^6bYMug@1vE;hXRc_&U5BPQYQ<2P^Oz_z_8*XW$e(34a0!TnSH*Ao?ME zAHDz&!pGn~_-(iw-V5)66JS4!i|SzHsriA)GLy_JEeC0N5SnZld#MWi4WrVS>N}3& zv#w6Y+0Z1b_Nc8+dOFjqPA|}Ds&1SdlJ7>lsn!?N?T*7M4#iRGdnQp@6*rA^qAA@Z z{@abG;)n~`WMon$PdS}V$3woh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YP(3GaJG}u#?%XEW$_f+%WG2x+t$=Ol zR1EUKk2g<*DD7dHvXDkuCh0+XgQZ5|dTY?j1u2Q{(IR=Q^c4`m2^eErD7BKT8Reoj<|v=E!_q2WvV(~aKX>htT*v Date: Tue, 16 Jun 2015 17:15:14 -0400 Subject: [PATCH 17/20] formatting --- .d.html.markdown.swp | Bin 20480 -> 0 bytes d.html.markdown | 10 +++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) delete mode 100644 .d.html.markdown.swp diff --git a/.d.html.markdown.swp b/.d.html.markdown.swp deleted file mode 100644 index 017dbf4e104bd614d8bb7c284148247a01d5c679..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI4Ym8(^b$~B^fWhn7u^p6`QO!8^_ORV|W_B%YnAu&t-oe-g?;5s;1+CZH)qShG zujfA6_c1+<1tv<6Y`~H81A$`85b_WplmH$nvRSutv9Or?1-nIUe^GWB@ zS2<4P_crA8^L@H`>PIF`Titl;x$b?Z6u7t+_wvw0S-Kb)okUxHGztAE&rI6#;$FJw zxx*|B+)yVQUObMTtHAnNErD7BFH8b?)^Gj#1m z@&8j7I?jKPsyTnU%LC2%gB15zIk&WDem?>NUGgA`U_1?J&m*a7FmS@75^9Ov8c5AZ>_84kcs zxDZ|r=fR^dr!Mem_&sAbbFZFo4&?PPh`DJlAoafJfn5@Fn;n{3(12 zJ_+xDH^61^6bYMug@1vE;hXRc_&U5BPQYQ<2P^Oz_z_8*XW$e(34a0!TnSH*Ao?ME zAHDz&!pGn~_-(iw-V5)66JS4!i|SzHsriA)GLy_JEeC0N5SnZld#MWi4WrVS>N}3& zv#w6Y+0Z1b_Nc8+dOFjqPA|}Ds&1SdlJ7>lsn!?N?T*7M4#iRGdnQp@6*rA^qAA@Z z{@abG;)n~`WMon$PdS}V$3woh7Pdx3g;Z6aMknsxYI>Q=`L{OqE_4>=oT1({ib|<; z5@mWz#eH?tku{ZON#4uygrXar?E`m9?N@s{3u^3V!{R9u>L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2^eErD7BKT8Reoj<|v=E!_q2WvV(~aKX>htT*v Date: Tue, 16 Jun 2015 17:16:24 -0400 Subject: [PATCH 18/20] formatting --- d.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d.html.markdown b/d.html.markdown index 39c6a4d3..4ccf65d3 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -26,7 +26,7 @@ expressive high-level abstractions. D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool dudes. With all that out of the way, let's look at some examples! - +```d import std.stdio; void main() { From 5f0d8c28cc8c8f33db45c82a79699a9c1ff6fbbc Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Tue, 16 Jun 2015 17:19:30 -0400 Subject: [PATCH 19/20] formatting --- d.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d.html.markdown b/d.html.markdown index 4ccf65d3..7356174d 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -219,7 +219,7 @@ void main() { Notice how we got to build a nice Haskellian pipeline to compute num? That's thanks to a D innovation know as Uniform Function Call Syntax. With UFCS, we can choose whether to write a function call as a method -or free function call! Walter wrote a nice article on this [http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394](here.) In short, you can call functions whose first parameter +or free function call! Walter wrote a nice article on this [here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) In short, you can call functions whose first parameter is of some type A on any expression of type A as a method. From a54c5b580b9a2900f2f6eb1b2b5f07d0c1dd2e9d Mon Sep 17 00:00:00 2001 From: NickPapanastasiou Date: Tue, 16 Jun 2015 17:46:58 -0400 Subject: [PATCH 20/20] parallel stuff --- d.html.markdown | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/d.html.markdown b/d.html.markdown index 7356174d..88c7e37f 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -219,7 +219,29 @@ void main() { Notice how we got to build a nice Haskellian pipeline to compute num? That's thanks to a D innovation know as Uniform Function Call Syntax. With UFCS, we can choose whether to write a function call as a method -or free function call! Walter wrote a nice article on this [here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) In short, you can call functions whose first parameter +or free function call! Walter wrote a nice article on this +[here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) +In short, you can call functions whose first parameter is of some type A on any expression of type A as a method. +I like parallelism. Anyone else like parallelism? Sure you do. Let's do some! +```d +import std.stdio; +import std.parallelism : parallel; +import std.math : sqrt; + +void main() { + // We want take the square root every number in our array, + // and take advantage of as many cores as we have available. + auto arr = new double[1_000_000]; + + // Use an index, and an array element by referece, + // and just call parallel on the array! + foreach(i, ref elem; parallel(arr)) { + ref = sqrt(i + 1.0); + } +} + + +```