gnu-smalltalk

Smalltalk variables: why should I declare them?

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 06:11:50
问题 Basically I can use variables just by assigning something to them, for example: x := something It works fine. But in classes, if I define a new method, but I don't declare the variable, I get an "assignment to undeclared variable x", so I have to use: |x| x := something Why is this? 回答1: As Uko mentions, there are different kinds of variables in Smalltalk and that's why we need to declare them differently. Let's review all of Smalltalk variables here for the sake of completeness. Instance

Smalltalk variables: why should I declare them?

我们两清 提交于 2021-01-27 06:10:28
问题 Basically I can use variables just by assigning something to them, for example: x := something It works fine. But in classes, if I define a new method, but I don't declare the variable, I get an "assignment to undeclared variable x", so I have to use: |x| x := something Why is this? 回答1: As Uko mentions, there are different kinds of variables in Smalltalk and that's why we need to declare them differently. Let's review all of Smalltalk variables here for the sake of completeness. Instance

GNU Smalltalk: Problem with Example in Tutorial (Object creation)

≡放荡痞女 提交于 2019-12-24 01:53:24
问题 I tried to run the example of GNU Smalltalk in the documentation but ran into an issue. Object subclass: Account [ | balance | new [ | r | r := super new. r init. ^r ] init [ 'initialize account' printNl. balance := 0 ] get [ ^balance ] ] In the new method the init message is never sent to the Account method. Heres my output: st> Account new get nil st> Account new init get 'initialize account' 0 I took this example from the GNU Smalltalk Documentation. Can somebody help me spot the error? I

Why this class/instance variable is not being intialized?

扶醉桌前 提交于 2019-12-24 01:39:06
问题 I am trying to use gnu-smalltalk. In following code of a simple class with a variable, I find it is not getting initialized to the given value: Object subclass: Myclass[ |mainval| mainval := 555. getmainval [^mainval] ] gc := Myclass new. gc getmainval printNl. The object gets created without any error. But, the output is: nil while I had expected it to be 555. If I add a method to assign a value to it and call it after creating an instance of the class, it works. Where is the problem and how

Why this method's return part is not working

会有一股神秘感。 提交于 2019-12-11 15:29:19
问题 I am trying to write a method which returns a new value. Following code is modified from here: | stripChars | stripChars := [ :string :chars | str := string reject: [ :c | chars includes: c ]. str displayNl. "THIS WORKS." ^ str "THIS DOES NOT WORK." ]. newstr := stripChars value: 'She was a soul stripper. She took my heart!' value: 'aei'. newstr displayNl. Although above function creates new string and displays it, there is error in returning or receiving returned new string: $ gst make_fn

Basic Smalltalk Subclass

ⅰ亾dé卋堺 提交于 2019-12-11 06:46:09
问题 I am trying to create an extremely simple Vector class as a subclass of Array in Smalltalk. My code to create the class looks like this: Array subclass: #Vector Vector comment: 'I represent a Vector of integers' Vector class extend [ new [ | r | <category: 'instance creation'> r := super new. r init. ^r ] ] Vector extend [ init [ <category: 'initialization'> ] ] Obviously I haven't written any methods yet, but I'm just trying to get this part working first. After the class is created as above

Extending default classes (SmallInteger)

家住魔仙堡 提交于 2019-12-10 16:33:12
问题 I'm trying to extend the SmallInteger class with a new instance method "square". The idea is I wanna be able to call "5 square" and it'll return 25. Extending your own classes with instance methods is fairly simple, since you know the variable names, but I don't know the variable names in the SmallInteger class. How can I find them? I'm thinking it should look something like this, but 'thisNumber' is referencing whatever number this SmallInteger object happens to be. SmallInteger extend [

GNU Smalltalk 80 Debugger. How to debug smallcode code ? Start Debugger?

删除回忆录丶 提交于 2019-12-10 14:32:31
问题 In GNU Smalltalk 80 it is possible to write smalltalk code in your own plain text editor of personal choice. Therefore, it is very important to debug the code. First you save the file as txt File. Then you open the file from the programmers text editor with the "Tools". Here the tool - link C/programme/GNU/gnu smalltalk/gst.exe. The code is running. The debug option is not included. Under these circumstances programming is not possible. There must be a "debug" option to activate. My question

What is the correct way to test Unicode support in a Smalltalk implementation?

江枫思渺然 提交于 2019-12-08 20:38:25
问题 Given any Smalltalk flavor, how should I proceed to check if Unicode is supported? In case of not having support, how can I detect at which level is missing (VM, font, Converter, etc)? 回答1: At the VM level you can try Character codePoint: 256 or Character codePoint: 65536 (some Smalltalks may use value: instead of codePoint: still). Converter APIs differ between dialects too, but chances are that if the VM supports Unicode so will the converters. As far as I know, no Smalltalk fully supports

Smalltalk and Assertions

孤人 提交于 2019-12-07 22:53:18
问题 Tryng out some smalltalk + TDD + "good practices" I've run into a kinda ugly block: How do I do an assertion in GNU Smalltalk? I'm just looking for a simple ifFalse: [Die] kind of thing 回答1: This is the code for assert: from Squeak (which I recommend you use rather than GNU): assert: aBlock "Throw an assertion error if aBlock does not evaluates to true." aBlock value ifFalse: [AssertionFailure signal: 'Assertion failed'] 回答2: as well as self assert: [ ... some block ] works for blocks & non