Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding examples to Janet api documentation. #242

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/++.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(var a 0) # -> 0
(set a (+ a 1)) # -> 1
(++ a) # -> 2 (same effect as above)
3 changes: 3 additions & 0 deletions examples/--.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(var x 10) # -> 10
(set x (- x 1)) # -> 9
(-- x) # -> 8 (same effect as above)
2 changes: 1 addition & 1 deletion examples/-.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(-) # -> 0
(- 10) # -> -10
(- 1 2) # -> -1
(+ 1.4 -4.5) # -> 5.9
(- 1.4 -4.5) # -> -5.9

# Equivalent to (- first (+ ;rest))
(- 1 2 3 4 5 6 7 8 9 10) # -> -53
Expand Down
5 changes: 5 additions & 0 deletions examples/-_62.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(-> {:a [1 2 3] :b [4 5 6]}
(get :a)
(sum)
((fn [x y] (/ x y)) 2)) # The 6 from the sum is threaded first and binds to x, then 2 binds to y.
# -> 3
8 changes: 8 additions & 0 deletions examples/accumulate.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(reduce + 0 [1 2 3 4]) #-> 10
(accumulate + 0 [1 2 3 4]) # -> @[1 3 6 10]

(reduce + 0 []) # -> 0
(accumulate + 0 []) # -> @[]

(reduce string "" ["J" "a" "n" "e" "t"]) # -> "Janet"
(accumulate string "" ["J" "a" "n" "e" "t"]) # -> @["J" "Ja" "Jan" "Jane" "Janet"]
8 changes: 8 additions & 0 deletions examples/accumulate2.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(reduce2 + [1 2 3 4]) #-> 10
(accumulate2 + [1 2 3 4]) # -> @[1 3 6 10]

(reduce2 + []) # -> 0
(accumulate2 + []) # -> @[]

(reduce2 max [1 4 2 3 9 5]) # -> 9
(accumulate2 max [1 4 2 3 9 5]) # -> @[1 4 4 4 9 9]
8 changes: 8 additions & 0 deletions examples/all.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(all pos? [1 2 3]) #-> true
(all pos? [1 2 -3]) #-> false

(all pos? []) # -> true
(all neg? []) # -> true

(all truthy? [1 2 3]) # -> true
(all truthy? [1 2 nil]) # -> false