RE: My posting about Optional command
- To: mathgroup at yoda.physics.unc.edu (Mathgroup)
- Subject: RE: My posting about Optional command
- From: Scott Herod <sherod at newton.colorado.edu>
- Date: Sat, 2 Jul 1994 23:12:02 -0600 (MDT)
I think I figured out the problem I was having with the Optional command. Briefly, it was the fact that I was assigning an undefined as the optional argument. This variable was then receiving all of the definitions. Use of the Trace command details this. In[3]:= ??f Global`f f[x_, y_:temp] := Block[{}, If[y == temp, y = Pi]; Print[x, y]] In[3]:= y Out[3]= y In[4]:= temp Out[4]= Pi In[5]:= Trace[f[b]] bPi Out[5]= {f[b], Block[{}, If[temp == temp, temp = Pi]; Print[b, temp]], > {If[temp == temp, temp = Pi]; Print[b, temp], > {If[temp == temp, temp = Pi], {{temp, Pi}, {temp, Pi}, Pi == Pi, True}, > temp = Pi, Pi}, {{temp, Pi}, Print[b, Pi], Null}, Null}, Null} In[6]:= bye As you can see, temp (not y) is being set to Pi. The next time the function f is loaded, temp has a value assigned to it. Sorry to make two post out of this. Scott Herod (sherod at newton.colorado.edu)