Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
# opens a file named filename for writing, and writes Hello World!
(def f (file/open "filename" :w ))
(file/write f "Hello World!" )
(file/flush f )
(file/close f )(map bytes? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ true true true true false false false false ]
(map symbol? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ true false false false false false false false ]
(map keyword? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false true false false false false false false ]
(map string? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false true false false false false false ]
(map buffer? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false true false false false false ] # can execute query from a file like:
(db/query (slurp "db/sql/random.sql" ))
# In context:
(defn show [request ]
(when-let [[name ] (request :wildcard )
name (uri/unescape name ) # escaping is important for = and especially %
name (string/replace "_q" "?" name )
binding (first (db/query (slurp "db/sql/search.sql" ) [name ]))]
[:vstack {:spacing "m" }
(binding-header binding )
(examples/index (merge request {:binding binding }))]))
# From https://codeberg.org/veqq/janetdocs/src/commit/ac1dc9e3e82f17e8e9ac047297b00803b68034d0/routes/examples.janet#L217 (int/u64 "18446744073709551615" )
# => <core/u64 18446744073709551615> @[1 2 3] # -> @[1 2 3]
(array 1 2 3) # -> @[1 2 3]
(array (splice [1 2 3]) # -> @[1 2 3]
(array ;[1 2 3]) # -> @[1 2 3]
(pp (all-bindings ))
# => prints @[% %= * ... yield zero? zipcoll]
(def a "A" )
(pp (all-bindings (curenv ) true ))
# => prints @[_ a] - only local bindings are listed (string/ascii-upper "hello" ) # => "HELLO" (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 (do
(def coll @[])
(forv i 0 9
(array/push coll i )
(+= i 2 ))
coll )
# => @[0 3 6]
(table/to-struct @{:a 1 }) # => {:a 1} (drop 1 "smile" )
# => "mile"
(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 ]
(let [len 8
rand-string (string/join (map |(string/format "%02x" $ )
(os/cryptorand len )))]
(= (length rand-string ) (* 2 len )))
# => true
(array/new-filled 3 ) # => @[nil nil nil]
(array/new-filled 3 :a ) # => @[:a :a :a] (mean [1 10 100 ]) # => 37
(mean []) # => nan