Hi,

Am 09.01.2010 um 09:59 schrieb Dmitry Kakurin:

> Suppose I already have a function f that accepts 0 and 1 param:
> (defn f
>  ([] 0)
>  ([ _ ] 1))
> 
> How do I extend it with additional version that takes 2 params?
> Something like the following that does not override the original:
> 
> (defn f [ _ _ ] 2)
> 
> and makes all 3 work:
> (f)
> (f 1)
> (f 1 2)

This is not possible. You have to add the definition to the original one. Or – 
if you can't influence the original function definition – substitute your own:

(def orig-f foo/f)

(defn my-f
  ([] (orig-f))
  ([x] (orig-f x))
  ([_ _] 2))

(binding [foo/f my-f]
  (foo/f :a :b))

I suspect that you want to use that for a dirty hack. Why do you need that? Do 
you have some example code which demonstrates the problem?

Sincerely
Meikel

-- 
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