From 6debb5461e8320076b1cce571dd3614e295f6881 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:16:09 +0900 Subject: [PATCH] Add examples for short-fn --- examples/short-fn.janet | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/short-fn.janet diff --git a/examples/short-fn.janet b/examples/short-fn.janet new file mode 100644 index 0000000..14421ab --- /dev/null +++ b/examples/short-fn.janet @@ -0,0 +1,19 @@ +# a function that doubles its arguments +((fn [n] (+ n n)) 10) # -> 20 +((short-fn (+ $ $)) 10) # -> 20 + +# pipe reader macro offers terser expression +(|(+ $ $) 10) # -> 20 + +# $0 is also the first (zero-th) argument +(|(+ $0 $0) 10) # -> 20 + +# handling multiple arguments: $0, $1, ... +(|(string $0 $1) "hi" "ho") # -> "hiho" + +# variadic function +(|(apply + $&) 1 2 3) # -> 6 + +# structs and some other things work too +(|{:a 1}) # -> {:a 1} +