Re: Destructuring arguments to pure functions?
- To: mathgroup at smc.vnet.net
- Subject: [mg95787] Re: Destructuring arguments to pure functions?
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Tue, 27 Jan 2009 06:59:19 -0500 (EST)
On 1/26/09 at 5:03 AM, dreeves at gmail.com (dreeves) wrote: >I'm curious what you all think of this idea: >Unprotect[Integer]; >1[x_] := x[[1]] >2[x_] := x[[2]] >3[x_] := x[[3]] >4[x_] := x[[4]] >5[x_] := x[[5]] >6[x_] := x[[6]] >7[x_] := x[[7]] >8[x_] := x[[8]] >9[x_] := x[[9]] >Protect[Integer]; Redefining built-in objects often leads to unpredictable behavior elsewhere in Mathematica. And doing this to more fundamental objects tends to dramatically increase the probability of something like this happening. >and then >1@# + 2@# & /@ testList >It seems to be very slow in the current version of Mathematica but >it seems like a concise/elegant way to avoid the clunky yet >oft-typed # [[n]] (ie, replacing it with n@# or n[#]). There are better ways to avoid the usage of # than adding definitions to Integer. In this particular example, you are adding sequential pairs. This can be done without # as: Plus@@@Partition[testList,2,1]