Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Re: := vs. =

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8915] Re: [mg8858] := vs. =
  • From: seanross at worldnet.att.net
  • Date: Thu, 2 Oct 1997 22:57:10 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Frank Roescher wrote:
> 
> When I define a function on Mathematica, I use f[x_]=xxxxx, without
> using a colon.  It seems to work just fine.  Is there a risk in leaving
> out the colon?  Thanks.
> 
> Frank

No "risk" at all.  It depends on what you want to do.  = means immediate
assignment using current values for all the symbols.  := means delayed
assignment, ie. don't evaluate the function until I ask for it.

If all you are doing is one-line algebraic type functions, then it
probably doesn't matter.  When you want function subroutine type
constructs with private symbols, such as 

f[x_,...]:=Module[{a,b,c,...}, body;Return[answer]];

Then it makes a big difference and usually the delayed assignment is
what you want.  When you use an immediate assignment, then mathematica
stores an internal symbolic representation of your function.  With a
delayed assignment, it evaluates the function once it is given numerical
values, so an internal symbolic version never exists.  

It also makes a difference if the function contains rules,
transformations, other defined functions, dynamic lists etc. etc. 
Imagine a function which reads in a data file from disk and performs a
fourier transform on it, then does some statistical analysis.  Using
immediate assignment would force mathematica to try and symbolically
evaluate a fourier transform on a data list of unknown size and come up
with some representation for it.  Delayed assignment allows it to wait
until you give it the file name so it can numerically evaluate the
fourier transform.

As your programming needs become more advanced, you will probably find a
need for the distinctions between := and =.


  • Prev by Date: Re: FindRoot
  • Next by Date: debugging
  • Previous by thread: Re: FindRoot
  • Next by thread: Re: := vs. =