#1486 Compiled Function error message/FIX

open
nobody
Lisp Core (471)
5
2009-07-17
2008-08-31
No

Try the following.

(%i1) f(x) := x$
(%i2) f(1,2);
Too many arguments supplied to f(x): [1,2]

(%i3) compile(f)$

(%i4) f(1,2);
 Maxima encountered a Lisp error:
Error in MACSYMA-TOP-LEVEL [or a callee]: MACSYMA-TOP-LEVEL [or a callee]
requires less than two arguments.

"The error message tells the user almost nothing. I consider that a bug.

Barton"

Rich Hennessy

------
Maxima version: 5.16.2
Maxima build date: 7:44 8/18/2008
host type: i686-pc-mingw32
lisp-implementation-type: GNU Common Lisp
(GCL)lisp-implementation-version: GCL 2.6.8
------

Discussion

  • Rich Hennessy

    Rich Hennessy - 2008-08-31

    Logged In: YES
    user_id=2055069
    Originator: YES

    I think I figured it out, you have to have a function defined and it also has to be compiled.

    this works
    (%i1) factor(-hbar^2/(2*m)*diff(f(x),x,2)=E*f(x)-mu*x^4*f(x));
    (%o1) -(hbar^2*('diff(f(x),x,2)))/(2*m)=f(x)*(E-mu*x^4)

    if f is defined as a function of two or more variables and it is not compiled then you get this error.
    (%i1) f(x,y):=x^2*y;
    (%o1) f(x,y):=x^2*y
    (%i2) factor(-hbar^2/(2*m)*diff(f(x),x,2)=E*f(x)-mu*x^4*f(x));
    Too few arguments supplied to f(x,y):[x] -- an error.  
    To debug this try debugmode(true);

    which is a better error message.

    but if you compile f then you get

    (%i1) f(x,y):=x^2*y;
    (%o1) f(x,y):=x^2*y

    (%i2) compile(f);
    Compiling C:/DOCUME~1/RICHAR~1/LOCALS~1/Temp/gazonk_3888_0.lsp.
    End of Pass 1.  
    End of Pass 2.  
    OPTIMIZE levels: Safety=2, Space=3, Speed=3
    Finished compiling C:/DOCUME~1/RICHAR~1/LOCALS~1/Temp/gazonk_3888_0.lsp.
    (%o2) [f]

    (%i3) factor(-hbar^2/(2*m)*diff(f(x),x,2)=E*f(x)-mu*x^4*f(x));
    Maxima encountered a Lisp error: Error in MACSYMA-TOP-LEVEL [or a callee]: MACSYMA-TOP-LEVEL [or a callee] requires more than one argument.
    Automatically continuing.
    To reenable the Lisp debugger set *debugger-hook* to nil.

    Which is a harder message to debug. I think I may have had a definition for f after all and it was compiled too since I have a workbook which does just that and I was playing around with that workbook last night before I got this error.  So it only happens on compiled functions so far in my testing.

     
  • Rich Hennessy

    Rich Hennessy - 2008-08-31
    • labels: 870406 --> Lisp Core
    • summary: Factor of Compiled Function error message --> Compiled Function error message
     
  • Raymond Toy

    Raymond Toy - 2009-07-16

    The message is from the underlying Lisp implementation.

    But consider this:

    h(x,y,[r]) := [x,y,r];

    h(1,2) -> [1,2,[]]
    h(1)->
    Too few arguments supplied to h(x,y,[r]):
    [1]

    After compiling h, we get:

    h(1,2) -> [1,2,[]]

    h(1) ->
    maxima-error h TAKES NO LESS THAN 2 ARGUMENTS.

    I think this is better. (I think the error message should match what the uncompiled version says, but that's a different issue.)

    The translator should do something similar with f as it does for h. Except, of course, extra arguments aren't allowed.

     
  • Raymond Toy

    Raymond Toy - 2009-07-17
    • summary: Compiled Function error message --> Compiled Function error message/FIX
     
  • Raymond Toy

    Raymond Toy - 2009-07-17

    FWIW, here is a potential fix. This makes compiled functions slightly slower and conses more, but the result is that the error messages and behavior are the same for compiled and interpreted code.

    (defmacro defmtrfun ((name mode prop restp . array-flag) argl . body )
    (let ((def-header))
    (and array-flag
    ;; old DEFMTRFUN's might have this extra bit NIL
    ;; new ones will have (NIL) or (T)
    (setq array-flag (car array-flag)))
    (setq def-header
    (cond ((eq prop 'mdefine)
    (cond (array-flag `(:property ,name a-subr))
    (t name)))
    (t `(,name translated-mmacro))))

    `(eval-when
    #+gcl (compile load eval)
    #-gcl (:compile-toplevel :load-toplevel :execute)

    ,@(and (not array-flag) `((remprop ',name 'translate)))
    ,@(and mode `((defprop ,name ,mode
    ,(cond (array-flag 'arrayfun-mode)
    (t 'function-mode)))))
    ,@(cond (array-flag
    ;; when loading in hashed array properties
    ;; most exist or be created. Other
    ;; array properties must be consistent if
    ;; they exist.
    `((insure-array-props ',name ',mode ',(length argl)))))
    ,@(cond ((and (eq prop 'mdefine) (not array-flag))
    `((cond ((status feature macsyma)
    (mputprop ',name t
    ,(cond ((not restp)
    ''$fixed_num_args_function)
    (t
    ''$variable_num_args_function)))))
    ,(cond ((not restp) nil)))))
    (,(if (consp def-header)
    'defun-prop
    'defmfun)
    ,def-header |mlexpr NARGS|
    ,@(cond ((not restp)
    (let ((nl (length argl)))
    `((cond ((/= |mlexpr NARGS| ,nl)
    (merror "Too ~M arguments supplied to ~M:~%~M"
    (if (< |mlexpr NARGS| ,nl) "few" "many")
    (cons (cons ',name nil) ',argl)
    (list* '(mlist) narg-rest-argument)))
    (t
    ((lambda ,argl ,@body)
    ;; this conses up the
    ;; calls to ARGS and LISTIFY.
    ,@(do ((j 1 (1+ j))
    (p-argl nil))
    ((> j nl)
    (nreverse p-argl))
    (push `(arg ,j) p-argl))))))))
    (t
    (let ((nl (1- (length argl))))
    `((cond ((< |mlexpr NARGS| ,nl)
    (merror "Too few arguments supplied to ~M:~%~M"
    ',(append (list (list name))
    (butlast argl)
    (list (cons '(mlist) (last argl))))
    (list* '(mlist) narg-rest-argument)))
    (t
    ((lambda ,argl ,@body)
    ;; this conses up the
    ;; calls to ARGS and LISTIFY.
    ,@(do ((j 1 (1+ j))
    (p-argl nil))
    ((> j nl)
    (push
    `(cons '(mlist) (listify (- ,nl |mlexpr NARGS|)))
    p-argl)
    (nreverse p-argl))
    (push `(arg ,j) p-argl)))))))))))))

     

Log in to post a comment.