Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
# many terminals will truncate long data, use this if you need to see/copypaste it:
(defn full-print `Print a large DS without truncation` [ds ] (print (string/format "%m" ds )))(math/exp 1 ) # => 2.71828
math/e # => 2.71828 (def p1 (os/spawn ["echo" "hello" ] :p {:out :pipe }))
(def p2 (os/spawn ["grep" "hello" ] :p {:in (p1 :out )}))
(:wait p2 )
# Creates a pipeline (e.g. echo hello | grep hello) janet:2:> (all true? [true true false ])
false
janet:3:> (all even? [2 4 6 7 ])
false
janet:5:> (all even? [2 4 6 ])
true # see https://janet-lang.org/docs/abstract_machine.html
(def plus10
(asm
'{
:arity 1
:bytecode @[(ldi 1 10 ) # $1 = 10
(add 2 0 1 ) # $2 = $0 + $1
(ret 2 )]})) # return $2
(plus10 1 ) # -> 11 (keyword? :a ) # => true
(keyword? "a" ) # => false (get (os/environ ) "HOME" ) # => "/Users/cell"
(os/getenv "HOME" ) # => "/Users/cell"
(each item [1 2 3 4 ] (print item ))
# prints 1
# prints 2
# prints 3
# prints 4
# => nil (partition-by even? [1 1 2 3 5 8 13 21 ])
# => @[@[1 1] @[2] @[3 5] @[8] @[13 21]]
(group-by odd? [1 2 3 5 6 ])
# =>
@{false @[2 6 ] true @[1 3 5 ]}(get default-peg-grammar :a )
# => '(range "az" "AZ") (math/rng-uniform (math/rng 0 ))
# => 0.487181
(bnot 255 ) # => -256
(map dictionary? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false true true ]
(map struct? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false true false ]
(map table? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false false false false false true ] (array/slice @[1 2 3 ] 0 0 ) # => @[]
(array/slice @[1 2 3 ] 0 1 ) # => @[1]
(array/slice @[1 2 3 ] 0 2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 3 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 4 ) # error: index out of range
(array/slice @[1 2 3 ] 1 1 ) # => @[]
(array/slice @[1 2 3 ] 1 2 ) # => @[2]
(array/slice @[1 2 3 ] 0 -1 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 -2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 -3 ) # => @[1]
(array/slice @[1 2 3 ] 0 -4 ) # => @[]
(array/slice @[1 2 3 ] 0 -5 ) # error: index out of range