On Jul 2, 2009, at 1:48 PM, Mark Volkmann wrote:

(defn match [prev-char next-char]
 (cond = prev-char
   \( (= next-char \))
   \[ (= next-char \])
   true false))

It looks like you intended condp here instead of cond.

Your test works as expected if you make that change. However, there's another correction required to allow match to work in the general case. The last clause should be "false" instead of "true false". If it's not, then any prev-chars except \(, \[, and true will throw an exception.

----------
volkmann.clj (on classpath):
----------

(ns volkmann)

(defn match [prev-char next-char]
 (condp = prev-char
   \( (= next-char \))
   \[ (= next-char \])
   false))

(defn main
  []
  (prn
   (match \( \))
   (match \r \))))

----------
using clojure.contrib.repl-utils/run
----------

user=> (run volkmann)
true false
nil
user=>

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to