3

In Calc Embedded Mode, you can define a variable with the := operator. You can then use it in an equation using the => operator and it will be automatically updated when you change the variable. See (calc) Assignments in Embedded Mode.

Example:

  • Create a new buffer containing:
x := 3

x + 2 => 9999
  • Invoke calc-embedded-activate (C-x * a)
  • Invoke calc-embedded-update-formula (C-x * u) on the bottom equation. It changes to x + 2 => 5

  • Now enter embedded mode on the top equation and change it to x := 30. The bottom one will change to x + 2 => 32.

But this doesn't work with functions. Create a buffer containing

f(x) := 2 x

f(2) => 9999

Invoke C-x * a anywhere and invoke C-x * u on the bottom equation. It changes to f(2) => f(2). Changing the top equation doesn't affect the bottom one.

Is there any way to define a function from within Calc or does it have another way of dealing with this? I know of defmath but that doesn't help in e.g. a Latex document (unless you define the function twice, likely making mistakes).

  • Could you please describe which commands you use to make your first example working? I'm unable to imitate it to get the same output. – jue Feb 18 at 10:56
  • @jue I rewrote the question, hope it's clearer now – Erik Feb 18 at 12:02
  • 1
    Your linked document states (at the bottom): Assignments to other kinds of objects can be represented by Calc, but the automatic linkage between assignments and references works only for plain variables .... So how to do the linkage for other objects? Maybe Omars answer shows this? – jue Feb 18 at 14:08
2

This probably won't be very satisfying but you can use the anonymous function syntax and call the function with the call function:

f := <x : 2 x>

call(f, 7) => 14

(Sadly f(7) doesn't work.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.