proposal to modify op and args



commercial macsyma produces an error for op(3).

An alternative  for this proposal is what Mathematica does
for its operator,   Head[].  
Head[a+b]   is Plus.
Head[3]  is Integer

so what it is doing is telling you some kind of type, for
an atom.

This fits into Mathematica's pattern matching/ pseudo-function
definition.  E.g. something like this..

F[x_+y__] :=    ... do something when there is a sum.   Or maybe
F[z_?PlusQ] :=... 
Fz_?IntegerQ]:=

This is sort of nice if you want to replace these big nested
if -statements  or case-statements with a set of rules, essentially.
............

Personally I don't see a big difference between

If atom(x) then dosomething(x)  else (block([r:op(x)], dosomething2(r,x)

and

block([r:op(x)],
   if  (= r false) then dosomething(x) else dosomething2 (r,x).

Since you have to test for r=false.


You could also write a program which catches the error
from op using errcatch,  but I think you will still get an
error message printed.

RJF






----- Original Message -----
From: Robert Dodier <robert.dodier at gmail.com>
Date: Sunday, May 7, 2006 11:38 am
Subject: proposal to modify op and args

> Hello,
> 
> At present the functions op and args barf on atoms.
> I propose that op and args return false when the argument is an atom.
> 
> This change is intended to obviate the need to always test whether
> the argument is an atom before calling op or args.
> 
> I looked at the commercial Macsyma documentation, but it didn't
> say what op and args do when the argument is an atom.
> 
> Comments?
> 
> Robert Dodier
> 
> PS. Here is a patch:
> --- comm.lisp   20 Apr 2006 14:31:45 -0000      1.14
> +++ comm.lisp   7 May 2006 18:18:31 -0000
> @@ -630,7 +630,7 @@
> 
> 
> ;;; These functions implement the Macsyma functions $op and 
> $operatorp. ;;; Dan Stanger
> -(defmfun $op (expr) ($part expr 0))
> +(defmfun $op (expr) (if ($atom expr) nil ($part expr 0)))
> 
> (defmfun $operatorp (expr oplist)
>   (if ($listp oplist) ($member ($op expr) oplist) (equal ($op 
> expr) oplist)))
> @@ -909,8 +909,11 @@
>   (if (null (cdr e)) (merror "Argument to `last' is empty."))
>   (car (last e)))
> 
> -(defmfun $args (e) (atomchk (setq e (format1 e)) '$args nil)
> -        (cons '(mlist) (margs e)))
> +(defmfun $args (e)
> +  (if ($atom e) nil
> +    (progn
> +      (setq e (format1 e))
> +      (cons '(mlist) (margs e)))))
> 
> (defmfun $delete n
>   (cond ((= n 2) (setq n -1))
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>