Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: function definition

  • To: mathgroup at
  • Subject: RE: function definition
  • From: Chip Sample <sample at>
  • Date: Fri, 21 Oct 1994 09:52:25 CDT

Can anyone explain the principle for function definition that yields the
First define f2[x]:
in: f2[x_] := x + 2;

in: ?f2
out: Global`f2
f2[x_] := x + 2

Now re-define f2[x], and we see that the old definition has been overwritten:
in: f2[x_] := x + 3;

in: ?f2
out: Global`f2
f2[x_] := x + 3

But now define f2[y], and see that the old definition
is the one that is used by Mma!
in: f2[y_] := y + 4;
out: ?f2
f2[x_] := x + 3
f2[y_] := y + 4

Check out values of f2. They're all from the x + 3 definition:
in: f2[x]
out: 3 + x
in: f2[y]
out: 3 + y
in: f2[1]
out: 4

David Kramer                               Telephone: (717) 291-4339
Coordinator of Academic Computing          e-mail:    D_Kramer at
Franklin & Marshall College                FAX:       (717) 399-4446
Lancaster, Pennsylvania 17604-3003 USA

I call that a bug.  Clearly Mma uses the first definition it finds it its list, 
but I think the second definition should over write the first.

The only thing I could think was that if before f2[x_] was defined, x was 
declared an integer (say), and before f2[y_] was defined, y was declared a 
vector, then f2 could be used to do different things depending on the data type 
it is sent.  BUT THIS DOESN'T WORK.  So I think its a bug.


  • Prev by Date: linespacing and subscripts in graphics
  • Next by Date: Re: Plot in reverse order
  • Previous by thread: function definition
  • Next by thread: Re: function definition