Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(try
(error :fun )
([e ]
(= e :fun )))
# => true
(def h ["a" "b" :c ]) # => ("a" "b" :c)
(find (fn [a ] (= "a" a )) h ) # => "a" (/ )
# => 1
(one? (math/next 1 math/inf )) # => false (update @[3 4 5 ] 1 dec ) # => @[3 3 5]
(update (update @[3 4 5 ] 1 dec ) 2 inc ) # => @[3 3 6]
# read input at compile-time and create a custom func to check whether a number is in one of the
# given ranges. This turned out to be almost 4x faster than writing it as a func
# from https://abhinavsarkar.net/notes/2025-aoc-1/#day-2
(defmacro in-range? [n & _ ]
(def ranges (parse-input (slurp input-path )))
~(or ,;(map (fn [[s e ]] ~(<= ,s ,n ,e )) ranges )))(last "hello" )
# => 111
(reduce (fn [s1 s2 ]
(string "[" s1 "+" s2 "]" ))
"x"
["a" "b" "c" ])
#=> "[[[x+a]+b]+c]"
(partition 2 [:a 1 :b 2 :c 3 ])
# => @[(:a 1) (:b 2) (:c 3)]
(when-let [root (math/sqrt 64 )
unused (even? root )]
(printf "%d is even" root ))
# -> "8 is even" # more at https://github.com/sogaiu/margaret/tree/master/examples
(peg/match ~{:main (replace (some :header-line )
,(fn [& captures ]
(table ;captures )))
:header-line (sequence (capture :header-name ) ":"
:s+
(capture :header-value ) :crlf )
:header-name (to ":" )
:header-value (to :crlf )
:crlf "\r\n" }
(string "Content-Type: text/plain\r\n"
"Content-Length: 1024\r\n" ))
# => @[@{"Content-Length" "1024" "Content-Type" "text/plain"}]
(map type [nil true 42 [] @[] {} @{} "a" @"b" 'c :d identity (fn [])])
# => @[:nil :boolean :number :tuple :array :struct :table :string :buffer :symbol :keyword :function :function]
(def f (ev/go (coro "world" ))) # coro is great for fast fiber creating
(ev/sleep 0.0001 ) # give ev a chance in the REPL, remove in file
(fiber/last-value f ) # "world"
(keyword : )
# => : # Some tips for working with bytes and unicode:
(string/bytes "что-нибудь" ) #> (209 135 209 130 208 190 45 208 189 208 184 ...
(print (string/from-bytes 208 176 208 177 )) #> аб
(map string/from-bytes (string/bytes "что-нибудь" )) #> @["\xD1" "\x87" "\xD1" "\x82" "\xD0" "\xBE" ...
# Print renders "\xD1" "\x87" as ч, as unicode characters may have multiple bytes
# So use apply:
(apply print (map string/from-bytes
(string/bytes "что-нибудь" ))) #> что-нибудь