["laurent couraud" , Tue, 26 Apr 2005 00:23:48 +0200]:
> In fact the final goal is to compute the number of atom in an EXPANDed form of expression.
>
> To do that I have tried:
...
You might want to try something like the following:
,----
| natoms(expr) :=
| if expr = 0
| then 0
| else if atom(expr)
| then 1
| else 0 + apply("+", maplist(natoms, args(expr))) $
^
--------------'
|
| natoms(0); ==> 0 //
| natoms(1); ==> 1 //
| natoms(a+b); ==> 2 //
| natoms(a+b+(c*2^(3+a))); ==> 6 //
`----
If you also want to count the functions as atoms (after all, "+" is an
atom, too), you should change the 0 to 1.
In most cases mapatom() is more likely to be what you want than
atom(), BTW.
HTH,
Albert.