Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1994
*January
*February
*March
*April
*May
*June
*July
*October
*November
*December
*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: 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)






  • Prev by Date: Re: Alternative to Timing[10000!] benchmark
  • Next by Date: Re: Specifying rules OR "How to do complex math in Mathematica"
  • Previous by thread: Problems with Xwindows
  • Next by thread: Re: Specifying rules OR "How to do complex math in Mathematica"