简体   繁体   English

Smalltalk不会识别声明的临时变量

[英]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. 因此,当谈到Smalltalk时,我是一个完全初出茅庐的人,现在我正在编写一个带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. 我在使用VisualWorks识别我已经声明的临时变量时遇到了麻烦。

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. 我想将它声明为temp,instance,shared等...它特别奇怪,因为当我通过GUI运行它时,该方法可以被接受甚至读取(虽然我遇到了将变量类型转换为整数的问题)但是如果我想打印或检查具有声明的临时变量的任何行,它会说它不会识别它并且我是否要将其声明为此或那样。

The Code: 代码:

add
"adds two input fields"

| op1 op2 result |

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

result := op1 + op2.

^result

Any ideas? 有任何想法吗?

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. 另一个选择是在编译器提示时选择“create temp”,然后恢复到方法的已保存版本以除去额外的temp声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM