Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(map |($ {:a 7 :b 8 } ) [ keys values kvs pairs ])
# => @[ @[:a :b] @[7 8] @[:a 7 :b 8] @[(:a 7) (:b 8)] ]
(map |($ [4 5 6 ] ) [ keys values kvs pairs ])
# => @[ @[0 1 2] @[4 5 6] @[0 4 1 5 2 6] @[(0 4) (1 5) (2 6)] ]
(map |($ 'ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ :ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ "ab" ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(eval-string "(+ 1 2 3 4)" ) # -> 10
(eval-string ")" ) # -> parse error
(eval-string "(bloop)" ) # -> compile error
(eval-string "(+ nil nil)" ) # -> runtime error (range 12 ) # => @[0 1 2 3 4 5 6 7 8 9 10 11]
(range 0 12 ) # => @[0 1 2 3 4 5 6 7 8 9 10 11]
(range 0 12 1 ) # => @[0 1 2 3 4 5 6 7 8 9 10 11]
(range 0 12 2 ) # => @[0 2 4 6 8 10]
(range 0 12 3 ) # => @[0 3 6 9]
(range 0 12 4 ) # => @[0 4 8]
(range 0 12 6 ) # => @[0 6]
(if-let [x true
y (not (not x ))]
:a
:b )
# => :a
# Suppose you have a fiber that yields chunks of paginated api results:
(def api-results (fiber/new (fn [] (yield [1 2 3 ]) (yield [4 5 6 ]))))
# Using :iterate, the right side of the binding is evaluated each time the loop is run,
# which allows for running a side-effecting expression that may be different each time.
(loop [_ :iterate (fiber/can-resume? api-results )] (pp (resume api-results )))
# This example can be simplified using :generate
(loop [chunk :generate api-results ] (pp chunk ))
(comment this is a
multiline line comment.
It won 't do anything )(partition 2 [:a 1 :b 2 :c 3 ])
# => @[(:a 1) (:b 2) (:c 3)]
(os/execute
["/usr/bin/bash" "-c" "set" ]
:e
@{"SOME" "value"
"OTHER" "one" })
# => 0
# execute bash and prints environment variables
# which contains SOME=value and Other=one # excess elements of the longer list are discarded
(interleave [1 ]
[2 4 ]
[3 6 ])
# -> @[1 2 3] (let [len 8
rand-string (string/join (map |(string/format "%02x" $ )
(os/cryptorand len )))]
(= (length rand-string ) (* 2 len )))
# => true
(print "You are using janet version " janet/version )(defn get-time-str []
(let [{:hours h :minutes m :seconds s } (os/date )]
(string h ":" m ":" s )))
(get-time-str ) => "23:18:16" (string/ascii-upper "hello" ) # => "HELLO" (describe {:a 1 }) # => "<struct 0x5564AF1BD6C0>" (scan-number "1_000_000" )
# => 1000000