Re: Re: What does & mean?

*To*: mathgroup at smc.vnet.net*Subject*: [mg107266] Re: [mg107239] Re: What does & mean?*From*: DrMajorBob <btreat1 at austin.rr.com>*Date*: Sun, 7 Feb 2010 06:13:31 -0500 (EST)*References*: <201002041126.GAA29847@smc.vnet.net> <hkgks4$6p9$1@smc.vnet.net>*Reply-to*: drmajorbob at yahoo.com

I think things like Sin@#& are functions (more or less), whereas things like f in f[x_Integer]:=x^2 f[x_Real]:=x are pattern-matching rule sets. Neither way of defining things gives mathematical functions, in general, since both can carry the same input to different outputs on subsequent calls. That is, f in i=0; f = (i++;i #)& is not a function mathematically, and neither is f[x_]:={AbsoluteTime[],x^2} Hence, to my mind, trying to label one of the two forms a "true function" and the other one "not a true function" is fruitless. Bobby On Sat, 06 Feb 2010 02:25:21 -0600, Richard Fateman <fateman at cs.berkeley.edu> wrote: > Leonid Shifrin wrote: >> Richard, >> >> >> Leonid's confusion relates to the pseudo-definition of a >> "function" by pattern matching using >> >> fn[arg_]:= ....... >> >> and the definition of a true function by >> >> fn= Function[{arg}], ......] or the brief but obscure ...#..& >> notation... >> fn = ....#.... & >> >> There is a widely held but technically bogus equivalence in the >> minds >> of Mathematica users, so Leonid's not alone.. >> >> In particular, there is no pattern matching going on in the fn= >> ... case, and the SetAttribute[fn, HoldAll] has no effect >> whatsoever. >> >> >> Can it be that you are not aware of the syntax of pure functions in >> Mathematica which allows to set Hold-attributes (Function[vars,body, >> HoldAll] for instance)? But more to the point. > In fact, I was unaware of this feature, which I suspect was added to the > language sometime after version 2 or 3. I was also unaware > of the possibility of using ## for SlotSequence. > > This does not change the fact that SetAttribute[fn,HoldAll] has no > effect on fn. > > I was unaware of your book (available online free! Thanks!) which looks > rather nice. But there is > generally a trade-off between being "friendly" and being "accurate". > Thus using the term "function" > is tricky. You can use a bunch of rules to define what is conceptually > a mathematical function ... > a pure mapping from input to output.. or you can talk about a > "programming language function" which > is (loosely speaking) any procedure, perhaps with side effect, that > returns a value.. > or you can talk about a Mathematica Function, or something (....)&, > which is a syntactic/ evaluation > convention that by-passes pattern matching. > > Much of the discussion (not really in response to the original posting > -- he just wanted to know how to > get help on the "&" symbol, I think) .. has concentrated on the > evaluation semantics in Mathematica, > which gets in the way of many programmers. How many times do you > evaluate a symbol? > If you type x=x+1, you see it is about 255 times. This causes problems > that eventually get solved > by trying to block evaluation, sometimes, and then in some controlled > way, Releasing it. > Using Functions is a way to help do this, though it can be seen more > cleanly in "functional programming" > languages. I do not know of any (non-Mathematica) functional language > with this > "evaluate forever" > semantics, though variants of it are common in rule-based transformation > languages. > > >> If you'd care to look at the relevant sections of my book you'd see >> that I clearly state that pure and pattern-defined functions are very >> different and used for different purposes (In fact, I had a couple of >> examples similar to yours to illustrate this). > I looked and yes you do. > > ... snip.... > >> fn1 = >> Function[{arg}, >> Switch[Head[Unevaluated[arg]], Print, "You want to print", Times, >> "You want to multiply", _, "I have no idea what you want to do"], >> HoldAll]; >> > .... > >> To my mind, this explanation should have left no room for further >> ambiguities, > .. much better example... > > And thanks for mentioning your book, which I had not seen before. It > seems to have good insights. (I admit to not > reading its predecessors except the one by Maeder). > > RJF > >> > -- DrMajorBob at yahoo.com

**References**:**Re: What does & mean?***From:*Bill Rowe <readnews@sbcglobal.net>

**Re: Could you prove this proposition:the i-th prime gap p[i+1]-p[i]<=i**

**Re: Could you prove this proposition:the i-th prime gap**

**Re: Re: What does & mean?**

**Re: Re: Re: What does & mean?**