Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(max 1 2 3 ) # => 3
(max (splice [1 2 3 ])) # => 3
(max ;[1 2 3 ]) # => 3
(apply max [1 2 3 ]) # => 3
(band 7 11 ) # => 3
# 0111 (7)
# and 1011 (11)
# --------
# 0011 (3)
(table/to-struct @{:a 1 }) # => {:a 1} (defn fizzbuzz [n ]
(cond
(and
(= 0 (% n 3 ))
(= 0 (% n 5 ))) "fizzbuzz"
(= 0 (% n 3 )) "fizz"
(= 0 (% n 5 )) "buzz"
:else n ))
(fizzbuzz 1 ) # 1
(fizzbuzz 3 ) # "fizz"
(fizzbuzz 5 ) # "buzz"
(fizzbuzz 15 ) # "fizzbuzz" (math/round 1.1 ) # => 1
(map math/round [1.49 1.50 1.51 ]) # => @[1 2 2]
(/ 1 2 3 )
# => 0.166667
(defn capitalize [str ]
(string (string/ascii-upper (string/slice str 0 1 )) (string/slice str 1 )))# demo of (@ <sym>) feature
(let [content "# => label" ]
(match [:comment @{} "# => label" ]
[:comment _ (@ content )]
:found
nil ))
# => :found (any? "" )
# => nil
(any? "Hello" )
# => 72
(any? @"Hello" )
# => 72
(any? @[])
# => nil
(any? [])
# => nil
(any? {})
# => nil
(any? @{})
# => nil
(any? @[1 2 3 4 ])
# => 1
(any? @{:a 2 :b 3 })
# => 2
(map true? [ true nil false 0 1 42 'a :a "a" [97 ] {:a 42 } (fn []) ])
# => @[ true false false false false false false false false false false false ]
# Linux pipes | send data through stdin
# To make linux programs accepting varied input forms:
(defn main [_ & args ]
# If no arguments, read from stdin
(let [data (if (empty? args ) (file/read stdin :all ) (string/join args " " ))]
(print (sum (flatten (parse-all data ))))))
# This accepts: 1 2 3 or "1" "2" "3" or "1 2 3" or "[1 2 3]" besides piping data in
# janet fib.janet 5 | janet sum.janet
# Allow file inputs also:
(defn main [_ & args ]
(let [data (cond (empty? args ) (file/read stdin :all )
(os/stat (first args )) (slurp (first args ))
(string/join args " " ))]
(print (sum (flatten (parse-all data ))))))(def cc (compile '(print "Janet" ))) # => <function _thunk> on success returns function
(cc ) # => prints Janet (loop [x :range [1 10 ]
:let [square (* x x )]
:until (> square 9 )
:before (print "before" )
:after (print "after" )
:repeat 2 ]
(print (string "square: " square )))
# before
# square: 1
# square: 1
# after
# before
# square: 4
# square: 4
# after
# before
# square: 9
# square: 9
# after
(try
(int/u64 "18446744073709551616" )
([e ] e ))
# => "bad u64 initializer: string" (/ )
# => 1