Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9852
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Distinquishing #'s in nested pure functions |
| Date | 2012-04-28 09:31 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jngde2$p4$1@smc.vnet.net> (permalink) |
| References | <201204260933.FAA05752@smc.vnet.net> <jndtj1$jit$1@smc.vnet.net> |
Hi,
> Is there a way to distinguish the #'s in nested pure functions?
>
> As a simple example:
>
> f[x_, y_] := x - y
>
> Select[{1, 2, 3}, (f[#, #]& /@ {-1, -2, -3}) == {3, 4, 5}&]
>
> I want the 1st # to correspond with the outer& (the equal)
> and the 2nd # with the inner& (the map)
> The answer in this example should by {2}
> (of course, the statement as written above does not do the job)
>
> Can Mathematica distinguish these #'s?
it often does the right thing, but of course there are ambiguities which
just can't be resolved. What you'd usually do is to use pure functions
with named arguments, which will resolve these ambiguities. You probably
should note that the notation with # and & is just a shortcut for
Function. Look up the documentation of Function for more details. Here
is an example:
Select[{1, 2, 3},
Function[outerarg,
Function[innerarg, f[outerarg, innerarg]] /@ {-1, -2, -3} == {3,
4, 5}]]
That's of course somewhat more verbose, but you can of course also mix
those with the shortcut notation, e.g.:
Select[{1, 2, 3},
Function[outerarg, f[outerarg, #] & /@ {-1, -2, -3} == {3, 4, 5}]]
hth,
albert
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Distinquishing #'s in nested pure functions "Dave Snead" <dsnead6@charter.net> - 2012-04-27 10:49 +0000 Re: Distinquishing #'s in nested pure functions David Reiss <dbreiss@gmail.com> - 2012-04-28 09:30 +0000 Re: Distinquishing #'s in nested pure functions A Retey <awnl@gmx-topmail.de> - 2012-04-28 09:31 +0000
csiph-web