Subject: Problems with ONEARGCHECK and TWOARGCHECK
From: Dieter Kaiser
Date: Sat, 26 Jul 2008 17:02:49 +0200
Thank you very much for your hint. I have not a lot of experience to optimize
Lisp code. Second, the macros of Lisp are allways a bit like a miracle for me. I
should take some extra lessons to really understand the full power of Lisp
macros.
I have taken your second example. For a function of two arguments the following
now works fine:
(defmspec $expintegral_e (l)
;; We check for a call with two arguments.
(unless (and (setq l (cdr l)) (not (null (cdr l))) (null (cddr l)))
(wna-err '$expintegral_e))
(simplify
(list '(%expintegral_e)
(resimplify (meval (car l)))
(resimplify (meval (cadr l))))))
In my first version I have ommitted the extra calls to meval which we need if
the arguments are not just numbers.
At the moment I am working on the numerical routines for Real and Complex
parameters of the Exponential Integral E[n](z). The numerical algorithm allready
works. Now I have to redesign some parts of the code.
Dieter Kaiser
-----Urspr?ngliche Nachricht-----
Von: fateman at cs.berkeley.edu [mailto:fateman at cs.berkeley.edu]
Gesendet: Samstag, 26. Juli 2008 15:54
An: 'Dieter Kaiser'
Cc: 'Maxima List'
Betreff: RE: [Maxima] 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
>