Giter Club home page Giter Club logo

Comments (5)

vemv avatar vemv commented on September 23, 2024

Thanks for the accurate report!

Taking a look at the commit that introduced this 02c4e80 - originally all params were forwarded.

Surely that was unawarely broken later.

I'm on the fence as to whether to introduce a breaking change.

Looks like we have a neat option: detect the arity of the user-set cider-interactive-eval-override, and only pass the last argument if cider-interactive-eval-override is ready for it.

Demo:

ielm> (help-function-arglist (lambda (a b c)))
(a b c)

ielm> (help-function-arglist 'mapcar)
(arg1 arg2)

Would you be interested in creating a PR?

Cheers - V

from cider.

chpill avatar chpill commented on September 23, 2024

That's a great idea, I'll try to submit a PR that checks the number of arguments. Thanks for the pointer!

from cider.

chpill avatar chpill commented on September 23, 2024

There is a func-arity that is even more convenient than help-function-arglist for our use case:

(let* ((arities (func-arity cider-interactive-eval-override))
       (min-arity (car arities))
       (max-arity (cdr arities)))
  (if (or (eq 'many max-arity)
          (and (numberp min-arity)
               (numberp max-arity)
               (<= min-arity 4 max-arity)))
    (funcall cider-interactive-eval-override form callback bounds additional-params)
    (funcall cider-interactive-eval-override form callback bounds)))

But there is an issue. When using apply-partially for example, the arglist becomes opaque, and from the outside, it'll look like the function takes any number of arguments (func-arity would return (0 . many)). I have found at least one example in the wild that would break because of this. I have thought of restricting functions using &rest arguments from accessing the new feature for the sake of backward compatibility, but then that would prevent other perfectly valid functions from working such as:

(defun println-override (form &rest extra-args)
  (let ((cider-interactive-eval-override nil))
    (apply 'cider-interactive-eval
           (concat "(do (println :wrapped) " form ")")
           extra-args)))

So maybe a better way is not to check the arities, but to try to call the arity-4 version anyway, and if an arity error occurs, fallback on the previous arity-3 call site:

(condition-case _
  (funcall cider-interactive-eval-override form callback bounds additional-params)
  (wrong-number-of-arguments
   (funcall cider-interactive-eval-override form callback bounds)))

@vemv what do you think?

from cider.

vemv avatar vemv commented on September 23, 2024

Hi @chpill kudos for looking into it!

Yes, suporting a simple defun println-override (form &rest extra-args) would be important.

So your proposal seems great.

from cider.

chpill avatar chpill commented on September 23, 2024

@vemv thanks a lot!

from cider.

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.