Re: Functional programming?

*To*: mathgroup at smc.vnet.net*Subject*: [mg91975] Re: [mg91945] Functional programming?*From*: Murray Eisenberg <murray at math.umass.edu>*Date*: Mon, 15 Sep 2008 03:43:20 -0400 (EDT)*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst*References*: <200809130957.FAA03536@smc.vnet.net>*Reply-to*: murray at math.umass.edu

Here's my favorite very simple example, for instructional purposes, that employs some functional programming -- hardly "real-world", I suspect, in the sense you mean. It's not "pure" functional programming, in that some arguments are explicitly mentioned in definitions, but it does includes some functional programming. newtonStep::usage="newtonStep[{c, x0}] performs one step of Hero's method to find a better estimate x1 for the square-root of c given estimate x0; the result has the form {c, x1}"; newton::usage="newton[c, epsilon, x0] applies Hero's method to find the square-root of c with |error| < epsilon, given the initial estimate x0."; newtonStep[{c_, x_}] := {c,Mean[{x,c/x}]} newton[target_,tolerance_,initialGuess_]:= Last@NestWhile[newtonStep, {target,initialGuess}, Abs[Last@#1-Last@#2]>=tolerance&,2] newton[2, 10.^-13, 1.] // NumberForm[#, 12] & 1.41421356237 I leave to explicit-looping advocates the exercise of coding the same thing in a Do or other explicit loop. Note that I consider array-oriented programming, such as originated in APL and as derivatively and partially incorporated into Mathematica, as a somewhat different programming paradigm from functional programming. AES wrote: > I suggest it might be instructive if some of the functional programming > proponents on this group could provide us DO-looping old timers with a > brief summary or tutorial as to what is really meant by, or involved in, > "functional programming"? > > --- especially as this concept might relate to building programs to do > calculations involving multi-stage real-world engineering or technical > problems > > --- and especially as it might relate to programs that are going to be > developed in an evolutionary process and that in the end, rather than > being built into some long-term library, are maybe only going to be run > or executed a few times before the person involved (e.g., an engineer, > or scientist, or other real-world individual, not a "programmer") moves > on to some other totally different task or assignment. > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305

**References**:**Functional programming?***From:*AES <siegman@stanford.edu>