MathGroup Archive 1998

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

Search the Archive

Re: expressions as arguments to functions.



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.



  • Prev by Date: Re: Re: RenderAll crash
  • Next by Date: Re: ListPlot?
  • Prev by thread: expressions as arguments to functions.
  • Next by thread: Return inside Do, For and While