Re: := vs. =
- To: mathgroup at smc.vnet.net
- Subject: [mg8907] Re: [mg8858] := vs. =
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Thu, 2 Oct 1997 22:56:59 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Frank Roescher <froesche at dekalb.dc.peachnet.edu>
[mg8858] := vs. =
> 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?
The difference is simply that
f[x_] := rhs causes f[x_] := rhs to be stored and outputs Null
f[x_] = rhs causes f[x_] := value(rhs) to be stored and outputs
value(value(rhs)).
Why one or the other?
f1[x_] = Integrate[1/(1+t^3), {t,0,y}]
to get the integration done once when the rule is stored rather
than every time it is used.
f2[x_] := Expand[x]
to store f2[x_] := Expand[x] rather than f2[x_] := x, which would
give f2[(a+b)^2] -> (a+b)^2 instead of a^2+2ab+b^2
Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester, UK