MathGroup Archive 2001

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

Search the Archive

Re: tricky question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27979] Re: tricky question
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 27 Mar 2001 01:26:15 -0500 (EST)
  • References: <99n63s$iht@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Otto,

gf1=Map[With[{x=#1},Times[x,#]&],#2]&

gf1[a,{x,y}]

{a x, a y}

gf2=Map[Function[x,Times[x,#]&][#1],#2]&

gf2[a,{x,y}]

{a x, a y}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Otto Linsuain" <linsuain+ at andrew.cmu.edu> wrote in message
news:99n63s$iht at smc.vnet.net...
>
> Dear mathgroup:
>
> this question has been teasing my brain for a while. It is about the
> apparent IMPOSSIBILITY of defining certain functions as pure functions.
>
> first take a simple case where it is POSSIBLE to define a pure function:
>
> g[x_,y_]:= Times[x,y]   will do the same as      g := Times[ #1, #2 ] &
>
> now in this case it seems to me it is IMPOSSIBLE to define a pure
function:
>
> g[x_,y_] :=  Map[ Times[ x, # ]&, y ]
>
> is NOT the same as g :=  Map[ Times[ #1, #]& , #2]&
>
> the reason these two are not the same is that in the function on the top
> line the arguments of Times would be x and the parts of y at level 1
> taken in sequence, while in the function on the botton line, the
> arguments of Times would both be just x, since #1 and # stand for the
> same.
>
> So, the question is: can  g[x_,y_] :=  Map[ Times[ x, # ]&, y ] be input
> as a pure function?
>
> Thanks in advance. Otto Linsuain.
>




  • Prev by Date: Re: Nonlinear differential equation
  • Next by Date: Re: tricky question
  • Previous by thread: Re: tricky question
  • Next by thread: Re: tricky question