smalltalk

How does the organisation of classes in categories and packages work in different versions of Pharo?

故事扮演 提交于 2020-02-01 04:05:08
问题 Can someone explain how the organisation of classes in Pharo works in different versions of Pharo? All Classes are part of the Smalltalk global (have always been, seem to stay like this?) Classes can have a Category, but thats only a kind of tag? (has always been, seems to stay like this? But the categories are somehow mapped to packages sometimes ?) There are different kinds of Packages in different Versions of Pharo MCPackages representing Monticello Packages PackageInfo RPackage (Pharo 1.4

method that accepts a block and the block accepts an argument

落花浮王杯 提交于 2020-01-25 15:51:20
问题 How can I send a block and its argument to a method ? so the method receive the block and the block receives the argument and I run the block in the method iteslf... 回答1: Just pass the block and its argument to the method as separate arguments. Then send #value: to the block to pass the argument to the block. E.g. methodTaking: aBlock and: anArgument aBlock value: anArgument. ... 回答2: For an example have a look at the sort: method of OrderedCollection (you'll find the block evaluated finally

method that accepts a block and the block accepts an argument

淺唱寂寞╮ 提交于 2020-01-25 15:50:57
问题 How can I send a block and its argument to a method ? so the method receive the block and the block receives the argument and I run the block in the method iteslf... 回答1: Just pass the block and its argument to the method as separate arguments. Then send #value: to the block to pass the argument to the block. E.g. methodTaking: aBlock and: anArgument aBlock value: anArgument. ... 回答2: For an example have a look at the sort: method of OrderedCollection (you'll find the block evaluated finally

Pharo Smalltalk - Message forwarding, is it possible to intercept a message and redirect it to another Object (instance)?

99封情书 提交于 2020-01-24 18:24:07
问题 Pharo Smalltalk - Message forwarding, is it possible to intercept a message and redirect it to another Object (instance)? In Objective-C there's forwardInvocation: that gets called right before an exception is thrown so you can do something about the message you received and know nothing about. Is there something similar in Smalltalk do I can redirect a message to a delegate? 回答1: Smalltalk has doesNotUnderstand: aMessage which is sent to the receiver in place of an otherwise undefined method

Double dispatch in Pharo

杀马特。学长 韩版系。学妹 提交于 2020-01-22 19:45:08
问题 Could someone please explain the process of double dispatch in Pharo 4.0 with Smalltalk? I am new to Smalltalk and am having difficulty grasping the concept, since it is implemented very differently in Java as compared to Smalltalk. It will be very helpful if some one could explain it with an example. 回答1: Essentially the idea is that you have method: #addInteger: which knows how to add integers, #addFloat: which knows how to add floats, and so on… Now in Integer class you define + as: +

What gives Smalltalk the ability to do image persistence, and why can't languages like Ruby/Python serialize themselves?

Deadly 提交于 2020-01-22 10:35:08
问题 In smalltalk, you're able to save the state of the world into an image file. I assume this has to do with Smalltalk's ability to "serialize" itself -- that is, objects can produce their own source code. 1) Is this an accurate understanding? 2) What is the challenge in adding this ability to modern languages (non-lisp, obviously)? 3) Is "serialization" the right word? What's the correct jargon? 回答1: It's much simpler than "serializing". A Smalltalk image is simply a snapshot of the object

Invoking shell commands from Squeak or Pharo

▼魔方 西西 提交于 2020-01-21 01:41:50
问题 How can you invoke shell commands from Squeak and Pharo? Do these environments have anything in them like the system() function in certain unix languages to run external shell commands, or the backticks (can't make them here do to the editor, but what you get when you push the key left of "1" and above "TAB") to capture the output of commands? 回答1: In Squeak you can use CommandShell, but I don't know what (if anything) is available for Pharo at this time. 回答2: I think you can use the package

Pharo SubscriptOutOfBounds:5 error

坚强是说给别人听的谎言 提交于 2020-01-16 16:29:07
问题 I have a Pharo extension that adds promises to Pharo Smalltalk. I then use the promise extension to do a bank transfer with the following bank application.An account contacts the bank in order to transfer money to another account. This code fails with the error SubscriptOutOfBounds:5 . I looked at Recursive method in pharo produces #SubscriptOutOfBounds:8. It talks about array bounds but I have no clue where I could be using arrays in my implementation unless the stack does.The debugger says

Capture string in regex replacement

a 夏天 提交于 2020-01-14 07:32:28
问题 From what I can gather from the Pharo documentation on regex, I can define a regular expression object such as: re := '(foo|re)bar' asRegex And I can replace the matched regex with a string via this: re copy: 'foobar blah rebar' replacingMatchesWith: 'meh' Which will result in: `'meh blah meh'. So far, so good. But I want to replace the 'bar' and leave the prefix alone. Therefore, I need a variable to handle the captured parenthetical: re copy: 'foobar blah rebar' replacingMatchesWith: '%1meh

Capture string in regex replacement

三世轮回 提交于 2020-01-14 07:31:09
问题 From what I can gather from the Pharo documentation on regex, I can define a regular expression object such as: re := '(foo|re)bar' asRegex And I can replace the matched regex with a string via this: re copy: 'foobar blah rebar' replacingMatchesWith: 'meh' Which will result in: `'meh blah meh'. So far, so good. But I want to replace the 'bar' and leave the prefix alone. Therefore, I need a variable to handle the captured parenthetical: re copy: 'foobar blah rebar' replacingMatchesWith: '%1meh