When abstracting out common behavior by creating higher-order functions, I
would like the resulting function to retain the arglist metadata. Has
anyone already solved this problem? If not, are there kosher ways of going
about it? I have a feeling it'd be possible to create a new def-form that
would do some additional merging of metadata from var to var... But rather
than diving into it immediately, I thought I'd take advantage of the
question and send my first email to the Clojure mailing list! :-)
Here's some contrived code to demonstrate the topic:
(defn foo [a]
(fn [x y] (println a x y)))
;= #'user/foo
(def bar (foo "_"))
;= #'bar
(meta (var foo))
;= {:arglists ([a]), :ns #<Namespace user>,…
(:arglists (meta (var bar)))
;= nil
(def ^{:arglists '([x y])} baz (foo "_"))
;= #'user/baz
(def quux (partial baz "x"))
;= #'user/quux
(find (meta (var quux)) :arglists)
;= nil
And here is a link demonstrating how I came across it in real life:
https://www.refheap.com/paste/3413 . Yes, I realized that there are
mistakes in the manually-entered metadata but I decided to leave them in
because they, as genuine accidents, emphasize the insufficiency of that
solution.
A pre-emptive "thank you" to any who help,
--Josh T
P.S. I can take this to StackOverflow instead if y'all think it would be
more appropriate there.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en