Behavior of Opional command
- To: mathgroup at yoda.physics.unc.edu (Mathgroup)
- Subject: Behavior of Opional command
- From: Scott Herod <sherod at newton.colorado.edu>
- Date: Sat, 2 Jul 1994 22:18:45 -0600 (MDT)
I have discovered a rather annoying property of the Optional command
and was hoping someone could comment. I noticed that the problem occurs
in the X11 notebook interface and also occurs on my MAC in version 1.2.
Below is a demonstration using version 2.2.
First I will create a file called test.m:
f[x_, y_:temp] := Block[{},
If[y == temp, y = Pi];
Print[x,y]]
Then run this as follows:
********************************************************************
Mathematica 2.2 for SPARC
Copyright 1988-93 Wolfram Research, Inc.
-- Terminal graphics initialized --
In[1]:= <<test.m
In[2]:= f[a]
aPi
In[3]:= <<test.m
In[4]:= ??f
Global`f
f[x_, y_:temp] := Block[{}, If[y == temp, y = Pi]; Print[x, y]]
f[x_, y_:Pi] := Block[{}, If[y == temp, y = Pi]; Print[x, y]]
In[4]:= bye
********************************************************************
In[2] runs correctly, but when I reload test.m it has been changed.
The variable y is now supposed to default to Pi. Admittedly, in
this case running f[a] again will have the same effect as it did
on Input line 2 because the correct version of f appears first.
However, if I had changed the file test.m, I would still be running
the old version.
Comments? Obviously there is an easy way around the problem. One
can simply put a line Clear[f]; in the file which defines f, but it
does seem strange that this problem occurs.
Scott A. Herod
(sherod at newton.colorado.edu)