GithubHelp home page GithubHelp logo

Comments (5)

yuhan0 avatar yuhan0 commented on September 26, 2024 1

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 (frob-impl default-opts), but figuring this out from the error stacktraces is not quite straightforward.

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)

from clojure-lsp.

yuhan0 avatar yuhan0 commented on September 26, 2024

Note that function-a as defined will fail to compile when its body contains a call to itself:
https://ask.clojure.org/index.php/13834/compiler-exception-dynamically-arglists-metadata-recursive

The interpretation given by @puredanger in the linked thread was that :arglists in the attr-map should be restricted to literal quoted lists, so expressions to be evaluated like (:arglists (meta #'function-b)) should be at least discouraged (if not considered illegal).

from clojure-lsp.

yuhan0 avatar yuhan0 commented on September 26, 2024

To avoid this construction, one has to use alter-meta! on the var after its creation, which I imagine is trickier to statically analyze:

(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]))

from clojure-lsp.

didibus avatar didibus commented on September 26, 2024

It should also include :macro meta for when you want to do this for a macro.

from clojure-lsp.

didibus avatar didibus commented on September 26, 2024

@yuhan0 I'm not sure if it matters here though, since you have one var copying another, it would never call itself no?

from clojure-lsp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.