Re: RE: Should Pure Functions Require &

• To: mathgroup at smc.vnet.net
• Subject: [mg29777] Re: [mg29775] RE: Should Pure Functions Require &
• From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
• Date: Sun, 8 Jul 2001 20:35:53 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```I think in order to do what you would like you would have to add to
Mathematica quite a lot of rules for deciding where to insert & in more
complicated cases, e.g.

Select[Range[100],Function[x,x>#]]&/@Range[10];

The point is that even if Mathematica was able to correctly decide where to
insert the & and even if Mathematica programmers could remember all the
rules which you stated in your message (and which, by the way, I can't
understand because I do not understand what you mean when you write
>where test has " "
and so on), implementing your idea would encourage people to write even more
unreadable code than they do at present. I find the idea of trying to
understand such code quite dreadful. Thus I would strongly oppose your idea
on the grounds of wanting to preserve my sanity.

By the way, I there is a reasonable use for # without & ( well, sort of).
Here is a somewhat artificial example.
This makes a list of expressions {#,#^2,...} which can be manipulated just
as any algebraic expressions.

l = Table[#^i, {i, 1, 100}];

This converts them to pure functions:

In[2]:=
v=Function/@l;

For example:

In[3]:=
v[[15]][3]
Out[3]=
14348907

--
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/~andrzej/

on 01.7.8 2:00 PM, Ersek, Ted R at ErsekTR at navair.navy.mil wrote:

> 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]
>> Select[data, #!=0&]
>>
>>
>> and we could use
>> #^2 /@expr
>> #^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,
> 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