Clojure Functions (L17) Flashcards
Where is the optional “doc string” placed when documenting a Clojure function?
Between the function name and the parameter sequence.
How are doc strings typically formatted?
As a multi line string, the first line being a summary and the remaining lines providing details.
What Clojure form displays the documentation of a specified function?
(doc myFunc)
What are Codox, Marginalia, and Cadastre?
These are third party tools that prepare indexed, web-based documentation from documented Clojure source code.
What is a function’s arity?
It is the number of parameters that function accepts.
Arity overloading occurs by defining separate versions of the same function that take a different of arguments.
False, arity overloading occurs within the same function definition.
Different arities of the same function can call one another.
True.
The following is a valid example of arity overloading.
(defn fname
[arg1] (expression1)
[arg1 arg2] (expression2))
False:
(defn fname
([arg1] (expression1))
([arg1 arg2] (expression2)))
Functions in Clojure may be passed as parameters without any special syntax.
True.
What does Clojure’s map function do?
It applies a specified function argument to each element of an associated sequence.
What does Clojure’s reduce function do?
Applies a specified function parameter to all elements of a sequence in order to produce a single value.
What does the following return?
(reduce + [1 2 3])
6
What does the following return?
(reduce + 1 [1 2 3])
7
What does Clojure’s filter function do?
Applies a specified function parameter to all elements of a sequence in order to extract elements that match the filter.
Must the function passed to Clojure’s filter return a Boolean?
No.
How can a function return another function?
By placing the definition of the function to return at the end of the outer function definition.