Actually this is an area in which macsyma could be
extended orthogonally (that is, without breaking any code
already existing).
allow for patterns like
fact[0]:=1;
fact[n_PositiveInteger]:= n*fact[n-1];
fact[q]:=Gamma[q+1];
where we have used Mathematica's pattern matching. And
in the example similar to Stavros',
foo[ [a_, b__] ] := cons (foo[a],foo[b])
foo [ [] ] : []
note that a_ is a pattern variable and b__ that is b _ _
is a variable that matches a span. So foo[[1,2,3,4,5]] works.
The details have to be worked out carefully, or alternatively,
can be slavishly copied from an existing system such as
the pattern matchers written in Norvig's book on AI programming,
or Mathematica, or the similar matcher written for Reduce at
one time. Or taken from MockMMa, for that matter.
RJF
Stavros Macrakis wrote:
>>How this one could be connect with pattern-matching task.
>
>
> Sorry if my far-fetched analogy confused things rather than clarifying
> them. It's just the idea of defining different cases without an
> explicit conditional. The analogy would have been much better if you
> could say things like
>
> foo[cons(a,b)]:= ...
> or declare(e,even) foo[e]:=...
>
> but you can't -- you must use explicit pattern-matching declarations.
>
>
>>(C8) fact[0]:=0;
>
>
> This should have been fact[0]:0; -- note the colon instead of
> colon-equals ;-).
>
> -s
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima