summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNickPapanastasiou <nickpap9411@gmail.com>2015-06-07 22:50:05 -0400
committerNickPapanastasiou <nickpap9411@gmail.com>2015-06-07 22:50:05 -0400
commitc5ac70f706802e9642c7ddc81caf88482a0eb2c6 (patch)
tree1607d9d15d286176030148968acf2bc305c1e622
parent8bdf48dc8c2d41f945db734ac1837b0e434e7a95 (diff)
D stuff
-rw-r--r--d.html.markdown37
1 files changed, 36 insertions, 1 deletions
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 <T> from C++/C#/Java
+struct(T) LinkedList {
+ T data = null;
+ LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think <T>
+}
+
+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;
```