Re: Should Pure Functions Require &
- To: mathgroup at smc.vnet.net
- Subject: [mg29731] Re: [mg29723] Should Pure Functions Require &
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Thu, 5 Jul 2001 06:07:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
It depends what you mean. There are certainly lots of cases where & is needed. E.g. how would you distinguish: In[1]:= Array[f,{3}] Out[1]= {f[1],f[2],f[3]} In[2]:= Array[f&,{3}] Out[2]= {f,f,f} In[3]:= Array[(f&)&,{3}] Out[3]= {f&,f&,f&} Here is another example: In[1]:= Composition[#,#&]&[f][2] Out[1]= f[2] In[2]:= Composition[#,#]&[f][2] Out[2]= f[f[2]] (There are more important examples, I made these up in a couple of minutes). So making & optional would mean that Mathematica would have to choose an interpretation in all the ambiguous cases and the user would then have to work out what went wrong by himself and insert the needed &. Sounds like bad interface to me. Andrzej Kozlowski on 01.7.5 7:43 AM, Ersek, Ted R at ErsekTR at navair.navy.mil 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? > > Regards, > Ted Ersek > Download Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html > > > -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ http://sigma.tuins.ac.jp/~andrzej/