Use Clojure: a. See attached picture. b. In Clojure (like other functional programming languages) functions and variables are treated identically. This means a function may easily take another function as an argument, and/or return a function. Write a function swap-arg-order which takes a function (of two arguments) as an argument returns another function that does the same thing, but expects its two arguments in the opposite order. That is, for example • given the division function / which divides the first argument by the second (so (/ 3 6) returns the number 1/2), the following expression should evaluate to 2 ((swap-arg-order /) 3 6) • given the function list-longer-than? from above, the following expression should evaluate to true ((swap-arg-order list-longer-than?) '(1 2 3) 2) c. Define a higher order function g so the following expression evaluates to true: (= 100 (g (fn [n] (* n n))))
Use Clojure:
a. See attached picture.
b. In Clojure (like other functional programming languages) functions and variables are treated identically. This means a function may easily take another function as an argument, and/or return a function. Write a function swap-arg-order which takes a function (of two arguments) as an argument returns another function that does the same thing, but expects its two arguments in the opposite order.
That is, for example
• given the division function / which divides the first argument by the second (so (/ 3 6) returns the number 1/2), the following expression should evaluate to 2
((swap-arg-order /) 3 6)
• given the function list-longer-than? from above, the following expression should evaluate to true
((swap-arg-order list-longer-than?) '(1 2 3) 2)
c. Define a higher order function g so the following expression evaluates to true:
(= 100 (g (fn [n] (* n n))))
Step by step
Solved in 3 steps