Clojure Programming/Examples/API Examples/Function Tools
Tools
General
Sister projects
In other projects
(map(fn[a](str"hi "a))["mum""dad""sister"]); => ("hi mum" "hi dad" "hi sister")
See thereader page, (Macro characters -> Dispatch -> Anonymous function literal) for an explanation of the '%' and other characters used to refer to function arguments.
user=>(defsq#(*%%))#'user/squser=>(sq3)9user=>(map#(class%)[1"asd"])(java.lang.Integerjava.lang.String)user=>
Use fn, or even better there is a custom syntax to create an anonymous function:
(map#(str"hi "%)["mum""dad""sister"])
Represents an optional argument to an unnamed function:
#(+2%)#(+2%1%2)
Arguments in the body are determined by the presence of argument literals taking the form %, %n or %&. % is a synonym for %1, %n designates the nth arg (1-based), and %& designates a rest arg.
Usage: (complement f)
Takes a fn f and returns a fn that takes the same arguments as f,has the same effects, if any, and returns the opposite truth value.
user=>(defnsingle-digit[x](<x10))#'user/single-digituser=>(single-digit9)trueuser=>(single-digit10)falseuser=>(defmulti-digit(complementsingle-digit))#'user/multi-digituser=>(multi-digit9)falseuser=>(multi-digit10)true