smalltalk

Smalltalk dictionary as calculator

匆匆过客 提交于 2019-12-11 04:20:53
问题 I'm working on a homework assignment that asks us to create a type of Units class that can keep track of units and perform basic arithmetic on them. The problem description has this bit, which I don't completely understand: Probably the easiest way to keep track of the units is to give Units a dictionary that maps symbols to integers. If you are dividing by a unit then it has a negative value in the dictionary. You add two Units together by adding the value together for each symbol in the

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

Smalltalk write a Sorted Collection to a file

廉价感情. 提交于 2019-12-11 03:46:48
问题 let's say i have a SortedCollection called whitepages , each record containing a Customer , with values name and number . I want to create a function which would write them to a file in such way name1 number1 name2 number2 I have to admit Im completely stuck here. Could anyone help? 回答1: Ok, so I hope you know how to write to file. And as you noticed that you have sorted collection I suppose that Customer s are ordered in the way you want. Then what you can do is: (whitepages collect: [

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 to create a window in smalltalk

落爺英雄遲暮 提交于 2019-12-11 03:26:10
问题 I am trying to make a window show up, but i keep getting a message not understood error. The snippet: Window new label: 'Hello'; open 回答1: Ok, for a game like that you want to use a custom control. You start by creating a subclass of View for your game and override the displayOn: method to display the view. You can add the view to the UIPainter canvas using a ViewHolder. Set the View: property to be the name of a method that returns your custom view. To intercept mouse clicks, you'll need to

Why can't I pass an UninterpretedBytes to a void* thru DLL/C-Connect?

孤者浪人 提交于 2019-12-11 01:09:09
问题 I'd like to pass an UninterpretedBytes to an external library, say something like this MyLibrary>>foo: buf len: len <C: int foo(void *buf,unsigned int len)> MyApplication>>test buffer := UninterpretedBytes new: 4. ^MyLibrary new foo: buffer len: buffer size. But this fails in CPointerType>>coerceForArgument:anObject . I know that I could use buffer gcCopyToHeap but I don't want to. I want to handle an object in Smalltalk memory with Smalltalk 1-based address and no extra copy nor any other

Can one create a standalone method/function (without any class)

浪子不回头ぞ 提交于 2019-12-10 21:31:57
问题 I am trying to understand smalltalk. Is it possible to have a standalone method/function, which is not part of any particular class, and which can be called later: amethod ['amethod called' printNl]. amethod. Above code gives following error: simpleclass.st:1: expected Eval, Namespace or class definition How can I use Eval or Namespace as being suggested by error message? I tried following but none work: Eval amethod [... amethod Eval [... Eval amethod Eval[... "!" Eval [... works but I want

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:

Performance differences between Swazoo and Komanche?

泪湿孤枕 提交于 2019-12-10 16:55:59
问题 I'd like to know what the performance differences between Swazoo and Komanche in general and for Seaside are. Especially why and in what situations I should prefer the one over the other? 回答1: The only major differences between the two are: Swazoo is licensed under the LGPL, while Komanche is licensed under the MIT license. Some people are very uncomfortable using LGPL software in Smalltalk, since the definition of whether something is a library in a Smalltalk is extremely ambiguous. If you