variable number of arguments



The way to do this "correctly" is to use the mma pattern matcher and
evaluator
(which I also wrote..., and whose source is in the same directory.).

Note that there are many many other options besides f[x_]:=   ...
and f[x__]:= ...,  like

f[{a_,b_},c_+d__]:=    ...

 

The expressiveness of the mathematica language, to the extent that it
exceeds (say)
C, Fortran, ...,  is mostly in the pattern matching, not in the parsing of
a+b*c.

If you want to do a partial implementation, restricted mostly to
arithmetic-like expressions and simple functions, that's ok.  but if you are
nudging the partial implementation into more and more aspects of pattern
matching, I suggest you consider using pattern matching from the start, and
use Maxima to replace the simplifier
and algorithms, instead of using the Maxima evaluator/ function model.


RJF


> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of John Lapeyre
> Sent: Sunday, October 05, 2008 9:16 PM
> To: Maxima at math.utexas.edu
> Subject: variable number of arguments
> 
> Hi,
> 
> I rewrote the Mathematica translator in lisp and used
> Richard Fateman's parser. The whole thing works pretty well
> and is very fast. But, there are a number of more or less
> difficult details, even with relatively common constructions.
> 
> Here is one. I wonder if someone has an idea.
> 
> Mma implements a variable number of arguments as part of its
> pattern system,  like this.
>   
>   f[x__] := g[x];
> 
> If I do f[1,2,3] , I get in, effect g[1,2,3].
> 
> In macsyma, I can do this
>   f([x]) := apply(g,x)
>  
> to get the same result. Translating this for slightly
> more complicated code seems difficult. I wonder if there is
> a way to do this (maybe with macros ?) without using
> 'apply'. I am looking for something like 'splice'.
> 
> Thanks,
> John
> 
> 
> 
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>