Problems with ONEARGCHECK and TWOARGCHECK



computing the length of the argument list is wasteful, as is binding a
variable a second time.

You could do, I suppose,

(defmspec $expintegral_ei(L)
 (if (/= (length (setq L (cdr L))) 1) (wna-err '$expintegral_ei))
 (simplify(....)))

or faster/simpler..
(unless (and (setq L (cdr L))(null (cdr L))) (wna-err ...))

or write a macro that expands into the above. e.g.

(defmacro unlesslength1(x result)..)
(defmacro unlesslength2(x result) ..)
(defmacro unlesslength3(x result) ..)

and then perhaps unlesslength(n x result)  for n>3

e.g. the usage would be
(setq L (cdr L))
(unlesslength2 L (wna-err ...))

where 

(defmacro unlesslength2(x res)`(if (and x (cdr x)(cddr x)(not (cdddr x)))
nil ,res))




RJF


> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Dieter Kaiser
> Sent: Saturday, July 26, 2008 3:22 AM
> To: robert.dodier at gmail.com
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] Problems with ONEARGCHECK and TWOARGCHECK
> 
> Sorry, I did not see that the problem arise because we have 
> no check (for GCL)
> for the arguments calling a Lisp function $<function>.
> 
> Because I am interested to make the code sure for Maxima 
> Users I have try to
> implement the Maxima User function for the Exponential 
> Integrals with defmspec.
> 
> The code looks like:
> 
> (defmspec $expintegral_ei (l)
>   (let ((l (cdr l)))
>     (if (= (length l) 1)
>       (simplify (list '(%expintegral_ei) (resimplify (car l))))
>       (wna-err '$expintegral_ei))))
> 
> With this code it works fine and we have a check for the 
> number of args.
> 
> The problem with the wrong number of arguments arise in all 
> function which are
> directly coded as Lisp functions. Should this be changed like 
> above e. g. for
> the Bessel functions or Airy functions to have a more correct 
> and predictable
> behaviour of the functions?
> 
> Dieter Kaiser
> 
> -----Urspr?ngliche Nachricht-----
> Von: robert.dodier at gmail.com [mailto:robert.dodier at gmail.com] 
> Gesendet: Samstag, 26. Juli 2008 04:00
> An: Dieter Kaiser
> Cc: maxima at math.utexas.edu
> Betreff: Re: [Maxima] Problems with ONEARGCHECK and TWOARGCHECK
> 
> On 7/24/08, Dieter Kaiser <drdieterkaiser at web.de> wrote:
> 
> >  (%i4) bessel_j(1);
> >  (%o4) bessel_j(1, #<compiled-closure 03cd5e38>)
> 
> >  (%i7) airy_ai();
> >  (NIL . |$;|) is a cons with an atomic cdr - `simplifya'
> 
> >  I use gcl 2.6.8 and the Maxiam CVS code on a Windows XP system.
> 
> The observed behavior appears to be a bug in GCL.
> >From what I can tell, GCL doesn't check the number of arguments
> in compiled code. Other Lisp varieties do check, so
> airy_ai() and bessel_j() cause errors for them (Clisp, CMUCL,
> probably others).
> 
> Here's a small example for GCL.
> 
> >(defun f (x y) y)
> 
> >(f 1)
>  => error
> 
> >(compile 'f)
> 
> >(f 1)
>  => #<compiled-function 08473b20>
> 
> This last result is incorrect; should be an error.
> 
> HTH
> 
> Robert Dodier
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>