MathGroup Archive 1999

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

Search the Archive

Re: "f[x_]:= 2 x" vs. "f = 2 #&"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16548] Re: "f[x_]:= 2 x" vs. "f = 2 #&"
  • From: "Dale Horton" <daleh>
  • Date: Tue, 16 Mar 1999 04:00:21 -0500
  • Organization: Wolfram Research, Inc.
  • References: <7c59pl$7nq@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

99.99% of the time they work the same. The choice is really personal
preference.

Here's an example that is different.

In[1]:=
f[x_] := 2 x
g := Function[x, 2 x]

f will only match expressions with 1 argument. g will match any expression.

In[2]:=
f[1, 2]

Out[2]=
f[1, 2]

In[3]:=
g[1, 2]

Out[3]=
2

The extra argument is ignored.

There are other differences, but most are very subtle.

-Dale

Kevin Jaffe wrote in message <7c59pl$7nq at smc.vnet.net>...
>What significant differences exist among the following
>three ways to define a function f:
>
>  f[x_]:= 2 x
>
>
>  f = Function[x, 2 x]
>
>
>  f = 2 #&
>
>Are there situations where one form is better than the others?
>
>Thanks,
>
>KJ
>
>
>
>Get your FREE Email at http://mailcity.lycos.com
>Get your PERSONALIZED START PAGE at http://personal.lycos.com
>.
>




  • Prev by Date: Re: Abs Symbol
  • Next by Date: Re: "Solve[x==Erf[x], x]"
  • Previous by thread: Re: "f[x_]:= 2 x" vs. "f = 2 #&"
  • Next by thread: What is the greatest known Fibonacci number?