From: Brendan Hansen Date: Wed, 30 Dec 2020 22:52:39 +0000 (-0600) Subject: laid out what examples need to be written X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f126e3438837fdbe30f0d4a8e50588d93cfe3b94;p=onyx.git laid out what examples need to be written --- diff --git a/docs/todo b/docs/todo index 8bcd3ee2..3e90abe5 100644 --- 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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/05_slices.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/06_dynamic_arrays.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/07_structs.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/08_enums.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/09_for_loops.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/10_switch_statements.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/11_map.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/12_varargs.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/13_use_keyword.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/14_overloaded_procs.onyx @@ -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 index 00000000..b0bf3ca2 --- /dev/null +++ b/examples/15_polymorphic_procs.onyx @@ -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 index 00000000..fd634832 --- /dev/null +++ b/examples/16_pipe_operator.onyx @@ -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