This may also be relevant. 

The following works:

(defn factorial [& args]
  (match [args]
   [([n] :seq)]            (factorial 1 n)
   [([so-far 1] :seq)]     so-far
   [([so-far n] :seq)]     (factorial (* n so-far) (dec n))))

user=> (factorial 5)
120

However, changing the order of clauses stops that:


(defn factorial [& args]
  (match [args]
   [([so-far 1] :seq)]     so-far
   [([so-far n] :seq)]     (factorial (* n so-far) (dec n))
   [([n] :seq)]            (factorial 1 n)))        ;; <<== moved this down

user=> (factorial 5)
NullPointerException   clojure.lang.Numbers.ops (Numbers.java:942)



-----
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to