Call a function: Difference between revisions

Adds Clojure solution
No edit summary
(Adds Clojure solution)
Line 243:
/* Scalar values are passed by value by default. However, arrays are passed by reference. */
/* Pointers *sort of* work like references, though. */</lang>
 
=={{header|Clojure}}==
<lang clojure>
;Calling a function that requires no arguments
(defn a [] "This is the 'A' function")
(a)
 
;Calling a function with a fixed number of arguments
(defn b [x y] (list x y))
(b 1 2)
 
;Calling a function with optional arguments (multi-arity functions)
(defn c ([] "no args")
([optional] (str "optional arg: " optional)))
(c)
(c 1)
 
 
;Calling a function with a variable number of arguments (variadic)
(defn d [& more] more)
(d 1 2 3 4 5 6 7 8)
 
;Calling a function with named arguments
(defn e [& {:keys [x y]}] (list x y))
(e :x 10 :y 20)
 
;Using a function in first-class context within an expression
(def hello (fn [] "Hello world"))
 
;Obtaining the return value of a function
(def return-of-hello (hello))
 
;Is partial application possible and how? Yes
(def add10 (partial + 10))
(add10 3) ;=> 13
(add10 1 2 3) ;=> 16
</lang>
 
=={{header|COBOL}}==
Anonymous user