Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: := vs = in some function definitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113259] Re: := vs = in some function definitions
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Thu, 21 Oct 2010 07:01:09 -0400 (EDT)

Sam,

One particular case to use := would be if you want to keep your matrix
packed (that is, if you expect x to always be an integer,
or real for a real-valued matrix). This may have an impact on performance.
Adding symbolic <x> will necessarily unpack the matrix, so all your
subsequent operations (which do not automatically pack it back when x
becomes a number) will be with an unpacked matrix and can be slower.

You also must be sure that x does not have a global value by the time you
make a definition - generally Set can produce bugs of this sort, and they
are hard to track. If you use Set, I'd wrap Module[{x},...] around the
definition.

Regards,
Leonid


On Wed, Oct 20, 2010 at 1:06 AM, Sam Takoy <sam.takoy at yahoo.com> wrote:

> Hi,
>
> Have read everything I could find regarding delayed assignment, I'm
> still not quite sure when to use which.
>
> For example, in the definition
>
> f[x_] = IdentityMatrix[50].Append[Range[1, 49], x];
>
> could there ever be any reason to use :=   ?
>
> It seems that using   :=  will condemn the function to repeated extra
> work every time its called. So could there be a situation where the use
> of ":=" for the above function is recommended?
>
> Many thanks in advance,
>
> Sam
>
>


  • Prev by Date: Re: := vs = in some function definitions
  • Next by Date: Re: Locator Manipulate
  • Previous by thread: Re: := vs = in some function definitions
  • Next by thread: Re: := vs = in some function definitions