(math/floor 1.1) # => 1
(map math/floor [1.1 1.2 1.3]) # => @[1 1 1]
math/floorcellularmitosisPlayground(int/u64 "18_446_744_073_709_551_615")
# => <core/u64 18446744073709551615>
int/u64sogaiuPlayground# based on: https://codeberg.org/veqq/janetdocs/src/commit/54a964d1a35920af2655c4932a9b51379e8b9380/seed.janet#L16
(def core-api (all-bindings))
(def alldocs @[])
(loop [b :in core-api]
(when (not= "allbindings" (string b))
(do
(def buf @"")
(with-dyns [:out buf]
(doc* b)
(array/push alldocs {:name (string b) :docstring (string buf)})))))
(pp alldocs)
with-dynsveqqqPlayground(os/shell "uptime > /tmp/uptime.txt") # => 0
(slurp "/tmp/uptime.txt")
# => @"22:33 up 5 days, 9:34, 15 users, load averages: 1.93 1.74 1.59\n"
(os/rm "/tmp/uptime.txt") # => nil
os/shellcellularmitosisPlayground# complex matching, when you need to use predicates
# to determine a match
(def test {:a {:b 1} :c 2})
(match test
({:a a} (dictionary? a)) (print "is a dictionary"))
# --> "is a dictionary"
(match test
({:a a} (boolean? a)) (print "is a dictionary"))
# --> nil
matchllmIIPlayground(sort @[5 4 1 3 2]) # -> @[1 2 3 4 5]
(sort @[5 4 1 3 2] >) # -> @[5 4 3 2 1]
sortfelixrPlayground(var x 1)
(+= x 2 3 4)
# x = 10
+=erichaneyPlayground(nat? 1) # => true
(nat? 3.14159) # => false
nat?cellularmitosisPlayground(def a @[1 2 3])
(def b (array/slice a))
#=> good way to clone array, a and b are different arrays
array/slicepepePlayground(import joy)
# Given a handler
(defn handle-func [request]
(joy/text/plain (string "Hi " ((request :params) :name))))
# joy/route will attach it to a route
(joy/route :get "/hi/:name" :handle-func)
# without needing to pass the route(s) to joy/app
(def app (joy/app {}))
(joy/server app 9002)
# visit at localhost:9002/hi/bob
joy/routeveqqqPlayground(def new-bytes 512)
(var new-buffer (buffer/new new-bytes))
# --> @""
buffer/newMorganPetersonPlayground(def a @[23 42])
(array/clear a)
(pp a)
# => prints @[]
array/clearpepePlayground(let [a 1]
(let [b a]
b)) # => 1
letjgartePlayground(string/bytes "foo") # => (102 111 111)
(string/from-bytes 102 111 111) # => "foo"
(string/from-bytes (splice (string/bytes "foo"))) # => "foo"
(map (fn [x] x) "foo") # => @[102 111 111]
(map string/from-bytes "foo") # => @["f" "o" "o"]
(defn string/explode [s] (map string/from-bytes s))
(string/explode "foo") # => @["f" "o" "o"]
string/from-bytescellularmitosisPlayground(var a nil)
(var b nil)
(varfn a
[x]
(if (zero? x)
0
(b x)))
(varfn b
[y]
(if (pos? y)
1
(a y)))
(a 1)
# =>
1
(b 0)
# =>
0
varfnsogaiuPlayground