Here's some (simpler?) code that will work for adding arity to
existing functions - http://gist.github.com/273401

It doesn't handle adding variable-arity (ie multiple arity using &) to
existing functions, but can add specific arity to existing varibale-
arity functions
It also doesn't handle adding more than one arity at a time, but you
can call it multiple times with different arity to get the same
effect. See example below -

An example to add arity -

user> (extend-fn keyword [ns name suffix]
        (keyword ns (str name "-" suffix)))

user> (extend-fn keyword [ns prefix name suffix]
        (keyword ns (str prefix "-" name "-" suffix)))

Here's the example usage -

user> (keyword nil "hello")
:hello

user> (keyword nil "hello" "more")
:hello-more

user> (keyword nil "oh" "hello" "more")
:oh-hello-more

Again, like Tom said, dunno why you'd need to do this...

On Jan 9, 10:45 pm, Tom Faulhaber <tomfaulha...@gmail.com> wrote:
> Actually this is possible. (seehttp://xkcd.com/386/)
>
> See the macro add-arity which I've put up here:http://gist.github.com/273349
>
> This allows you to do things like:
>
> user> (add-arity keyword [ns name suffix] (keyword ns (str name "-"
> suffix)))
> #<user$eval__6304$fn__6309 user$eval__6304$fn__6...@5d8e63>
>
> user> (keyword nil "hello" "more")
> :hello-more
>
> The code I put up will handle (I think) all sorts of variations of arg
> counts: you can use add-arity just like defn and it will grab any
> specified arglists (including arglists with &) and proxy the others
> back to the original function. It doesn't do anything with metadata,
> though. Also, you can override a given arity on the original function,
> but you can't then call the original version at that arity.
>
> Whether this is a good idea or not is a completely different
> question :-)
>
> Tom
-- 
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