Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(freeze @"Ho" ) #=> "Ho"
(freeze ["Ho" ]) #=> ("Ho")
(freeze @["Ho" ]) #=> ("Ho")
(freeze @{"Ho" "Ho" }) #=> {"Ho" "Ho"}
(var a false )
(defer (set a 42 )
(set a true )
(error "Oh no!" ))
# error: Oh no!
(pp a ) # => prints 42 (defn output [x ]
(case x
:a "a"
"b" ))
(output :a ) # => "a"
(output "anything else" ) # => "b" (let [x 10 ]
(unless (= x 10 )
(print "x is not 10!" )
)
)
# => nil
(let [x 5 ]
(unless (= x 10 )
(print "x is not 10!" )
)
)
# => "x is not 10!" (eachk k [1 2 3 ] (print k ))
# prints 0
# prints 1
# prints 2
# for indexed collections indices are printed (scan-number "123" ) # => 123
(scan-number "f" ) # => nil
(scan-number 123 ) # =>
# error: bad slot #0, expected string|symbol|keyword|buffer, got 123
# in scan-number
# in _thunk [repl] (tailcall) on line 1, column 1 (try
(int/u64 "18446744073709551616" )
([e ] e ))
# => "bad u64 initializer: string" # Convert an array of k/v pairs into a table
(def kvp @[[:foo 1 ] [:bar 2 ]])
(table ;(mapcat identity kvp )) # => @{:foo 1 :bar 2} (-> 1 (< 2 )) # -> true
(->> 1 (< 2 )) # -> false (->> "X"
(string "a" "b" )
(string "c" "d" )
(string "e" "f" )) # => "efcdabX" # 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 )(defn to-double-digit-string [digit ]
(string/slice (string "0" digit ) -3 ))
(defn get-date-time-string [time ]
(let [date (os/date time )
year (get date :year )
month (to-double-digit-string (get date :month ))
day (to-double-digit-string (get date :month-day ))
hours (to-double-digit-string (get date :hours ))
minutes (to-double-digit-string (get date :minutes ))
seconds (to-double-digit-string (get date :seconds ))]
(string year "-" month "-" day "__" hours ":" minutes ":" seconds )))
(defn get-current-date-time-string []
(get-date-time-string (os/time )))
### USAGE
(get-current-date-time-string )
# => "2020-09-23__17:20:00" # janet 1.10.1
(= :a :a ) # => true
(= :a "a" ) # => false
(= :a ":a" ) # => false
(= "a" "a" ) # => true
(= "a" @"a" ) # => false
(= @"a" @"a" ) # => false
(= [1 2 ] [1 2 ]) # => true
(= [1 2 ] @[1 2 ]) # => false
(= @[1 2 ] @[1 2 ]) # => false
(= {:a 1 } {:a 1 }) # => true
(= {:a 1 } @{:a 1 }) # => false
(= @{:a 1 } @{:a 1 }) # => false
(= (fn []) (fn [])) # => false
(let [a 1 b 2 c 3 ] (+ a b c )) # => 6
(let
[a 1
b (+ a 1 )
c (+ b 1 )]
(+ a b c )) # => 6
(math/log (* math/e math/e )) # => 2
(math/log2 256 ) # => 8
(math/log10 1000 ) # => 3