MathGroup Archive 2000

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

Search the Archive

Re: best solution?


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


  • Prev by Date: Re: Command to get a notebook's directory?
  • Next by Date: Re: Q: Axes on top of graphics primitives?
  • Previous by thread: Re: best solution?
  • Next by thread: Re: @@@ for Version 3??