Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write :else in condp in Clojure?

Tags:

clojure

I want to use the condp clause but I dont know how to catch any unmatched clause. How do I do that?

(defn subst[id value W-lang]
  (let [[type expr][(first W-lang)(rest W-lang)]]
    (condp = type
        'num (first expr)
        'add expr       
        ***** expr)))
like image 553
unj2 Avatar asked Aug 07 '09 03:08

unj2


1 Answers

The documentation for condp says:

A single default expression can follow the clauses, and its value will be returned if no clause matches. If no default expression is provided and no clause matches, an IllegalArgumentException is thrown.

So:

(condp = type
    'num (first expr)
    'add expr
    expr)))
like image 156
Greg Hewgill Avatar answered Oct 24 '22 16:10

Greg Hewgill