|
[Date Index]
[Thread Index]
[Author Index]
Re: function definition
- To: mathgroup at christensen.cybernetics.net
- Subject: Re: function definition
- From: Richard Mercer <richard at rmercer.wright.edu>
- Date: Fri, 21 Oct 1994 12:43:09 -0400
> Can anyone explain the principle for function definition
> that yields the following:
...
> f2[x_] := x + 3
> f2[y_] := y + 4
...
> David Kramer
Sorry, David, but that's how it works!
Seriously, there are very strong advantages to maintaining multiple function
definitions for a single symbol, although not in this particular case. What Mma
does is maintain all definitions with different variables, unfortunately
y_ is considered to be different than x_. This is useful e.g. if you have
f[x_Rational]:= and f[y_Integer]:=
as then you can define different behaviors for different inputs, i.e.
"overload" the symbol f.
There are also some disadvantages, mostly that it can be very confusing for
non-experts. In my calcE package (designed to make life with Mma easier for
students, novices, and people with other things to do), I include a Define[__]
command that automatically clears all previous definitions for the symbol being
defined.
e.g. in your situation
Define[f[y] = y+4]
would result in
??f
f2[y_] := y + 4
and the standard syntax is still available when you actually want to overload a
symbol.
*********************************************************************
Richard Mercer 513-873-2191 office
Department of Mathematics and Statistics 513-873-2785 message
Wright State University 513-429-2179 fax
Dayton, OH 45435 NeXTmail welcome!
richard at rmercer.wright.edu or rmercer at desire.wright.edu
*********************************************************************
Prev by Date:
Re: Math on Sun..Help!
Next by Date:
inverse CDF
Previous by thread:
Re: function definition
Next by thread:
Re: function definition
|