       Re: := vs = in some function definitions

• To: mathgroup at smc.vnet.net
• Subject: [mg113291] Re: := vs = in some function definitions
• From: Albert Retey <awnl at gmx-topmail.de>
• Date: Fri, 22 Oct 2010 01:36:12 -0400 (EDT)
• References: <i9m7u7\$j41\$1@smc.vnet.net>

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.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?

I think there have been many good answers to your question already, but
if you are interested in what is going on I think it worth to mention
that a function definition is nothing but a definition of a global
replacement rule in Mathematica. And of course you can look at these
rules and that might be interesting if you try to understand what Set
and SetDelayed actually do (so no more guessing is needed).

Have a look at the DownValues (or OwnValues) to see what happens in the
two cases:

f[x_] = IdentityMatrix.Append[Range[1, 49], x];
DownValues[f]
g[x_] := IdentityMatrix.Append[Range[1, 49], x];
DownValues[g]

it is instructive to also evaluate this:

x = 1
f[x_] = IdentityMatrix.Append[Range[1, 49], x];
DownValues[f]

hth,

albert

• Prev by Date: Re: palettes that would not move
• Next by Date: Re: Table of tables
• Previous by thread: Re: := vs = in some function definitions
• Next by thread: Re: := vs = in some function definitions