Difference between Symbols and Vars in Clojure

There’s a symbol + that you can talk about by quoting it: user=> ‘+ + user=> (class ‘+) clojure.lang.Symbol user=> (resolve ‘+) #’clojure.core/+ So it resolves to #’+, which is a Var: user=> (class #’+) clojure.lang.Var The Var references the function object: user=> (deref #’+) #<core$_PLUS_ clojure.core$_PLUS_@55a7b0bf> user=> @#’+ #<core$_PLUS_ clojure.core$_PLUS_@55a7b0bf> (The @ sign is … Read more

Why such implementation of partial in clojure.core

Yes, it’s a performance optimization. I’ts not just about not calling concat – it’s about the fact that & in the argument list requires a collection to be created as well. The clojure core libraries tend to take performance seriously, under the assumption that the basic building blocks of the language will be present in … Read more

Function call in -> threading macro

The documentation for the -> and ->> macros state that the forms after the first parameter are wrapped into lists if they are not lists already. So the question is why does this not work for #() and (fn ..) forms? The reason is that both forms are in list form at the time the … Read more

How can I display the definition of a function in Clojure at the REPL?

An alternative to source (which should be available via clojure.repl/source when starting a REPL, as of 1.2.0. If you’re working with 1.1.0 or lower, source is in clojure.contrib.repl-utils.), for REPL use, instead of looking at functions defined in a .clj file: (defmacro defsource “Similar to clojure.core/defn, but saves the function’s definition in the var’s :source … Read more

Clojure multimethods vs. protocols

Protocol and multimethods are complementary and intended for slightly different use cases. Protocols provide efficient polymorphic dispatch based on the type of the first argument. Because the is able to exploit some very efficient JVM features, protocols give you the best performance. Multimethods enable very flexible polymorphism which can dispatch based on any function of … Read more

How many primitives does it take to build a LISP machine? Ten, seven or five?

Basic Predicates/F-functions McCarthy‘s Elementary S-functions and Predicates were: atom Which was necessary because car and cdr are defined for lists only, which means you cannot count on any sort of answer to indicate what was happening if you gave car an atom. eq For testing equality between atoms. car For returning the first half (address) … Read more