MathGroup Archive 2010

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

Search the Archive

Re: := vs = in some function definitions


On Oct 20, 10:06 am, Sam Takoy <sam.ta... 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 ext=
ra
> 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

Multiplying vector Append[Range[1, 49], x] with IdentityMatrix[50] is
useless cause you simply obtain Append[Range[1, 49], x].
Apart from this, considering your definition as a contrived example,
the = is in this case more efficient than := cause IdentityMatrix[50]
is calculated only once and so the multiplication and I see no
convenience in using :=


  • Prev by Date: Re: := vs = in some function definitions
  • 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