RE: Should Pure Functions Require &

*To*: mathgroup at smc.vnet.net*Subject*: [mg29775] RE: Should Pure Functions Require &*From*: "Ersek, Ted R" <ErsekTR at navair.navy.mil>*Date*: Sun, 8 Jul 2001 01:00:20 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Earlier I wrote: -------------------- > I stated wondering if all would work well if pure functions didn't require > & at the end. I am thinking it would be great if a future version of > Mathematica would make the use of & optional. > > So for example we could use > Select[data, #!=0] > instead of > Select[data, #!=0&] > > > and we could use > #^2 /@expr > instead of > #^2& /@expr > > I would want to have pure functions ending with & optional rather than > prohibited for backward compatibility. Wouldn't life be better if we > didn't have to use &. Is there a reason why my suggestion would not work? > ----------------- Orestis Vantzos, asked whether Select[data, #!=0] should do what Select[data, #!=0&] does now, or what Select[data, #!0]& does now. In that case one clearly wants Select[data, #!=0&] since the other case is a pure function that always returns an empty list. ---------------- The way I would like to see it the kernel would put an & at a suitable place in the following situations. 1 A head has one or more #, #n, ##, or ##n but no &. 2 Use of expr/;test, _?test, __?test, ___?test where test has " ". 3 The right side of Set, or SetDelayed has " ". 4 The second argument of Select, MatrixQ, VectorQ has " ". 5 An argument of a functional programming construct includes #, #n, ##, or ##n but no & and a function is expected in this argument. Examples of 5 In[1]:= g = {##+1, ##+2}; Through[ g[{x,y,z}] ] This would return the same thing as if we had g = {##+1&, ##+2& } since Through expects an argument of the form p[func1, func2][x] In[2]:= g= {##+1, ##+2}; Apply[ g, {x,y,z} ] This would return the same thing as if we had g= {##+1, ##+2}& since Apply expects the first argument to be a function. In[3]:= Clear[g]; Apply[g, {x,y,z}] Out[3]= g[x,y,z] In this case (g) has no #, #n, ##, ##n so an (&) would not be assumed. I haven't found a case where the "missing" (&) could go "here" or "there" and both decisions would be useful. Also I am not aware of a use for #, #n, ##, ##n without an (&). ------------------ > Regards, > Ted Ersek > Download Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html >