MathGroup Archive 2001

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

Search the Archive

Re: slot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28050] Re: slot
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 29 Mar 2001 03:24:15 -0500 (EST)
  • References: <99s682$pbr@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bob,
One reason is convenience: in the middle of some progam we can use
Times[#1,#2,#3]& (or Times[##]& or Function[{x,y,z}, x y z])
 without needing to make a definition like those you give for g2 and g3.

There is also some speed advantage in avoiding having to look up a
definition.

g2[x_,y_,z_]:=Times[x,y,z]
g3:=Times[#1,#2,#3]&

Do[g2[2,3,4],{10000}]//Timing

        {0.88 Second,Null}

Do[g3[2,3,4],{10000}]//Timing

        {0.66 Second,Null}

Do[Function[{x,y,z},x *y *z][2,3,4],{10000}]//Timing

        {0.77 Second,Null}

Do[Times[#1,#2,#3]&[2,3,4],{10000}]//Timing

        {0.44 Second,Null}

Do[Times[##]&[2,3,4],{10000}]//Timing

        {0.55 Second,Null}
--
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

"Robert-Lewis HYDE" <bobhyde at wanadoo.fr> wrote in message
news:99s682$pbr at smc.vnet.net...
> hello,
> For those who never dared ask.
>
> g2[x_,y_,z_]:=Times[x,y,z]
>
> g3:=Times[#1,#2,#3]&
>
> g2[1,2,3]===g3[1,2,3]
>
> True
>
> Why or when should we go in for the g3 format ?
>
> It confuses us ordinary folks (me) who just want to go forth and multiply.
>
> Bob
>
>




  • Prev by Date: Unconventional Max[] behavior
  • Next by Date: Re: Exponential fit question.
  • Previous by thread: slot
  • Next by thread: RE: Re: slot