Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(math/acos 0.3 )
1.2661036727795
(var x 5 )
(%= x 3 )
(pp x ) # 2 (forv i 0 10
(print "hello" ))
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => nil
(buffer/bit (buffer/new-filled 1 48 ) 4 )
# => true
(assert :dude :what? ) # => :dude
(assert :dude :dude ) # => :dude
(assert (= :dude :what? ) "Where's my car?" )
# => error: Where's my car?
# => in _thunk [repl] (tailcall) on line 84, column 1
(assert (= :dude :dude ) "Where's my car?" ) # => true
# repeat is about _side-effects_, since it returns nil.
# You'll need to use a mutable collection if you want to
# use repeat to add repeated items to a collection:
(var coll @["Y" "Z" ]) #=> @["Y" "Z"]
(repeat 3 (array/push coll "A" )) #=> nil
coll
# Returns:
@["Y" "Z" "A" "A" "A" ]
# You can use map if the whole collection consists
# of these repetitions:
(map (fn [_ ] "A" ) (range 3 ))
# Returns:
@["A" "A" "A" ](def a @[11 12 ]) # => @[11 12]
(array/insert a 0 10 ) # => @[10 11 12]
(array/insert a 3 13 ) # => @[10 11 12 13]
(array/insert a -1 14 ) # => @[10 11 12 13 14]
(array/insert a -1 15 16 17 ) # => @[10 11 12 13 14 15 16 17]
# Contrived examples returning the variadic arguments passed in.
(defn example-function [& args ] args )
(defmacro example-macro [& args ] ~(tuple ,;args ))
(macex '(example-macro 1 2 3 ))
(assert (= (example-function 1 2 3 )
(example-macro 1 2 3 )))
(def args [1 2 3 ])
# `apply` is for functions, but there's always `eval`.
(assert (= (apply example-function args )
(eval ~(example-macro ,;args ))))
# Same return for both.
# => (1 2 3)
(def f (file/temp ))
(file/write f "ok stuff" )
(file/seek f :set 0 )
(file/read f :all )
# N.b. file/temp's file is not accessible outside of the process (protect
(if (> (math/random ) 0.42 )
(error "Good luck" )
"Bad luck" ))
# => randomly returns:
# (false "Good luck")
# or
# (true "Bad luck") (print (doc-format "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." 30 ))
Lorem ipsum dolor
sit amet , consectetur
adipiscing elit , sed
do eiusmod tempor
incididunt ut labore
et dolore magna
aliqua. Ut enim ad
minim veniam , quis
nostrud exercitation
ullamco laboris nisi
ut aliquip ex ea
commodo consequat.
(let [x 10 ]
(unless (= x 10 )
(print "x is not 10!" )
)
)
# => nil
(let [x 5 ]
(unless (= x 10 )
(print "x is not 10!" )
)
)
# => "x is not 10!" (map false? [ false nil true 0 1 42 'a :a "a" [97 ] {:a 42 } (fn []) ])
# => @[ true false false false false false false false false false false false ]
(math/log (* math/e math/e )) # => 2
(math/log2 256 ) # => 8
(math/log10 1000 ) # => 3
(- 1 )
# => -1