Yup, this version would cover most cases in a simpler way. My goal (for no particular reason except it entertained me) was to make something that worked as much like defn as possible. Most of the complexity is because of handling the possible combinations of arities that we might see as a result: I need to "fill in the holes" with proxies (though I could have wrapped with an if as well).
extend-fn is also a much better name. I'm amused that you did the same thing I did before I realized it was silly: "old-fn# (var-get (var ~name))" can just be "old-fn# ~name". (It's like "use" and "utilize" one of my pet peeves in English.) Tom On Jan 10, 1:03 am, Amit Rathore <amitrath...@gmail.com> wrote: > 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