smalltalk

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 [

How to manage 2d array in Smalltalk?

两盒软妹~` 提交于 2019-12-10 16:11:28
问题 I have a list of point and have to do erosion/dilation operations. I need a kind of 2d-array but can't find how to do in VisualWorks (I know there is a Array2d class in Squeak, but I must use VW). 回答1: Use simply a generic way: array of arrays: (Array new: xSize) at: 1 put: ((Array new: ySize) at: 1 put: aValue; at: 2 put: aValue; ...); at: 2 put: ((Array new: ySize) at: 1 put: aValue; at: 2 put: aValue; ...); ... 回答2: Many Smalltalk implementation will have some kind of Matrix class,

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

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

Pharo Smalltalk and mySql

戏子无情 提交于 2019-12-10 14:31:53
问题 I am looking for someone who knows how to interface Pharo Smalltalk and mySql. I just want to do the basic things like "select * from names" and then read the result into Pharo. Does anyone know anything about this? If you have a screen video that would be super and I would buy you a beer. 回答1: Check out DBXTalk. Mariano Peck gave a presentation on it at ESUG 2011. Here's the abstract and video. I'll take a Blue Moon, please ;-) 回答2: And what do I get? ;) Now, really, let us know if you have

Smalltalk superclass vs metaclass?

梦想与她 提交于 2019-12-10 13:05:59
问题 I new to OOP, but with a "procedural" background. I'm currently trying to get my head around OOP via GNU Smalltalk and Lovejoy's "Smalltalk: Getting The Message". I'm confused as to the the heck the metaclass and Metaclass class are, vs superclass. I can see the inheritance flow of superclass -> class -> subclass; but I don't see how/where metaclass fits in. TIA... 回答1: There is an excellent description in the free online book Pharo by Example, Chapter 13 (Classes and metaclasses). The things

The use of “>>” in Pharo/Smalltalk

核能气质少年 提交于 2019-12-10 10:25:23
问题 I am implementing futures in Pharo. I came across this website http://onsmalltalk.com/smalltalk-concurrency-playing-with-futures. I am following this example and trying to replicate it on Pharo. However, I get to this point the last step and I have no idea what ">>" means: This symbol is not also included as part of Smalltalk syntax in http://rigaux.org/language-study/syntax-across-languages-per-language/Smalltalk.html. BlockClosure>>future ^ SFuture new value: self fixTemps I can see future

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects changes of the variable?

一世执手 提交于 2019-12-10 09:33:05
问题 I have an object with a variable containing a String. I have a window containing a LabelMorph/TextMorph (or some other Morph that displays Text?). How do i bind the LabelMorph/TextMorph to the variable, so that the label updates when the String in the variable changes? classic Smalltalk-80 dependent/change/update mechanism? Pharo Announcement framework? something different?? How would i do this? Which Morph should i use? 回答1: Depends on what you want to achieve. You might want to take a look

What is the difference between a Morph in Morphic and a NSView in Cocoa?

余生长醉 提交于 2019-12-10 03:26:28
问题 I'd like to know about the things that make Morphic special. 回答1: Morphic is much more than NSView or any other graphics class that simply allow the re-implementation of a limited set of features. Morphic is an extremely malleable UI construction kit. Some design ideas behind Morphic makes this intention clear: A comprehensive hierarchy of 2D coordinate systems is included. They are not restricted to Cartesian or linear. Useful nonlinear coordinate systems include polar, logarithmic