Skip to content

Commit 77b7468

Browse files
authored
Merge pull request #257 from sogaiu/add-short-fn-examples
Add examples for short-fn
2 parents ac7512d + 6debb54 commit 77b7468

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/short-fn.janet

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# a function that doubles its arguments
2+
((fn [n] (+ n n)) 10) # -> 20
3+
((short-fn (+ $ $)) 10) # -> 20
4+
5+
# pipe reader macro offers terser expression
6+
(|(+ $ $) 10) # -> 20
7+
8+
# $0 is also the first (zero-th) argument
9+
(|(+ $0 $0) 10) # -> 20
10+
11+
# handling multiple arguments: $0, $1, ...
12+
(|(string $0 $1) "hi" "ho") # -> "hiho"
13+
14+
# variadic function
15+
(|(apply + $&) 1 2 3) # -> 6
16+
17+
# structs and some other things work too
18+
(|{:a 1}) # -> {:a 1}
19+

0 commit comments

Comments
 (0)