Question
Do not use any of the built-in Clojure functions/macros except: def, defn, fn, if, cond, let, arithmetic operations, comparison operations, and, or, not, str, seq,
Do not use any of the built-in Clojure functions/macros except: def, defn, fn, if, cond, let, arithmetic operations, comparison operations, and, or, not, str, seq, cons, first, rest, nth, zero?, seq?, empty?, nil?, odd?, even?, assoc. Create the following functions using Clojure. 1. (swapper s1 s2 slist) returns a list the same as slist, but with all occurrences of s1 replaced by s2 and all occurrences of s2 replaced by s1. > (swapper a d (a b c d)) (d b c a)
2. (list-set lst n x) returns a list like lst, except that the n-th element, using zero-based indexing, is x. n will always satisfy (and (>= n 0)(< (count lst))) (that is, it will be a valid existing index). > (list-set (a b c d) 2 (1 2)) (a b (1 2) d)
3. (count-occurrences s lst) returns the number of occurrences of s in lst. > (count-occurrences x ((f x) y (((x z) x)))) 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started