MathGroup Archive 2011

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

Search the Archive

Re: Mapping to Create Nested Loops

  • To: mathgroup at
  • Subject: [mg119430] Re: Mapping to Create Nested Loops
  • From: Leonid Shifrin <lshifr at>
  • Date: Thu, 2 Jun 2011 19:12:42 -0400 (EDT)

Hi Szabolcs,

AFAIK, it is safe, as long as inner pure anonymous  function is totally
contained in the outer, being
passed as an argument. Here is one relevant mathgroup thread:

Regarding pure functions with named arguments, I try to avoid them because
the functional abstraction
is generally leaky in Mathematica. I pointed this out here:

and also discussed here:

You may also look at the bottom of this post:

for a really short but instructive example illustrating the problem.


2011/6/2 Szabolcs Horv=E1t <szhorvat at>

> On 2011.06.01. 13:27, Bob Hanlon wrote:
> > GatherBy[myArray, #[[3]]&]
> >
> > GatherBy[#, #[[3]]&]&  /@ myListOfArrays
> >
> >
> Is this kind of use of nested functions with # guaranteed to be safe
> (let's disregard readability concerns for now)?
> It appears that # indeed is always the argument of the innermost
> function, but I couldn't find this stated in the docs.  Instead, it's
> suggested in the docs (page for Slot) to use named arguments with nested
> functions (but those aren't without name-conflict / localization issues
> either)

  • Prev by Date: Re: Portfolio Optimization
  • Next by Date: Re: Workbench - Recommendation?
  • Previous by thread: Re: Mapping to Create Nested Loops
  • Next by thread: Re: Mapping to Create Nested Loops