-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reusing of another functions :doc
and :arglists
#1811
Comments
Note that The interpretation given by @puredanger in the linked thread was that |
To avoid this construction, one has to use (defn function-a [args]
(function-b args)
(alter-meta! #'function-a
assoc
:arglists (:arglists (meta #'function-b)))
;; or
(alter-meta! #'function-a
merge
(select-keys (meta #'function-b)
[:arglists :doc])) |
It should also include |
@yuhan0 I'm not sure if it matters here though, since you have one var copying another, it would never call itself no? |
Well, not in the specific example given.. but I can imagine a situation where it could arise: (defn- frob-impl ;; maybe a protocol method which can't take 0 args
[{:keys [beep boop]}]
,,,)
(defn frob
"public API with extra convenience arity"
{:arglists (->> (:arglists (meta #'frob-impl))
(cons []))}
([] (frob default-opts))
([opts] (frob-impl opts))) Of course it could be rewritten as Either way if the syntax itself turns out to be officially unsupported or discouraged, it's probably not a good idea to build a feature around it? (I don't think it was definitively settled in the ask.clojure thread) |
Is your feature request related to a problem? Please describe.
function-a
takes the same arguments asfunction-b
. In fact,function-a
callsfunction-b
. Sometimes they also share docs. E.g. with Polylith style interfaces and implementations. Without too much synchronized updating of the function signatures, I'd like for clojure-lsp to show me the same docs/hover info for the two functions.At the REPL, this works:
It makes the sharing very clear.
(doc function-b)
will print:Describe the solution you'd like
It would be super nice if it worked with clojure-lsp too, making for a shared way for the dynamic and static tools to help with this.
Describe alternatives you've considered
There are some ways to make the sharing a bit less verbose than full copies of the the docs and argument lists, but I don't think none is this clear and complete and also at the same time works for the REPL.
Additional context
Here's a write-up about the general problem and some ways to deal with it with the current clojure-lsp: https://blog.agical.se/en/posts/keeping-the--arglists-of-clojure-functions-dry/
Here's a Clojurians Slack thread where that blog post started from: https://clojurians.slack.com/archives/C03S1KBA2/p1713449139604419 (It also reveals that the actual suggestion in this feature request comes from @ericdallo 😄 )
The text was updated successfully, but these errors were encountered: