Re: expressions as arguments to functions.
- To: mathgroup@smc.vnet.net
- Subject: [mg12614] Re: [mg12559] expressions as arguments to functions.
- From: Bob Hanlon <BobHanlon@aol.com>
- Date: Mon, 25 May 1998 14:25:23 -0400
For a different approach try: testfunction[f_, a_, sym_Symbol:x] := f /. sym :> a testfunction[f[x], 3] f[3] testfunction[x^2, 3] 9 testfunction[3*x^2 + x*y + 7*y, 3, y] 3*x^2 + 3*x + 21 Bob Hanlon In a message dated 5/23/98 11:31:35 PM, seanross@worldnet.att.net wrote: >I forgot the magic combination of Hold, Release and Evaluate to get a >user defined function to accept expressions as arguments like most >built-in functions do. For example: > >I want to define > >testfunction[f_,a_]:=f[a] > >and have testfunction[x^2,3] return 9 rather than x^2[3]. > > > >Can someone remind me how to do it. If you wouldn't mind, explain to me >why it works. I still don't understand all the holds and evaluations >of arguments. Note that I don't want to have to enter in a pure >function construct as an argument.