laid out what examples need to be written
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 30 Dec 2020 22:52:39 +0000 (16:52 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 30 Dec 2020 22:52:39 +0000 (16:52 -0600)
13 files changed:
docs/todo
examples/05_slices.onyx [new file with mode: 0644]
examples/06_dynamic_arrays.onyx [new file with mode: 0644]
examples/07_structs.onyx [new file with mode: 0644]
examples/08_enums.onyx [new file with mode: 0644]
examples/09_for_loops.onyx [new file with mode: 0644]
examples/10_switch_statements.onyx [new file with mode: 0644]
examples/11_map.onyx [new file with mode: 0644]
examples/12_varargs.onyx [new file with mode: 0644]
examples/13_use_keyword.onyx [new file with mode: 0644]
examples/14_overloaded_procs.onyx [new file with mode: 0644]
examples/15_polymorphic_procs.onyx [new file with mode: 0644]
examples/16_pipe_operator.onyx [new file with mode: 0644]

index 8bcd3ee2f7ce3f50cdd07c88375711e8a9a17cbc..3e90abe54865c8c1eaaaa416901ca5c13958ab98 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -168,7 +168,7 @@ Usability:
         - Maps
         - varargs
         - `use` keyword
-        - pipe operator
+         pipe operator
         - Overloaded procedures
         - Polymorphic procedures
         - WASM directives (#export, #foreign)
diff --git a/examples/05_slices.onyx b/examples/05_slices.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/06_dynamic_arrays.onyx b/examples/06_dynamic_arrays.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/07_structs.onyx b/examples/07_structs.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/08_enums.onyx b/examples/08_enums.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/09_for_loops.onyx b/examples/09_for_loops.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/10_switch_statements.onyx b/examples/10_switch_statements.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/11_map.onyx b/examples/11_map.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/12_varargs.onyx b/examples/12_varargs.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/13_use_keyword.onyx b/examples/13_use_keyword.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/14_overloaded_procs.onyx b/examples/14_overloaded_procs.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/15_polymorphic_procs.onyx b/examples/15_polymorphic_procs.onyx
new file mode 100644 (file)
index 0000000..b0bf3ca
--- /dev/null
@@ -0,0 +1,6 @@
+#include_file "core/std/wasi"
+
+use package core
+
+main :: proc (args: [] cstr) {
+}
diff --git a/examples/16_pipe_operator.onyx b/examples/16_pipe_operator.onyx
new file mode 100644 (file)
index 0000000..fd63483
--- /dev/null
@@ -0,0 +1,37 @@
+#include_file "core/std/wasi"
+
+use package core { println }
+
+main :: proc (args: [] cstr) {
+    // These functions will be used to demo the pipe operator.
+    Num    :: #type i32;
+    double :: proc (v: Num)         -> Num do return v * 2;
+    add    :: proc (a: Num, b: Num) -> Num do return a + b;
+    square :: proc (v: Num)         -> Num do return v * v;
+
+    // Something you may find yourself doing often is changing function
+    // calls together likes this:
+    println(square(add(double(4), 3)));
+
+    // I think we can agree that that line is hard to understand just
+    // by looking at it. This kind of pattern appears very often, at
+    // least in the way that I program, so I wanted to have a way to 
+    // make this kind of operation cleaner. My solution was the pipe
+    // operator (|>). The above code can be rewritten as so:
+    double(4) |> add(3) |> square() |> println();
+
+    // The pipe operator simply places the expression on its left into
+    // the FIRST argument slot of the function call on its right. The
+    // operator is left associative, so the implicit parentheses are
+    // exactly where you expect them to be. For example,
+    //      a |> f(b, c) |> g(d)
+    // is the same as,
+    //      (a |> f(b, c)) |> g(d)
+    // which becomes,
+    //      g(f(a, b, c), d)
+    //
+    // This may seem a little simple and useless, and that is okay.
+    // It is not an operator you probably will not have to use very
+    // often; But when you have code like the first println above,
+    // it can clean up the code and make it easier to read.
+}
\ No newline at end of file