Elance Clojure Test Answers 2015



What is Clojure a dialect of?
Scheme
Lisp
Cobra
C/C++


True or False? Clojure is NOT an imperative language.
True
False


Vars _____
manage independent, synchronous changes to a single location
provide thread-local variable bindings
manage independent, asynchronous changes to a single location
provide thread-isolated transactions


(= (map + '(1 2 3)) 3)
True
(1 2 3)
False
6
5


________ evaluates all of the expressions provided to it in order and yields the last expression's value as its value.
fn
do
def
let


To calculate the average of some numbers in Clojure, your code would look like this:
def average (numbers): return sum( numbers) / len( numbers)
public static double average (double[] numbers) { double sum = 0; for (int i = 0; i < numbers.length; i + +) { sum + = numbers[ i]; } return sum / numbers.length; }
(defn average [numbers] (/ (apply + numbers) (count numbers)))
def average (numbers) numbers.inject(: +) / numbers.length end


Which is an example of a Clojure function call?
function-name (arg1, arg2, arg3)
(method-name arg1 arg2 arg3)
(function-name arg1 arg2 arg3)
methodName(arg1, arg2, arg3)


True or False? Arity is the number of arguments a function can handle.
True
False


True or False? Clojure a functional language.
False
True


What type does the following code result in? {:a 1 "b" 2}
List
Vector
Map
Array


True or False? In Clojure a symbol can contain characters that most imperative languages don't allow in variable names. (Example: in Clojure you can have a symbol with the name +a-.)
True
False


True or False? The Clojure language is homoiconic.
True
False


The two comment types that are defined by the reader are:
basic comments and source comments
Single-line comments and Form-level comments
textual comments and multi-line comments
custom comments and code-snippets


Leiningen uses _____ to locate and manage project dependencies
Maven
GitHub
SourceForge
Ivy


What are sequences?
Specific collections
Concrete lists
Ordered codes
Logical views of collections


What is the syntax of the "if" function?
(if condition then-expr else-expr)
(condition-if-then-expr-else expr)
(condition to-expr else-expr)
(condition if then-expr else-expr)


What is the function that evaluates a single argument form?
var
defn
eval
test


Does Clojure have a metadata system that allows for annotation of symbols and collections?
True
False


True or False? Clojure programs only support some Java classes and interfaces.
False
True


Which of the following Clojure fragments calculates (4+2)*(5-3)?
4 2 + 5 3 - *
(+ 4 2 (* (- 5 3)))
4+2*(5-3)
(* (+ 4 2) (- 5 3))


A function can be stored in a var or passed as an argument to other functions.
False
True


Collections that classically support last-in, first-out (LIFO) semantics are called ____________.
vectors
indices
stacks
contains


Clojure strings are Java Strings and are represented in exactly the same way, delimited by double quotes.
FALSE
True


How do you create an anonymous function?
#{items}
#(single-expression)
#(double-expression)
prefix#


What is significant about function names that end with a "!"?
It serves as a warning that the function in question may produce an unstable result.
It warns users that the function is deprecated.
All functions that mutate some state must end with a "!", or else you will get a compiler error.
It is a convention that indicates the function mutates some state.


Which is a type of collection in Clojure?
Set
None of these
Vector
All of these


How do you add metadata to a symbol or collection?
{key-value-pairs}
^{key-value-pairs} object
(class-name. args)
#"pattern"


What does the REPL tool do?
Read-enter-print look
Read-eval-part loop
Repeat-eval-pair loop
Read-eval-print loop


True or False? Sets are collections of unique items. They are better than lists and vectors when duplicates aren't allowed.
False
True


In Clojure, you can create a new class using _____
gen-class
proxy
All of the above
deftype


Which statement about Clojure macros is true?
Macros are useful, but Clojure's implementation of them is very limited.
Macros are basically a glorified parameterizable search-replace mechanism. They are error prone, and should be avoided at all costs.
Macros provide an ad-hoc mechanism for improving the performance of critical code.
Macros allow programmers to specify program transformations that occur during compile time.


Which statement best describes protocols in Clojure?
A protocol defines how two programs communicate over a computer network.
A protocol defines an interface. But unlike Java interfaces, which must be specified when a class is created, protocols can be attached to a class at any time.
Clojure uses the term "protocol" to refer to what Java calls an "interface".
Clojure provides several macros that make it easy to implement various network protocols.


Which of the following code fragments evaluates to 5?
(get {:a 1 :b 3 :c 5} :c)
({:a 1 :b 3 :c 5} :c)
(:c {:a 1 :b 3 :c 5})
All of the above


What do keywords begin with?
:
-
#
;


What are the 3 phases Clojure code is processed in?
Read-time, compile-time, run-time
Read-time, gather-time, run-time
There are actually 4 phases.
Read-time, compile-time, load-time


The map function is used to _____
aggregate the elements in a collection using a given function and return the result as a single value
All of the above
apply a function to all elements in a collection and return a sequence of the results
create a new Map object containing the specified elements


If you are already using Java or another JVM language for RDBMS work, it’s likely that you’re using ______________, easily the most popular Java object/ relational mapping library.
SLIME
Entity
Korma
Hibernate


lib-noir, Ring, and Compojure are all examples of Clojure:
HTTP service modules
SOAP service modules
REST service modules
API service modules
JSON service modules


The reduce function is used to _____
All of the above
substract a given amount from an integer value
aggregate the elements in a collection using a given function and return the result as a single value
apply a function to all elements in a collection and return a sequence of the results


A built-in Clojure "operation" may be implemented as a...
Function
Special Form
All of these
Macro


Stack abstraction is supported in Clojure via what three operations?
conj, pop, peek
get, nth, find
find, conj, get
get, find, pop


REPL stands for _____
Read, Eval, Print, Loop
Read, Eval, Process, Loop
REPresentational Language
Rediscover Enlightened Programs and Languages


The following code will evaluate to true? (defn +++ [n] (+ (inc n) 1)) (= (+++ 1) 3)
Can't define a reserved symbol
+ is reserved and can't be re-defined
True
Syntax error
False


STM stands for _____
State Transfer Machine
Software Transactional Memory
Safe Transactions in Memory
Step, Translate, Motion


:foo is an example of a(n) _____
keyword
symbol
atom
variable name


Clojure is primarily an imperative language.
True
False


True or False? Metadata is data about data, and has no effect on the 'host' data.
False
True


True or False? A lazy-sequence can hold all the possible calculations of the Fibonacci sequence.
True
False


A(n) ________ is a named Emacs object that represents something editable, usually a file in your filesystem, but also the Clojure REPL or debugger, for example.
Window
paredit
inferior-lisp
Buffer


What type does the following code result in? [1 2 3 4]
List
Vector
Map
Array


Clojure provides several "persistent" data structures. Objects of these classes are _____
stored in a database
implemented in a way that makes them robust in case of memory errors
immutable
serializable


What is generally the first step in deploying your Clojure web application?
Installing and configuring Leiningen or setting up and configuring an app server.
Restarting the application
Copying the .war file your build process is producing to your server.
Reverting your application's .war file to a prior version.


How would you want to create a new Atom with an initial value <value>?
(make-atom <value)
(new-atom value)
(atom <value>)
(new 'Atom <value>)
(new Atom <value>)


We can use _____________ to create a table with a specific name and define columns.
with-query-results
with-connection
transaction
create-table


Clojure documentation can be accessed
through the clojure.org website
All of the above
via the doc function
on clojuredocs.org


What is the literal syntax for maps?
#{:a 1 :b 2}
{:a 1 :b 2}
[:a 1 :b 2]


A multimethod is created using a ________form, and implementations of a multimethod are provided by ___________ form.
defmulti, defmethod
defmethod, defmulti
fill, fill-dispatch
derive, make-heiracrchy


Clojure is hosted on the JVM (Java Virtual Machine) and can use any Java library.
FALSE
True


In many object-oriented languages, ________________ is a way to decouple a class from other objects upon which that class depends.
chain of responsibility
dependency injection
the template method
strategy pattern


What is the conventional first and last character used to name vars intended to be bound to new, thread-local values?
(
^
*
"


________ is a very low-level looping and recursion operation that is usually not necessary.
leap
reduce
map
recur


What's a difference between quote (') and syntax-quote (`) macro characters?
Quote (') fully qualifies symbols, while syntax-quote (`) doesn't
There is no difference between quote (') and syntax-quote (`)
Syntax-quote (`) fully qualifies symbols, while quote (') doesn't


True or False? Function definitions must appear before they're first used.
False
True


Which statement about -> and comp is true?
-> is not a valid identifier in clojure, but comp is
-> is a macro while comp is a higher order function
comp is a macro while -> is a higher order function
-> and comp are exactly the same, except the parameters are in the opposite order


In Clojure, tail-call optimization is _____
only done for simple recursion
done for every call which is in a tail position
impossible
not supported natively by the compiler, but could be simulated using thunks, trampolines, and macros.


Locks _____
provide thread-local variable bindings
provide thread-isolated transactions
are a low-level construct that should be avoided in most cases
manage independent, asynchronous changes to a single location


To represent a boxed decimal in Clojure, you would use ____________.
float
Float
java.lang.Double
Fixnum


Which statement regarding Clojure "forms" is true?
Every form is a function call, but not every function call is a form.
The terms "function call" and "form" are completely interchangeable.
A form is like a function call, except it invokes a macro instead.
Every function call is a form, but not every form is a function call.


What does the "contains?" function work on?
All of these
Sets
Maps
Vectors


True or False? (reset!) is used to set the value of an atom.
False
True


In Clojure >= 1.3, which of these follows the naming conventions for dynamic objects? (def ^:dynamic *d* (atom [])) (def ^:dynamic d (atom []))
d, but not *d*
*d*, but not d


For the following code to evaluate without error, what needs to be added? (def regex "<a>(.*)</a>") (re-seq regex "<a>Ryan Kelker</a>")
@ symbol when defining regex
# symbol before the string in regex
Nothing. The syntax is correct
# symbol before regex and after def
# symbol before regex in (re-seq)


You can use ___________ whenever you like if you need a unique symbol, but its primary role is in helping us write hygienic macros.
defmacro
hygienic
gensym
important-value


let is a _____
Reserved Keyword
Macro
Special Form
Function


Agents _____
provide thread-isolated transactions
manage independent, asynchronous changes to a single location
provide thread-local variable bindings
manage independent, synchronous changes to a single location


Suppose you want to implement a set of mutually-recursive functions. Which approach might you take?
Define the functions locally using def
Since Clojure only supports simple recursion, you need to convert to an iterative algorithm.
Define the functions using letfn
Define the functions using let


What provides synchronous changes to a single piece of shared data?
Atoms
Agents
Refs
Vars


(.split "Java String" " ") returns
A Java array of strings
A lazy-sequenced array of strings
Syntax error
Invalid operation for string


True or False? In functional oriented languages, you can't manipulate objects like in object oriented languages.
False
True


What provides synchronous changes to a single, thread-local value?
Agents
Refs
Atoms
Var


Atoms _____
manage independent, asynchronous changes to a single location
provide thread-isolated transactions
manage independent, synchronous changes to a single location
provide thread-local variable bindings


A "dynamic" var _____
has a value that is related to the call stack, and can be used to pass contextual information between functions that do not call each other directly
has a value that is shared across multiple threads
must be expected to change value at any time, even if there is no local code that changes it
is a variable that has mutable state


If you want to create class that extends another class, you must use _____
reify
deftype
defrecord
gen-class


A _______ is a construct that suspends some body of code, evaluating it upon demand, when it is "deref"erenced.
deliver
future
delay
promise


Refs _____
provide thread-isolated transactions
provide thread-local variable bindings
manage independent, synchronous changes to a single location
manage independent, asynchronous changes to a single location


The Clojure reader can be extended using _____
reader macros
tagged literals
XML
metadata


The application of advice or other aspect transformations is often called __________.
profiling
advising
weaving
wrapping


How many ways can you safely share mutable data using Clojure?
5
3
4
2


What's the value returned by... (let [[x y [z]] [2 4 [8 9]]] (list x y z))
[2 4 [8 9]]
(2 4 8)
(2 4 (8 9))


What is the Closure equivalent to ClassName.class in Java?
ClassName
ClassName.CLASS
Class.name
(ClassName.class)


(letfn [ (t [] (true? (some true? ["false"])))] (t))
False because the string "false" is not the value true
False because "false" is not a string
True because "false" is a string
True because "false" is not a string
False because "false" is a string


A Clojure sequence is a Java
Iterator
List
Iterable
Map

No comments:

Post a Comment