MathGroup Archive 2001

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

Search the Archive

Re: Should Pure Functions Require &

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29781] Re: Should Pure Functions Require &
  • From: "Orestis Vantzos" <atelesforos at hotmail.com>
  • Date: Sun, 8 Jul 2001 20:35:56 -0400 (EDT)
  • Organization: National Technical University of Athens, Greece
  • References: <9i8qaq$r05$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

My objection is based on the fact that there is no true "declaring
mechanism" for functions, in the sense that you never really declare what
arguments a function is supposed to handle. True, there is the pattern you
provide with each SetDelayed evaluation, but that is not definite, since a
future SetDelayed could relate to a completely different pattern. To sum up,
Mathematica can never be sure that a certain function expects a true
Function as its n-th argument, and therefore it can not automatically decide
that Select[....,3+#] really means Select[....,3+#&].
Orestis
"Ersek, Ted R" <ErsekTR at navair.navy.mil> wrote in message
news:9i8qaq$r05$1 at smc.vnet.net...
> 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
> >
>




  • Prev by Date: Re: icon to Evaluate Notebook?
  • Next by Date: Re: RE: Should Pure Functions Require &
  • Previous by thread: RE: Should Pure Functions Require &
  • Next by thread: Re: RE: Should Pure Functions Require &