Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(peg/find-all ~(capture :d )
"hi 0 bye 1" )
# => @[3 9] (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"]
(table ;(kvs (struct :a 1 :b 2 )))
# => @{:a 1 :b 2} (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 ]
# foo.txt is a file with contents "hello\nworld\n".
(slurp "foo.txt" ) # => @"hello\nworld\n"
(string/split "\n" (slurp "foo.txt" )) # => @["hello" "world" ""]
(defn slurp-lines [path ]
(string/split "\n" (slurp path )))
(slurp-lines "foo.txt" ) # => @["hello" "world" ""]
(string/join @["hello" "world" "" ] "\n" ) # => "hello\nworld\n"
(spit "foo2.txt" (string/join @["hello" "world" "" ] "\n" ))
# The contents of foo.txt and foo2.txt are now identical.
(defn spit-lines [path lines ]
(spit path (string/join lines "\n" )))
(spit-lines "foo3.txt" (slurp-lines "foo.txt" ))
# The contents of foo.txt and foo3.txt are now identical.
# Flatten single level of nested collections
(def foo [ [[1 2 ] [3 4 ]]
[[5 6 ] [7 8 ]] ])
(apply array/concat @[] foo ) # => @[(1 2) (3 4) (5 6) (7 8)] (def add17 (partial + 17 ))
(add17 3 ) # -> 20
(add17 3 4 ) # -> 24
(map add17 [1 2 3 ]) # -> @[18 19 20]
(math/ceil 1.1 ) # => 2
(map math/ceil [1.1 1.2 1.3 ]) # => @[2 2 2] (defn ls-sockets
"List the sockets in the current directory."
[]
(filter
(fn [fname ] (= :socket (os/stat fname :mode )))
(os/dir "." )))
(string "hello " "world" ) # => "hello world"
(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 (def a @[])
(array/insert a 1 :a ) # error: index out of range
(array/insert a -2 :a ) # error: index out of range
(table/to-struct @{:a 1 }) # => {:a 1} (def b @"" )
(xprint b "HOHOHO" )
# => nil
b
# => @"HOHOHO\n" (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