pharo

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

Creating a key value message in Smalltalk/Pharo that take blocks as argument

北慕城南 提交于 2019-12-11 04:03:57
问题 I have a scenario where a class holds two instance variables that are mutually exclusive. That is only one can be instantiated at a time. To be precise, I have a Promise class (trying to add promises to Pharo) and it holds promiseError and promiseValue instance variables. I then want to implement the method "then: catch:". This method should work as follows: promiseObject := [10/0] promiseValue. promiseObject then : [ : result | Transcript crShow : result ] catch : [ : failure | Transcript

Subclassing Stream

对着背影说爱祢 提交于 2019-12-11 03:48:26
问题 I am interested in creating my own Stream subclass and I'm wondering what methods I should override (deploying on pharo and Gemstone). I have a collection with various types of things in it and I want to be able to stream over a subset of it, containing elements of a class. I don't want to copy the collection or use a collect: block because the collection may be large. My first use case is something like this: stream := self mailBox streamOf: QTurnMessage. stream size > 1 ifTrue: [ ^ stream

Debugging in Pharo 5 headless mode

别来无恙 提交于 2019-12-11 03:34:26
问题 I'm running pharo 5 (seaside) in headless mode, with RFB: ./pharo -vm-display-null -vm-sound-null /app/pharo5/Pharo5.0.image --no-quit Locally works well (Ubuntu 14 with XFCE). In DigitalOcean (Ubuntu 14 without GUI) it works until the debugger is activated: then it closes. I can connect via VNC with no problem, but when I execute a Halt or an error it triggers the debugger, it leaves ... some clue of the problem? 回答1: This sounds like a case where remote debugging might be a reasonable

How can I change the position of a morph in smalltalk? 2D Grid

瘦欲@ 提交于 2019-12-10 20:49:53
问题 Hello I have trouble changing the position of some morphs. While it is possible to move them from the Inspector with: self position: 50 @ 50 for example. I wrote a function wich should set the position of of a 2d collection of morphs. Cell is a subclass of simple switchmorph. And the class owning this function is a subclass of bordered morph. setCells | xPos yPos row col | xPos := 0. yPos := 0. row := 1. col := 1. cells := OrderedCollection new. cols timesRepeat: [ cells add:

Pharo Goferit results in MessageNotUnderstood: FileList

眉间皱痕 提交于 2019-12-10 19:13:30
问题 I just installed Pharo5.0 and attempting to go through "Pharo by Example". When I get to the BouncingAtomsMorph I apply the "Gofer it" fetch provided by MartinW at Error Unknown variable:BouncingAtomsMorph openInWorld please correct or cancel This results in a MessageNotUnderstood: FileList class>>registerFileReader: AnimatedImageMorph class initialize [:cl | cl registerFileReader: self ] BlockClosure cull: SystemDicdtionary(Dictionary) at:ifPresent: AnimatedImageMorph class initialize

Idiomatic way to detect sequences of x times same object in an Array in Smalltalk?

最后都变了- 提交于 2019-12-10 15:16:49
问题 What's the idiomatic way to detect sequences of x times the same object (or an object with a specific matching parameter) in an OrderedCollection or Array? E.g. does the Array contain 10 times the number 5 in a row? 回答1: Getting the sequences of repeating objects is as simple as: ({ 1. 1. 2. 2. 2. 5. 5. 3. 9. 9. 9. 9. } as: RunArray) runs => #(2 3 2 1 4) If you want to test if there is a run satisfying specific constraints, you can do something like the following: meetsConstraint := false. ({

Indices of a substring in Smalltalk

我与影子孤独终老i 提交于 2019-12-10 14:43:21
问题 It seems Smalltalk implementations misses an algorithm which return all the indices of a substring in a String. The most similar ones returns only one index of an element, for example : firstIndexesOf:in: , findSubstring:, findAnySubstring: variants. There are implementations in Ruby but the first one relies on a Ruby hack, the second one does not work ignoring overlapping Strings and the last one uses an Enumerator class which I don't know how to translate to Smalltalk. I wonder if this