Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(printf "%s %s!" "Hello" "World" ) # Hello World! (invert :yo )
# => @{111 1 121 0} # sorted allocates the full memory of its input
(def d2 (range 10000000 0 -1 )) # 87mb
(sorted d2 ) # now 167 mb (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
(map math/abs [-2.9 -2.1 2.1 2.9 ]) # => @[ 2.9 2.1 2.1 2.9 ]
(map math/floor [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -3 2 2 ]
(map math/ceil [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 3 3 ]
(map math/round [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -2 2 3 ]
(map math/trunc [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 2 2 ]
(cmp [1 2 ] [1 2 3 ])
# => -1
(last :hello )
# => 111
(let [a 1 b 2 c 3 ] (+ a b c )) # => 6
(let
[a 1
b (+ a 1 )
c (+ b 1 )]
(+ a b c )) # => 6
(os/time ) # => 1593837535 (buffer/format @"0 - 1 = " "%d" -1 )
# =>
@"0 - 1 = -1" # There is a list of formatters here: https://janet-lang.org/capi/writing-c-functions.html
(string/format "With terminal colors: %M" [:array {:key-in "struct" }]) # => "With terminal colors: (\e[33m:array\e[0m {\e[33m:key-in\e[0m \e[35m\"struct\"\e[0m})"
(var n 5 ) # n = 5
(-= n 1 ) # n -= 1
(print n ) # 4 (sort (keys default-peg-grammar ))
# => @[:A :D :H :S :W :a :a* :a+ :d :d* :d+ :h :h* :h+ :s :s* :s+ :w :w* :w+] # Demonstrate file/flush -- tail %flushtest.csv to see new
# entries appended as the program runs. Otherwise, entries
# wouldn't be visible until file was closed. @oofoe
(def fp (file/open "flushtest.csv" :wb ))
(file/write fp "Timestamp,Fiducial\n" )
(for i 0 5
(print "-- Writing " i )
(file/flush (file/write fp (string (os/time ) "," i "\n" )))
(os/sleep (* 5 (math/random ))))
(file/close fp )(spit "/tmp/hello.sh" "#!/bin/bash\necho 'Hello from Bash!'\n" )
(os/chmod "/tmp/hello.sh" "rwx------" )
(os/setenv "PATH" (string (os/getenv "PATH" ) ":/tmp" ))
(os/shell "hello.sh" )