Why did father of Clojure say that Scheme’s true/false are broken?

It strikes me you’d rather see it from the horse’s mouth, so here’s a choice extract from a message Rich posted: Scheme #t is almost completely meaningless, as Scheme conditionals test for #f/non-#f, not #f/#t. I don’t think the value #f has much utility whatsoever, and basing conditionals on it means writing a lot of … Read more

When to use let vs. if-let in Clojure

I guess if-let should be used when you’d like to reference an if condition’s value in the “then” part of the code: i.e. instead of (let [result :foo] (if result (do-something-with result) (do-something-else))) you write: (if-let [result :foo] (do-something-with result) (do-something-else)) which is a little neater, and saves you indenting a further level. As far … Read more

What is the difference between defn and defmacro?

defn defines a function, defmacro defines a macro. The difference between functions and macros is that on a function call first the arguments of the function are evaluated then the body of the function is evaluated using the arguments. Macros on the other hand describe a transformation from one piece of code to another. Any … Read more

Any clojurescript tutorials? [closed]

Fogus is writing a series on ClojureScript which you may find interesting. Compiling Clojure to Javascript Jul 21, 2011 Compiling Clojure to JavaScript, pt. 2 – Why No Eval? Jul 29, 2011 Compiling Clojure to JavaScript, pt. 3 – The Himera Model Mar 27, 2012 The ClojureScript Compilation Pipeline Apr 25, 2012

Why should I use Reify instead of proxy in clojure?

The method bodies of reify are lexical closures, and can refer to the surrounding local scope. reify differs from proxy in that: Only protocols or interfaces are supported, no concrete superclass. The method bodies are true methods of the resulting class, not external fns. Invocation of methods on the instance is direct, not using map … Read more

How to check the equality of strings in clojure without invoking java.lang.String?

Equality in Clojure (the = function) always tests value, not identity, so two strings are = if they have the same contents. For most Java types, including String, Clojure = dispatches to Java .equals. String.equals is defined as “represents the same sequence of characters.” If you want to test identity (Are these pointers to 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