1

I was solving problems in 4clojure and got stuck at Problem 46 or example

(= true ((__ >) 7 8))

where we need to fill in the _

Basically I need to create a function that would take in another function as an argument but don't know where to go with that. Also, the evaluation kind of confuses me, if I create an anonymous function

(fn [f] ())

which takes in the function > I don't know how to pass in the other arguments for > to operate on.

I don't want the answer, just some direction.

1
  • A couple tips: with a function f, you can do (apply f args) where args is a list, or (f arg1 arg2 ...). Commented May 30, 2014 at 18:36

2 Answers 2

5

Given what ever you put in the blank will take > and then be evaluated as a function what you need is a function that returns a function.

You have this:

 (fn [f] ())

How do we get that to return a function?

 (fn [f] (fn [something here] (something here)))

Now all you have to do is fill out the 'something here's.

Sign up to request clarification or add additional context in comments.

2 Comments

Solved it (fn [f] (fn [a b] (f b a))) The returning a function part was a bit confusing initially. Thanks!!
nice, you can also use complement and partial - ((complement (partial >)) 7 8)
0

The function you are looking for is the one that returns a function that reverses its arguments and applies to the original function:

(fn [f]
  (fn [x y]
    (f y x)))

1 Comment

If you click through to the actual problem set he is looking at, that is not right. What they are looking for is a swap the arguments to the given function. One of the other examples is (= 3 ((__ nth) 2 [1 2 3 4 5]))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.