MathGroup Archive 2008

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

Search the Archive

Re: nesting pure functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85992] Re: nesting pure functions
  • From: "D. Grady" <D.C.Grady at gmail.com>
  • Date: Sat, 1 Mar 2008 04:37:44 -0500 (EST)
  • References: <47C7144C.4040305@berkeley.edu> <fq8r58$jeh$1@smc.vnet.net>

On Feb 29, 5:43=A0am, Ryan Olf <r... at efrus.com> wrote:
> I have figured out how to do this in one manner. What I want is this:
>
> g = Function[{x,y,f},f[x,y,#]&]
>
> Now, the question remains: is there a way to do this without naming
> variables explicitly? I would not be surprised if the answer is no.
>
> Ryan
>
> Ryan Olf wrote:
> > I'm trying to define a function, g, such that given some parameters and
> > a function as arguments, it returns a pure function:
>
> > g[x_,y_,f_Function] = Function[f[x,y,#]]
>
> > However, I need to define g itself as a pure function. I'm not sure how
> > to do this. It may be something like this:
>
> > g = Function[Function[#3[#1,#2,#?????]]]
>
> > Obviously, I want #?????? to be the argument of the of the outermost
> > Function, and #1, #2, #3 of the innermost function.
>
> > Is there a way of defining g as a pure function (of a pure function) in
> > Mathematica?
>
> > I appreciate your help,
> > Ryan

If you're asking, is there a way to write this using the #& notation,
I think the answer is no.  You'd like to write something similar to
this

(#3[#1, #2, #] &) &

or

Function[Function[#3[#1, #2, #]]]

but these are both incorrect; you intend for #1,#2,#3 to refer to the
parameters of the outer Function, but they do not.

As you pointed out, you can write

Function[{x, y, f},
 Function[f[x, y, #]]]

to get what you want.  This seems like the best solution; although
some of the variables are named, Function localizes variable names, so
you won't have to worry about name conflicts.  An alternative might be
to redefine the functions f that you're interested in using.  Right
now you call them with a sequence of three arguments: f[x,y,z].  If
you called them like this instead: f[x,y][z], then you could write

#3[#1, #2] &

which would be called like

(#3[#1, #2] & [x, y, f]) [z]

Hopefully that helps at least a little bit; good luck with your
project!

-Daniel


  • Prev by Date: RE: Creating Palettes
  • Next by Date: Re: Text does not scale with size of graphic
  • Previous by thread: Re: nesting pure functions
  • Next by thread: How do twice Working Precision in square operation