1

If I have a named expression, how can I convert that to a function? Here's an example:

argx: 2*x;
f(x) := argx;

I'd like then this to be equivalent to:

f(x) := 2*x

But I know somehow I have to force "unquoting" or something of argx

mpettis
  • 3,222
  • 4
  • 28
  • 35

1 Answers1

4

There are a couple of ways to do that.

(1) define(f(x), argx);

(2) f(x) := ''argx;

Approach (2) only works when you're in the top-level interpreter, since quote-quote '' (i.e., two single quotes) is only applied when an expression is first parsed. Approach (1) works within functions, while (2) does not, so (1) is a little more general. However, since function definitions are global, there isn't much motivation to define named functions within functions.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48