Clojure MCQs

Clojure MCQs

Our team has conducted extensive research to compile a set of Clojure MCQs. We encourage you to test your Clojure knowledge by answering these 80+ multiple-choice questions provided below.
Simply scroll down to begin!

1: For the following code to evaluate without error, what needs to be added? (def regex "<a>(.*)</a>") (re-seq regex "<a>Ryan Kelker</a>")

A.   @ symbol when defining regex

B.   # symbol before the string in regex

C.   # symbol before regex in (re-seq)

D.   Nothing. The syntax is correct

E.   # symbol before regex and after def

2: Which statement regarding Clojure "forms" is true?

A.   Every function call is a form, but not every form is a function call.

B.   Every form is a function call, but not every function call is a form.

C.   The terms "function call" and "form" are completely interchangeable.

D.   A form is like a function call, except it invokes a macro instead.

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

A.   True

B.   False

4: Vars _____

A.   provide thread-isolated transactions

B.   provide thread-local variable bindings

C.   manage independent, asynchronous changes to a single location

D.   manage independent, synchronous changes to a single location

5: Locks _____

A.   provide thread-local variable bindings

B.   are a low-level construct that should be avoided in most cases

C.   manage independent, asynchronous changes to a single location

D.   provide thread-isolated transactions

6: To represent a boxed decimal in Clojure, you would use ____________.

A.   java.lang.Double

B.   float

C.   Fixnum

D.   Float

7: In Clojure, tail-call optimization is _____

A.   done for every call which is in a tail position

B.   only done for simple recursion

C.   impossible

D.   not supported natively by the compiler, but could be simulated using thunks, trampolines, and macros.

8: What's a difference between quote (') and syntax-quote (`) macro characters?

A.   There is no difference between quote (') and syntax-quote (`)

B.   Syntax-quote (`) fully qualifies symbols, while quote (') doesn't

C.   Quote (') fully qualifies symbols, while syntax-quote (`) doesn't

9: Which statement about -> and comp is true?

A.   -> is a macro while comp is a higher order function

B.   -> and comp are exactly the same, except the parameters are in the opposite order

C.   -> is not a valid identifier in clojure, but comp is

D.   comp is a macro while -> is a higher order function

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

A.   True

B.   False

11: (= (map + '(1 2 3)) 3)

A.   False

B.   True

C.   (1 2 3)

D.   6

E.   5

12: You can use ___________ whenever you like if you need a unique symbol, but its primary role is in helping us write hygienic macros.

A.   important-value

B.   defmacro

C.   hygienic

D.   gensym

13: ________ is a very low-level looping and recursion operation that is usually not necessary.

A.   reduce

B.   map

C.   recur

D.   leap

14: What is the conventional first and last character used to name vars intended to be bound to new, thread-local values?

A.   *

B.   ^

C.   "

D.   (

15: In many object-oriented languages, ________________ is a way to decouple a class from other objects upon which that class depends.

A.   dependency injection

B.   strategy pattern

C.   chain of responsibility

D.   the template method

16: What is the literal syntax for maps?

A.   {:a 1 :b 2}

B.   #{:a 1 :b 2}

C.   [:a 1 :b 2]

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

A.   True

B.   False

18: A multimethod is created using a ________form, and implementations of a multimethod are provided by ___________ form.

A.   defmulti, defmethod

B.   derive, make-heiracrchy

C.   fill, fill-dispatch

D.   defmethod, defmulti

19: 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.

A.   Window

B.   Buffer

C.   inferior-lisp

D.   paredit

20: ________ evaluates all of the expressions provided to it in order and yields the last expression's value as its value.

A.   def

B.   let

C.   do

D.   fn

21: What is generally the first step in deploying your Clojure web application?

A.   Installing and configuring Leiningen or setting up and configuring an app server.

B.   Copying the .war file your build process is producing to your server.

C.   Restarting the application

D.   Reverting your application's .war file to a prior version.

22: Clojure is primarily an imperative language.

A.   True

B.   False

23: How would you want to create a new Atom with an initial value <value>?

A.   (new Atom <value>)

B.   (new-atom value)

C.   (new 'Atom <value>)

D.   (atom <value>)

E.   (make-atom <value)

24: The following code will evaluate to true? (defn +++ [n] (+ (inc n) 1)) (= (+++ 1) 3)

A.   True

B.   Can't define a reserved symbol

C.   + is reserved and can't be re-defined

D.   False

E.   Syntax error

25: Clojure provides several "persistent" data structures. Objects of these classes are _____

A.   implemented in a way that makes them robust in case of memory errors

B.   immutable

C.   stored in a database

D.   serializable

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

A.   False

B.   True

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

A.   False

B.   True

28: STM stands for _____

A.   Software Transactional Memory

B.   Step, Translate, Motion

C.   State Transfer Machine

D.   Safe Transactions in Memory

29: The reduce function is used to _____

A.   apply a function to all elements in a collection and return a sequence of the results

B.   All of the above

C.   aggregate the elements in a collection using a given function and return the result as a single value

D.   substract a given amount from an integer value

30: What are the 3 phases Clojure code is processed in?

A.   Read-time, gather-time, run-time

B.   Read-time, compile-time, load-time

C.   There are actually 4 phases.

D.   Read-time, compile-time, run-time

31: What type does the following code result in? [1 2 3 4]

A.   List

B.   Map

C.   Array

D.   Vector

A.   Hibernate

B.   Korma

C.   SLIME

D.   Entity

33: REPL stands for _____

A.   Rediscover Enlightened Programs and Languages

B.   Read, Eval, Process, Loop

C.   REPresentational Language

D.   Read, Eval, Print, Loop

34: :foo is an example of a(n) _____

A.   atom

B.   keyword

C.   variable name

D.   symbol

35: A built-in Clojure "operation" may be implemented as a...

A.   Macro

B.   All of these

C.   Special Form

D.   Function

36: Stack abstraction is supported in Clojure via what three operations?

A.   conj, pop, peek

B.   get, find, pop

C.   find, conj, get

D.   get, nth, find

37: Which statement about Clojure macros is true?

A.   Macros are basically a glorified parameterizable search-replace mechanism. They are error prone, and should be avoided at all costs.

B.   Macros provide an ad-hoc mechanism for improving the performance of critical code.

C.   Macros allow programmers to specify program transformations that occur during compile time.

D.   Macros are useful, but Clojure's implementation of them is very limited.

38: The map function is used to _____

A.   apply a function to all elements in a collection and return a sequence of the results

B.   All of the above

C.   aggregate the elements in a collection using a given function and return the result as a single value

D.   create a new Map object containing the specified elements

39: What are sequences?

A.   Specific collections

B.   Concrete lists

C.   Logical views of collections

D.   Ordered codes

40: To calculate the average of some numbers in Clojure, your code would look like this:

A.   def average (numbers) numbers.inject(: +) / numbers.length end

B.   (defn average [numbers] (/ (apply + numbers) (count numbers)))

C.   def average (numbers): return sum( numbers) / len( numbers)

D.   public static double average (double[] numbers) { double sum = 0; for (int i = 0; i < numbers.length; i + +) { sum + = numbers[ i]; } return sum / numbers.length; }

41: lib-noir, Ring, and Compojure are all examples of Clojure:

A.   REST service modules

B.   SOAP service modules

C.   API service modules

D.   JSON service modules

E.   HTTP service modules

42: What do keywords begin with?

A.   :

B.   -

C.   ;

D.   #

43: How do you add metadata to a symbol or collection?

A.   (class-name. args)

B.   #"pattern"

C.   {key-value-pairs}

D.   ^{key-value-pairs} object

44: The two comment types that are defined by the reader are:

A.   basic comments and source comments

B.   Single-line comments and Form-level comments

C.   custom comments and code-snippets

D.   textual comments and multi-line comments

45: What is significant about function names that end with a "!"?

A.   All functions that mutate some state must end with a "!", or else you will get a compiler error.

B.   It warns users that the function is deprecated.

C.   It is a convention that indicates the function mutates some state.

D.   It serves as a warning that the function in question may produce an unstable result.

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

A.   False

B.   True

47: Collections that classically support last-in, first-out (LIFO) semantics are called ____________.

A.   vectors

B.   stacks

C.   indices

D.   contains

48: How do you create an anonymous function?

A.   #(single-expression)

B.   #(double-expression)

C.   #{items}

D.   prefix#

49: What type does the following code result in? {:a 1 "b" 2}

A.   List

B.   Vector

C.   Map

D.   Array

50: Which is an example of a Clojure function call?

A.   (method-name arg1 arg2 arg3)

B.   function-name (arg1, arg2, arg3)

C.   (function-name arg1 arg2 arg3)

D.   methodName(arg1, arg2, arg3)