Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(def b @"" )
(xprint b "HOHOHO" )
# => nil
b
# => @"HOHOHO\n" (repeat 12 (-> 12 os/cryptorand pp ))
# => @"\xA7li[ \xED\xD2\xF7O\xD6\x15="
# => @">\"-w+\x04\x1C\xC1KG\x9C\xE4"
# => @"\x06b\f\xBD\x12\x19\xB6\x1A\xCA\xB9[\x85"
# => @"\xBE`R\t\x13\x81\xED\x9D#\xD0\x11!"
# => @"\xE2\xC1\xD8\x7F\\\xA7\x84\xC0\v\x8B'\x98"
# => @"\xD6\x0Fz\x86\xE2\xB2\x1D}\xC6'{\xB5"
# => @"\x9D\x97\xA1\x07i\x9FW\x83h4n2"
# => @"d\x8E\xB8\xBA \xA6\x9C\f\xC6\xAD{g"
# => @"\r\xB5\xF84#\xB8c~V\xD7d>"
# => @"\xBB\x19\xB2\xDC\x8B\xD9\x7F\xDC\xBE\f\x88\xE3"
# => @"w\xB50\xF9\xFD\xEB\x1D\xFF:j]\xB8"
# => @"\x8F$\xEBKL~\xFD\t\xA8\xD1\x8C\xC5"
# => nil (or true ) # => true
(or true true ) # => true
(or true false ) # => true
(or false 1 2 ) # => 1
(or false 2 1 ) # => 2
(or false nil ) # => nil
(or nil false ) # => false
# note that `or` does not behave as you might expect
# when used with `apply` and `splice`:
(or 1 2 3 ) # => 1
(or (splice [1 2 3 ])) # => (1 2 3)
(apply or [1 2 3 ]) # => (if 1 1 (if 2 2 3))
(defn read-from-file [file-path ]
(let [f (file/open file-path :r )
content (file/read f :all )]
(file/close f )
content ))
### USAGE
(read-from-file "/path/to/file-read-example.janet" )
# => @"(defn read-from-file [file-path]\n (let [f (file/open file-path :r)\n content (file/read f :all)]\n (file/close f)\n content))\n" (map number? [nil true 42 :a "a" [] {} (fn []) ])
# => @[false false true false false false false false ]
(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 ]
(try
(error :fun )
([e ]
(= e :fun )))
# => true
(string/join @["alice" "bob" "eve" ] "\t" )
# => "alice\tbob\teve" (keyword "" )
# => : (defn ddup [ds ks val ]
(update-in ds ks
(fn [x ]
(if (= nil x )
@[val ]
(array/push x val )))))
(var a @{})
(ddup a [:a ] 1 )
(ddup a [:a ] 2 )
(ddup a [:a ] 3 )
# @{:a @[1 2 3]}
(band 7 11 ) # => 3
# 0111 (7)
# and 1011 (11)
# --------
# 0011 (3)
(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)] ]
(let [a 1 b 2 c 3 ] (+ a b c )) # => 6
(let
[a 1
b (+ a 1 )
c (+ b 1 )]
(+ a b c )) # => 6
(let [tbl @{:a 1 }]
(merge-into tbl {:b 2 })
tbl )
# => @{:a 1 :b 2}
# real-world example: https://git.sr.ht/~subsetpark/bagatto/tree/19aea03fe23fe5486890912df7dc4a936ce617a3/item/main.janet#L23
# excess elements of the longer list are discarded
(interleave [1 ]
[2 4 ]
[3 6 ])
# -> @[1 2 3]