Menu

#3455 Argument count checking

None
closed
nobody
None
5
2020-07-29
2018-07-25
No

Many Maxima functions give poor error messages when called with the wrong number of arguments, e.g.:

factor(2,3,4);
Maxima encountered a Lisp error:
invalid number of arguments: 3

Same thing for integerp, oddp, featurep, etc. etc.

This is ridiculous. A user calling a public Maxima function with the wrong number of arguments should get a nice clean error, identifying the function being called with the wrong number of argumens.

It should not be necessary to go into Lisp debugging mode to figure that out. Surely the exception includes information about what function is being called?!

Maxima version: "5.41.0a_dirty"
Maxima build date: "2017-10-24 09:10:17"
Host type: "x86_64-w64-mingw32"
Lisp implementation type: "SBCL"
Lisp implementation version: "1.3.18"

Related

Bugs: #3455

Discussion

  • Raymond Toy

    Raymond Toy - 2018-08-06

    I agree, but I'm not really sure how to maek this happen except to change $factor to be bascially.

    (defun $factor (&rest args)
       ;; parse args to find out what the options are and how many are needed
        ;; Then throw if a maxima-error if the number of arguments is wrong.
        ;; This will slow down code that calls $factor.
     )
    

    ```

     
    • Stavros Macrakis

      If that's what we need to do, that seems OK with me.
      But I would have thought that the error handler could take care of it (but
      I don't know how compatible the error handlers are in our different Lisps).
      In any case, we have lots of ancient code where the functions are
      unnecessarily argument-quoting (defmspec, old FEXPRs) -- and so have to
      explicitly call meval -- because there was no other way to handle a
      variable number of arguments.

      On Mon, Aug 6, 2018 at 6:53 PM Raymond Toy rtoy@users.sourceforge.net
      wrote:

      I agree, but I'm not really sure how to maek this happen except to change
      $factor to be bascially.

      (defun $factor (&rest args)
      ;; parse args to find out what the options are and how many are needed
      ;; Then throw if a maxima-error if the number of arguments is wrong.
      ;; This will slow down code that calls $factor.
      )

      ```

      Status: open
      Group: None
      Created: Wed Jul 25, 2018 08:30 PM UTC by Stavros Macrakis
      Last Updated: Wed Jul 25, 2018 08:30 PM UTC
      Owner: nobody

      Many Maxima functions give poor error messages when called with the wrong
      number of arguments, e.g.:

      factor(2,3,4);
      Maxima encountered a Lisp error:
      invalid number of arguments: 3

      Same thing for integerp, oddp, featurep, etc. etc.

      This is ridiculous. A user calling a public Maxima function with the wrong
      number of arguments should get a nice clean error, identifying the function
      being called with the wrong number of argumens.

      It should not be necessary to go into Lisp debugging mode to figure that
      out. Surely the exception includes information about what function is being
      called?!

      Maxima version: "5.41.0a_dirty"
      Maxima build date: "2017-10-24 09:10:17"
      Host type: "x86_64-w64-mingw32"
      Lisp implementation type: "SBCL"
      Lisp implementation version: "1.3.18"


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/maxima/bugs/3455/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #3455

  • Gunter Königsmann

    Common lisp offers a zillion of useful things that often are quite astonishing. The information which function has thrown an error it doesn't offer, though. So we have to use specific extensions of sbcl, clisp, ecl etc. In order to determine the command that threw an lisp error.

     
  • Raymond Toy

    Raymond Toy - 2018-08-10

    There is already some support for this in defun-checked (in clmacs.lisp), used in the quadpack routines (and maybe others). Doing this will slow everything down at least a little.

    So

    quad_qag()
    

    produces this nice error:

    Too few arguments supplied to quad_qag(fun, var, a, b, key, 
                                                 [epsrel, limit, epsabs]): found []
     -- an error. To debug this try: debugmode(true);
    

    This would need to be extended to handle optional args like that used in $factor.

     
  • Robert Dodier

    Robert Dodier - 2018-08-18

    Dunno about DEFUN functions, but it seems like we could beef up the DEFMFUN macro to give a clearer error message for the wrong number of arguments.

     
  • Robert Dodier

    Robert Dodier - 2020-07-29
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2020-07-29

    I think this is appropriately handled by recent work on the DEFMFUN macro. At present (5.44.0) for the example cited I get:

    (%i1) factor(2,3,4);
    factor: expected at most 2 arguments but got 3: [2, 3, 4]
    

    I think that's a useful result.

     

Log in to post a comment.

MongoDB Logo MongoDB