COMP348 Clojure Programming Exercises and Solutions, Exams of Nursing

A series of exercises and solutions related to clojure programming, focusing on recursion, namespaces, and library definitions. It covers key concepts like recursion, tail-call optimization, namespace definition, and importing java classes into clojure code. Valuable for students learning clojure programming, offering practical examples and explanations.

Typology: Exams

2023/2024

Available from 01/16/2025

Toperthetop
Toperthetop 🇬🇧

3

(6)

28K documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
L18 COMP348 Clojure Programs
questions with verified solutions
No - correct answer ✔✔For/while loop version in Clojure
Recursion - correct answer ✔✔What do we use to perform iterative processing (replacement for/while
loop)
1. A function calls itself repeatedly
2. The recursive invocations terminate when a programmer-specified condition is met
3. The recursion then unwinds back to the first invocation of the function - correct answer ✔✔3 basic
features of recursion
The program will crash with an ''out of stack space error'' - correct answer ✔✔What will happen if the
terminating condition does not occur
Another stack frame - correct answer ✔✔Each recursive invocation creates what until the terminating
condition is met
None - correct answer ✔✔Which data is shared inside the function invocations
Must occur between the function invocations, in other words:
sharing is done via the arguments and return values. - correct answer ✔✔How do you do sharing for
recursion
(defn flip
[numbers]
(if (empty? numbers)
[]
pf3
pf4

Partial preview of the text

Download COMP348 Clojure Programming Exercises and Solutions and more Exams Nursing in PDF only on Docsity!

L18 COMP348 Clojure Programs

questions with verified solutions

No - correct answer ✔✔For/while loop version in Clojure Recursion - correct answer ✔✔What do we use to perform iterative processing (replacement for/while loop)

  1. A function calls itself repeatedly
  2. The recursive invocations terminate when a programmer-specified condition is met
  3. The recursion then unwinds back to the first invocation of the function - correct answer ✔✔3 basic features of recursion The program will crash with an ''out of stack space error'' - correct answer ✔✔What will happen if the terminating condition does not occur Another stack frame - correct answer ✔✔Each recursive invocation creates what until the terminating condition is met None - correct answer ✔✔Which data is shared inside the function invocations Must occur between the function invocations, in other words: sharing is done via the arguments and return values. - correct answer ✔✔How do you do sharing for recursion (defn flip [numbers] (if (empty? numbers) []

(conj (flip (rest numbers)) (first numbers) ))) - correct answer ✔✔Code to reverse the values in a vector of ints? By combining recursion with multi-arity methods - correct answer ✔✔How can you get more sophisticated results with recursion When one needs to initialize a value in just one instance of a function invocation - correct answer ✔✔When is it necessary to combine recursion with multi-arity methods in order By making a recursive call - correct answer ✔✔How can basic recursion be implemented When the recursion is the last expression in the function - correct answer ✔✔When is it recommended to use the recur function no - correct answer ✔✔Does Clojure directly support ''tail-call'' optimization Because Clojure doesn't support ''tail-call'' optimization - correct answer ✔✔Why a large number of stack frames can be created in Clojure tail-call recursions are transformed into something resembling a while loop, this uses a constant amount of stack space and is far more memory efficient - correct answer ✔✔What does the recur function do a default namespace called 'user' - correct answer ✔✔Clojure will associate your code to A collection of functions - correct answer ✔✔Library def in CLojure Java package - correct answer ✔✔CLojure library equivalent to Java's... once - correct answer ✔✔How many times will a library be processed

/ - correct answer ✔✔What do you use to separate thhe namespace path from the function :as - correct answer ✔✔Abbreviation for the namespace path in a single symbol When additional options are included - correct answer ✔✔When are [] required for namespace abbreviation Because we now have a vector of specification elements - correct answer ✔✔Why are [] necessary for namespace abbreviation :refer option - correct answer ✔✔How do you eliminate the need to fully qualify specific functions by using the yes - correct answer ✔✔Can you import Java classes into your Clojure Code using :import instead of :require - correct answer ✔✔How to import Java classes into Clojure code instantiates an object - correct answer ✔✔What does Date. do