Title: Clojure
Course: LoadTesting

Write a function transpose that takes a matrix in the form of a list of rows (of equal length) and returns the transposed matrix (in the same form). See the examples.

Hints:

- Use the fact that map can take an arbitrary number of lists as its arguments.
- The function list may come handy (depending on your solution). See what is the result of (list 1 2 3).

Write a function conjoin that takes a variable number predicates (functions) as arguments and returns a new predicate (function) that is the logical conjunction of the given predicates. Assume that all the given predicates take one and only one argument (and return true or false). See the example test cases.

Hints:

1. Use reduce. Alternatively you can use the every? function in Clojure.
2. See variable arity in the lecture notes. For example see what the function (defn my-func [& more] more) returns when it is called like (my-func 1 5 "hi" :blah).
3. The above note implies that your function definition must start with something similar to (defn conjoin [& funcs] ...).

Write a function compose that takes a variable number of functions and returns a function that is the composition of those functions. The returned function takes one argument, applies the first (leftmost) of the functions to the argument, then the next function to the result, and so on until the last function whose result is returned. Assume that all the supplied functions accept one and only one argument. If compose is called with no argument, it must return the identity function. See the examples.

Restriction: Do not use any of these functions or symbols anywhere in your code: comp.

Hints:

1. You need to use variable arity, see the lecture notes.
2. See the documentation of reduce by calling (doc reduce) in Clojure shell (or reading the online documentation).
3. If you decide to use reduce, you need to use it with a function that returns another function.
4. Avoid using the #(...) short form as it does not work well with nested anonymous functions.
5. As a suggestion, start your exploration with writing a function that takes two functions and returns a composed function. Then extend your solution using reduce to take a list of functions.

Write a function arg-max that takes a function and a list of values and returns the value that maximises the function. If the list is empty the function must return nil. Assume that the given function takes one and only one argument.

Notes:

- arg-max is different from max
- See what (first ()) evaluates to. This may come useful depending on your solution.
- Consider using reduce.
- If there are more than one value that maximise the function, return only one of them (not a list of them).