Re: best solution?
- To: mathgroup at smc.vnet.net
- Subject: [mg22967] Re: [mg22899] best solution?
- From: Hartmut Wolf <hwolf at debis.com>
- Date: Fri, 7 Apr 2000 02:54:49 -0400 (EDT)
- Organization: debis Systemhaus
- References: <200004050241.WAA01036@smc.vnet.net> <8ch9iv$95n@smc.vnet.net> <Pine.GSO.4.21.0004061746200.23405-100000@flip.eecs.umich.edu>
- Sender: owner-wri-mathgroup at wolfram.com
Daniel Reeves schrieb:
>
> > (If you don't have version 4, then replace @@@ by the alternative
> > input form:
> >
> > In[5]:= Hold[F[x] @@@ k] // InputForm
> > Out[5]//InputForm=
> > Hold[Apply[F[x], k, {1}]]
> > )
>
> Or you can actually replace the
> @@@
> with
> @@#&/@
>
> Ugly, but I do it that way so it's easy to switch over to the ver4 way
> sometime in the near future when I can feel sure that my code won't ever
> need to run on ver3 anymore.
>
Hallo Daniel,
nice ideom! Yet you have to be cautious when applying it:
In[1]:= k = {{a1, b1}, {a2, b2}, {a3, b3}}
In[2]:= f @@@ k
Out[2]= {f[a1, b1], f[a2, b2], f[a3, b3]}
In[3]:= g /@ f @@@ k
Out[3]= {g[f[a1, b1]], g[f[a2, b2]], g[f[a3, b3]]}
In[4]:= f @@#&/@ k
Out[4]= {f[a1, b1], f[a2, b2], f[a3, b3]}
In[5]:= g /@ f @@#&/@ k
Out[5]= {f[g[a1], g[b1]], f[g[a2], g[b2]], f[g[a3], g[b3]]}
So @@#&/@ is not a "read macro" to be textually substituted by @@@ when
transiting from version 3 to 4 (or vice versa). Of course the correct
expression for In[5] would be:
In[6]:= g /@ (f @@ # &) /@ k
Out[6]= {g[f[a1, b1]], g[f[a2, b2]], g[f[a3, b3]]}
The full form Apply[f, k, {1}] however remains correct in any case for
both versions.
If you want to have a true syntactical equivalent substition for @@@ you
may have one; define
In[16]:= aaa = ( Function[{e}, #1 @@ e ] /@ #2 &)
In[17]:= f ~aaa~ k
Out[17]= {f[a1, b1], f[a2, b2], f[a3, b3]}
In[18]:= g /@ f ~aaa~ k
Out[18]= {g[f[a1, b1]], g[f[a2, b2]], g[f[a3, b3]]}
Kind regards, Hartmut
- Follow-Ups:
- Re: @@@ for Version 3??
- From: Hartmut Wolf <hwolf@debis.com>
- Re: @@@ for Version 3??
- References:
- best solution?
- From: "Peter Weijnitz" <peter.weijnitz@perimed.se>
- best solution?