3

I have a simple local variable in Forth:

: subtraction { a b } a b - ;

I would like to assign the output of

a b -

to another variable, say c.

Is this possible?

1 Answer 1

3

TO works for both VALUEs and local variables, so:

: subtraction { a b | c -- } a b - to c ;
Sign up to request clarification or add additional context in comments.

2 Comments

Do you have to have the | c — part? Can c just be a variable within the local variable. I’m thinking of it as being inside a function and declaring a new variable like in Java.
Yes, you do. This declares a and b to be local variables that take their values off the stack, and c to be an uninitialized local variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.