Search code examples
smalltalkvisualworks

Smalltalk won't recognize declared temporary variables


So I'm a complete fledgling when it comes to Smalltalk and right now I'm writing a very simple app with a GUI. All this app does is add two operands together from two input fields and displays the sum in a third, read-only input field.

I am having trouble with VisualWorks recognizing temporary variables that I have already declared.

I try to highlight any line with a declared temporary variable, and it will say such variable has not been declared; do I want to declare it as temp, instance, shared, etc... It's especially strange because the method can be accepted and even read through when I run it by the GUI,(although I am having a problem typecasting the variables as integers) but if I want to print or inspect any line with a declared temporary variable, it will say that it doesn't recognize it as such and do I want to declare it as this or that.

The Code:

add
"adds two input fields"

| op1 op2 result |

op1 := #InputOperand1 value asInteger.
op2 := #InputOperand2 value asInteger.

result := op1 + op2.

^result

Any ideas?


Solution

  • The problem is that only the text you've selected is compiled and evaluated. If you are only selecting a single line, then the variable declarations aren't included in the compiled code. If you select the whole method body for evaluation (not including the method signature), it should work fine. Another option is to just choose "create temp" when the compiler prompts, and then revert to the saved version of the method to get rid of the extra temp declaration.