Re: Re: What does & mean?
- To: mathgroup at smc.vnet.net
- Subject: [mg107263] Re: [mg107229] Re: What does & mean?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 7 Feb 2010 06:12:56 -0500 (EST)
- References: <201002041126.GAA29847@smc.vnet.net> <hkgks4$6p9$1@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
> f[x_]:=Hello[x]
> g=Hello[#]&
> f[1,2,3] returns Hello[1]
> g[1,2,3] returns g[1,2,3]
No...
f[1,2,3] returns f[1,2,3]
g[1,2,3] returns Hello[1]
But, if we define:
Clear[f, g]
f[x___] := Hello[x]
g = Hello[##] &;
...now we get the same results from both, for any arguments:
f[1, 2, 3]
Hello[1, 2, 3]
g[1, 2, 3]
Hello[1, 2, 3]
g == f
Hello[##1] & == f
Bobby
On Sat, 06 Feb 2010 02:23:32 -0600, Richard Fateman
<fateman at cs.berkeley.edu> wrote:
> Unfortunately, Leonid's explanation is wrong, and while some of
> the discussion is correct and may clarify the meaning of "&",
> some of it is slightly and more-than-slightly wrong.
>
> Leonid's confusion relates to the pseudo-definition of a "function" by
> pattern matching using
>
> fn[arg_]:= .......
>
> and the definition of a true function by
>
> fn= Function[{arg}], ......] or the brief but obscure ...#..&
> notation...
> fn = ....#.... &
>
> There is a widely held but technically bogus equivalence in the minds
> of Mathematica users, so Leonid's not alone..
>
> In particular, there is no pattern matching going on in the fn= ...
> case, and the SetAttribute[fn, HoldAll] has no effect whatsoever.
>
> (aside: Programming with "pure functions" in Mathematica follows from
> its heritage in Lisp, where Function[{x,y},x+y] or #1+#2& more
> briefly, would be written as (lambda(x y)(+ x y)). Further use of pure
> functions can be viewed in the literature on Lisp. )
>
> To see that the two forms are different most simply, try
>
> f[x_]:=Hello[x]
> g=Hello[#]&
>
> f[1] is the same as g[1], namely Hello[1] but
>
> f[1,2,3] returns Hello[1]
> g[1,2,3] returns g[1,2,3]
>
--
DrMajorBob at yahoo.com
- References:
- Re: What does & mean?
- From: Bill Rowe <readnews@sbcglobal.net>
- Re: What does & mean?