When to prefer keywords as functions?

2014-07-03 Thread gvim
I'm reading Cloujure in Action as an introduction to Clojure and, although, I understand a keyword can be used as a function I don't understand the difference between: (ns org.currylogic.damages.http.expenses (:require [clojure.data.json :as json-lib]

Re: When to prefer keywords as functions?

2014-07-03 Thread James Reeves
The ns form is a macro that takes a special syntax and always uses the keyword form, as you have in your first example. Your second example is incorrect; I'd be surprised if it even ran. The reason for this is to make it clear that you're not executing the require function directly, but instead

Re: When to prefer keywords as functions?

2014-07-03 Thread gvim
On 03/07/2014 18:36, James Reeves wrote: The reason for this is to make it clear that you're not executing the require function directly, but instead passing options to the ns form. I don't understand not executing the require function directly. I've also seen the when function called as

Re: When to prefer keywords as functions?

2014-07-03 Thread adrian . medina
I believe you might have seen :when in the binding vector of either a for or deseq form. Their special usage is documented here: http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/for In any event, James explained the distinction quite well. Macros are often used to create

Re: When to prefer keywords as functions?

2014-07-03 Thread Mauricio Aldazosa
Keywords can be used as a function with a map, so the keyword will search for itself in the map. Take a look at http://clojure.org/data_structures#Data%20Structures-Keywords In the case of the ns form, as James pointed out, what is happening is not a function call. ns is a macro and as such that

Re: When to prefer keywords as functions?

2014-07-03 Thread Jony Hudson
One thing to note is that while it's true keywords can be used as functions they can only really do one thing, which is get values from maps. That is to say, the keyword-function :foo is equivalent to the function #(get % foo). The function :foo has no relationship with the function foo, if it