Hi Rich, hi everybody,

I finally got around to trying an implementation of condp.  I had to
write two other libs to do it the way I wanted.  Here's the result:

    (condp (instance? _ (* 99 99))
           Number "it was a Number"
           String "it was a String"
           "it was something else")
    => "it was a Number"

    (condp (instance? String _)
           32 "32 was a String"
           :foo ":foo was a String"
           "hello" "hello was a String")
    => "hello was a String"

    (econdp (instance? _ :foo)
            Number "it was a Number"
            String "it was a String")
    => java.lang.Exception: Nothing matched in econdp.

Note the underscores in the expressions.  Those are "templates", in
clojure.contrib.template, which work a little like #().  They are
anonymous functions, but sub-expressions get evaluated when the
function is defined, not every time it is called.  So, in the first
example, (* 99 99) only gets evaluated once.

Take a look at clojure.contrib.walk, clojure.contrib.template, and
clojure.contrib.condp (SVN rev. 304) for source & more comments.  Hope
something here is useful, or at least interesting.

I'm going to use this to redefine "are" in clojure.contrib.test-is.

Later,
-Stuart Sierra
--~--~---------~--~----~------------~-------~--~----~
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
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