Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
# janet 1.10.1
(= [1 1 ] [1 1 ]) # => true
(= [1 1 ] [2 3 ]) # => false
(= [1 1 ] @[1 1 ]) # => false
(= [1 1 ] @[2 3 ]) # => false
(= @[1 1 ] @[1 1 ]) # => false
(= @[1 1 ] @[2 3 ]) # => false
(deep= [1 1 ] [1 1 ]) # => true
(deep= [1 1 ] [2 3 ]) # => false
(deep= [1 1 ] @[1 1 ]) # => false
(deep= [1 1 ] @[2 3 ]) # => false
(deep= @[1 1 ] @[1 1 ]) # => true
(deep= @[1 1 ] @[2 3 ]) # => false
(/ 2 )
# => 0.5
(var a 0 )
(assert (pos? a ) "A is definitely not positive" )
# error: A is definitely not positive
# in assert [boot.janet] on line 149, column 11
# in _thunk [repl] (tailcall) on line 3, column 1 (get-in {:a {:cc 2 } :b {:dd 3 }} [:a ] 42 ) # => {:cc 2}
(get-in {:a {:cc 2 } :b {:dd 3 }} [:a :cc ] 42 ) # => 2
(get-in {:a {:cc 2 } :b {:dd 3 }} [0 ] 42 ) # => 42
(get-in {:a {:cc 2 } :b {:dd 3 }} [:z ] 42 ) # => 42
(defn square [x ] (* x x ))
(defn square-then-dec [x ] ((comp dec square ) x ))
(defn dec-then-square [x ] ((comp square dec ) x ))
(square-then-dec 3 ) # => 8
(dec-then-square 3 ) # => 4
# Due to: https://github.com/swlkr/janetdocs/issues/50
(defn parse-date
"Parses YYYY-MM-DD date format to time"
[date ]
(let [[year month day ] (map scan-number (string/split "-" date ))]
(os/mktime {:year year :month (dec month ) :month-day (dec day )})))
(print (parse-date "2021-01-01" )) # 1609459200
(print (os/strftime "%c" (parse-date "2021-01-01" ))) # Fri Jan 1 00:00:00 2021 (defn array-difference [array-1 array-2 ]
(filter |(not (has-value? array-2 $ )) array-1 ))
(array-difference [1 2 3 4 5 ] [2 3 4 ]) # => @[1 5] (map (fn [arg ] (* arg arg )) (range 10 ))
# => @[0 1 4 9 16 25 36 49 64 81] (<= 1 2 3 ) # => true
(<= 1 2 1 ) # => false (put @{:a 4 :b 5 } :c 6 ) # => @{:a 4 :b 5 :c 6}
(put @{:a 4 :b 5 } :b nil ) # => @{:a 4}
(put @{:a 4 :b 5 } :z nil ) # => @{:a 4 :b 5}
(put @[:a :b :c ] 0 :z ) # => @[:z :b :c]
(put @[:a :b :c ] 1 nil ) # => @[:a nil :c]
(put @[:a :b :c ] 5 :d ) # => @[:a :b :c nil nil :d]
(put @"hello" 0 "z" ) # error: can only put integers in buffers
(defn ord [ch ] (first (string/bytes ch )))
(ord "z" ) # => 122
(put @"hello" 0 122 ) # => @"zello"
(put @"hello" 0 (ord "z" ) ) # => @"zello"
(put @"hello" 8 (ord "y" ) ) # => @"hello\0\0\0y"
(eachk k [1 2 3 ] (print k ))
# prints 0
# prints 1
# prints 2
# for indexed collections indices are printed (reduce string "ha" ["ha" "ha" "ha" "ha" ]) # => "hahahahaha"
(accumulate string "ha" ["ha" "ha" "ha" "ha" ]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"] (interleave [:a :b :c ]
[1 2 3 ]
["x" "y" "z" ])
# => @[:a 1 "x" :b 2 "y" :c 3 "z"] (sandbox :fs ) # disable access to the sandbox
(os/mkdir "lol" )
# error: operation forbidden by sandbox
# in os/mkdir [src/core/os.c] on line 2146
# in thunk [repl] (tail call) on line 30, column 1 (os/shell "seq 12 | head -n 1" ) # => 1