2
votes
3answers
217 views

What are those functional functions called?

I'm looking for a functional way to implement this: list = [a b c d e f] foo(list, 3) = [[a d] [b e] [c f]] A potential solution is: foo(list,spacing) = zip(goo(list,spacing)) Where, for ...
3
votes
2answers
36 views

def'ine a value with a dynamic name

So I want to pass a function to the "name" portion of def. The problem is: "First argument to def must be a Symbol" I'm trying to for instance do: (def serverNumber 5) (def (str "server" ...
6
votes
3answers
155 views

Sharing functions between namespaces in Clojure

I may very well be approaching this in the wrong way, so please forgive me of my naiveté: In order to learn Clojure I've begun porting my OAuth client library for Python to Clojure. I'm doing this by ...
2
votes
5answers
91 views

More idiomatic and elegant way of Clojure function

I have a function which finds the least distance between nodes in graph, written in Ruby. I translated it to Clojure, but in my opinion it looks terrible. The representation of data looks like this: ...
1
vote
1answer
87 views

Clojure recursive function execution time

I'm programming a web crawler in clojure and it takes constant time independently of the depth I give to the function. This is the function itself. (it is using clojure soup, but that I think is ...
4
votes
2answers
86 views

Retrieve Clojure function metadata dynamically

Environment: Clojure 1.4 I'm trying to pull function metadata dynamically from a vector of functions. (defn #^{:tau-or-pi: :pi} funca "doc for func a" {:ans 42} [x] (* x x)) (defn #^{:tau-or-pi: ...
2
votes
2answers
158 views

Calling an anonymous function from an anonymous function

I'd like to call an anonymous function which is not using the shorthand notation from another anonymous function. Doing the following isn't working because the last evaluation is returned: user> ...
12
votes
3answers
416 views

Anonymous function shorthand

There's something I don't understand about anonymous functions using the short notation #(..) The following works: REPL> ((fn [s] s) "Eh") "Eh" But this doesn't: REPL> (#(%) "Eh") This ...
2
votes
1answer
108 views

Clojure: how to send remaining arguments “& args” into list?

Is there any (reasonable) way to write this macro as a function? (defmacro assocTop [v & args] `(push (pop ~v) (assoc (peek ~v) ~@args))) Given a vector of ...
4
votes
1answer
90 views

Clojure: function arguments/signatures using macro or def

I have many functions of the same long signature (shortened here for simplicity): (defn f [x & {:keys [a b c d e f g h] :or [a false b false c false d false e false f false g ...
1
vote
3answers
76 views

Is the Macro argument a function?

I am trying to determine whether a given argument within a macro is a function, something like (defmacro call-special? [a b] (if (ifn? a) `(~a ~b) `(-> ~b ~a))) So that the following ...
9
votes
1answer
167 views

Is it good practice for a Clojure record to implement IFn?

Suppose I have a record that is "function-like", at least in the sense that it represents an operation that could be applied to some arguments. I can make it work as a function by implementing ...
2
votes
2answers
92 views

How can I get the name of a function from a symbol in clojure?

Suppose I define x as symbol function foo (defn foo [x] x) (def x foo) Can the name "foo" be discovered if only given x? Is there a way within foo to look up the name of the function x - "foo" in ...
1
vote
2answers
54 views

Use record in several namespaces

I have clojure file with some predefined functions and records ;outer.clj (ns outer ) (defn foo [a] (println a)) (defrecord M [id]) And now usage file ;inner.clj (ns inner (:use outer )) (foo 2) ...
0
votes
1answer
74 views

Higher-order functions and short forms

Why we can write (defn factory-foo [] (fn [] (println "foo"))) (apply (factory-foo) []) but not: (defn factory-bar [] #((println "bar"))) (apply (factory-bar ) []) ;throws NPE Is this a bug? ...

1 2 3
15 30 50 per page