Re: Style for function calls?
- To: mathgroup at smc.vnet.net
- Subject: [mg97346] Re: Style for function calls?
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Wed, 11 Mar 2009 04:25:25 -0500 (EST)
- References: <goqpg6$lsb$1@smc.vnet.net>
For constructions where you re-use data several times @ can be shorter and sometimes faster than standard function call: myList = RandomReal[{0, 10}, {10000, 2}]; finding the coordinate with the largest value at the end: Cases[#, {_, x_} /; x == Max[#[[All, 2]]]] & @ ( myList^2) // Timing {5.156, {{50.8683, 99.998}}} Cases[ myList^2, {_, x_} /; x == Max[(myList^2)[[All, 2]]]] // Timing Out[32]= {10.875, {{50.8683, 99.998}}} [BTW: try this without the square and the difference becomes very small] Cheers -- Sjoerd On Mar 6, 11:13 am, Erik Max Francis <m... at alcyone.com> wrote: > I'm fairly new to Mathematica and have a style question rather than a > functionality question. > > I'm aware with the operator forms for Postfix (//), Prefix (@), and > Infix (~), and I've found the // operator useful for piping long results > through the ...Form functions, or N, or the like, as a quick > afterthought while typing a lot of stuff. > > What are the analogous situations where @ or ~ are used? Looking at > random notebooks around I've from time to time seen them used but there > doesn't seem to be any rhyme or reason; it's not clear when > stylistically they'd be useful, as opposed to the // operator, which I > can see and use myself. > > -- > Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/ > San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis > To understand is to forgive, even oneself. > -- Alexander Chase