MathGroup Archive 2001

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

Search the Archive

Re: RE: Should Pure Functions Require &

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29793] Re: RE: Should Pure Functions Require &
  • From: "Orestis Vantzos" <atelesforos at hotmail.com>
  • Date: Tue, 10 Jul 2001 20:25:31 -0400 (EDT)
  • Organization: National Technical University of Athens, Greece
  • References: <9iau96$15r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Building an expression with #s and applying Function to it, does not always
yield the desired effect. I distinctly remember running into serious trouble
more than once in this way...although I can't recite specific code right
now.
Orestis


"Andrzej Kozlowski" <andrzej at tuins.ac.jp> wrote in message
news:9iau96$15r$1 at smc.vnet.net...
> 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]
> >> 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: Combining Plots in a Natural Manner
  • Previous by thread: Re: RE: Should Pure Functions Require &
  • Next by thread: Drawing a Washer, Polar Plot Question