Overloading mathematica built in functions
- To: mathgroup at smc.vnet.net
- Subject: [mg5716] Overloading mathematica built in functions
- From: seanross at worldnet.att.net
- Date: Sat, 11 Jan 1997 14:29:10 -0500
- Sender: owner-wri-mathgroup at wolfram.com
I want to add a capability to the Sum function. If I give it a single argument that is a 1-D list, I want it to sum the list. For example: In[1]:= w={1,1,1,3}; Sum[w] Out[1]:= 5 The function sum[f_List]:=Sum[f[[i]],{i,1,Length[f]}]; performs this function, However Unprotect[Sum]; Sum[f_List]:=Sum[f[[i]],{i,1,Length[f]}]; Protect[Sum]; does not work. Does anyone know why? I am guessing it has something to do with the attribute HoldAll on the built-in function Sum. Is there a way to overload a function so that the attributes are different for different argument lists? Thanks