smalltalk

How can I parse character in a File in Squeak4.1?

ⅰ亾dé卋堺 提交于 2019-12-12 06:13:34
问题 friend, suppose I have a file test.txt, the content of file is "1+2*3", if the fomular directly expressed in Squeak's Workspace, print it will result 9 , What I want to get is 7 then I read the file content 1+2*3 from a file. code like this and it works well ReadFrom "read the equation from ./formular.txt" | fileContents | fileContents := FileStream readOnlyFileNamed: 'test.txt' do: [:f | f contents ]. ^fileContents. but how can I store the 5 caracters of string "1+2*3" into a collection ,

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

Keyword messages in smalltalk (Beginner)(Pharo)

五迷三道 提交于 2019-12-11 13:38:36
问题 I am trying to create a keyword message style method, but I can't figure out how to access the Receiver from inside the method. I am sure this is simple, however I can't find the answer anywhere. What I am trying to implement is redundant, but I would still like to know how it works. subst: i1 by: i2 ^ self copyReplaceAll: i1 with: i2. It would be called in the workspace as follows: string1 := 'Lemon'. string2 := 'm'. string3 := 'ss'. string1 subst: string2 by: string3. Error msg:

How to display the contents of a dictionary in a morph in smalltalk?

荒凉一梦 提交于 2019-12-11 12:48:39
问题 Because I don't seem to be able to find some predefined Morph that can display the contents of a Dictionary , I decided I'd better stop looking and wanted to create my own Morph . I found a nice description how to start with some nice example code to get me started, but quite soon I got to the problem that I don't seem to manage to draw text or anything like that on a canvas. I created a class Morph subclass: #DictionaryView instanceVariableNames: 'dictionary' classVariableNames: ''

Aconcagua measure library - storing BaseUnits

折月煮酒 提交于 2019-12-11 09:08:07
问题 What is the best practice to store base units? Let's say I want to have a mile unit. So, I implement Number>>#miles , but what is the implementation? The problem is that: (2 * (BaseUnit named: 'mile')) ~= (2 * (BaseUnit named: 'mile')) , so it seems the mile base unit must be a singleton. So I'd have something like: Number>>#miles ^ self * Mile uniqueInstance Am I on the right track, or can you think of a better way? 回答1: Yes the mile base unit must be a singleton, you can take a look at the

Find references to string/symbol/method

妖精的绣舞 提交于 2019-12-11 08:46:08
问题 This relates to the Dolphin variant of Smalltalk. I'm digging around in the image to try and figure this out but haven't find the correct method invocation yet and I'm hoping someone might be able to help shortcut this process. What I'm trying to do is to find all methods (either within the entire system or, preferably, just within a single class) which refer to a given string, symbol, or method. I've found the #references family of methods in SmalltalkSystem but have not had luck figuring

What is the difference between = and == in Pharo Smalltalk?

不羁岁月 提交于 2019-12-11 08:01:29
问题 What is the difference between = and == in Pharo Smalltalk? What are they named, one isEqual and the other? = ~= equality / inequality (deep) == ~~ equality / inequality (shallow) 回答1: Yes, == is identity and it uses a primitive to compare if pointers point to the same address (i.e. same object). = is equality, meaning that two objects are equal, although they may be 2 different objects. By default = uses == , but it can be reimplemented. Also when you reimplement = it's advised to also

PetitParser evaluator not working properly

夙愿已清 提交于 2019-12-11 07:29:55
问题 when I try running this code on pharo, my answers are somewhat off. I try evaluating 1-2+3 but for some reason, it does 1- (2+3) and I do not understand why this is so. Thanks for your time. number := #digit asParser plus token trim ==> [ :token | token inputValue asNumber ]. term := PPUnresolvedParser new. prod := PPUnresolvedParser new. term2 := PPUnresolvedParser new. prod2 := PPUnresolvedParser new. prim := PPUnresolvedParser new. term def: (prod , $+ asParser trim , term ==> [ :nodes |

What object to hold a large amount of text in?

无人久伴 提交于 2019-12-11 06:51:44
问题 I am planning a Seaside app to hold text, a single instance which may be up to, say, 5Mb. What kind of object is best for this? I would also like to do some iterations over this text. Thanks, Vince Edit: Thanks for your replies thus far. The file is a CSV file that takes ~40 minutes to generate from a legacy finance system, so it must be pre-generated and stored. Each line is a customer record and I need to pull each one out and use the values as and when the customer logs in. Customer access

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