pharo

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

How can I get all the methods in a Protocol?

一笑奈何 提交于 2020-01-12 15:09:08
问题 How can I get a collection of all the (class) methods in a given protocol in smalltalk/squeak/pharo? I'm trying to collect the values returned by a group of methods. I don't want to have to store the methods in an instance or class variable. So I though I could add them to a protocol and in this way to "mark" them. Thanks. 回答1: In Pharo, the method you're looking for is ClassDescription>>allMethodsInCategory: : | selectors | selectors := MyClass allMethodsInCategory: #'protocol name'. To find

How can I get all the methods in a Protocol?

青春壹個敷衍的年華 提交于 2020-01-12 15:07:21
问题 How can I get a collection of all the (class) methods in a given protocol in smalltalk/squeak/pharo? I'm trying to collect the values returned by a group of methods. I don't want to have to store the methods in an instance or class variable. So I though I could add them to a protocol and in this way to "mark" them. Thanks. 回答1: In Pharo, the method you're looking for is ClassDescription>>allMethodsInCategory: : | selectors | selectors := MyClass allMethodsInCategory: #'protocol name'. To find

Recursive method in pharo produces #SubscriptOutOfBounds:8

北战南征 提交于 2020-01-06 06:02:51
问题 I created a class in Pharo known as BinarySearchTreean i implemented a method called BinarySearchTree>>PreOrder and BinarySearchTree>>index Preorder: myArray index: position (myArray at: position) ~= -1 ifTrue: [ Transcript show: (myArray at: position). self Preorder: myArray index: (position * 2). self Preorder: myArray index: (position * 2) + 1. ]. I then provided this array #(90 60 95 50) with index 1 to make a PreOrder search in my binary tree which i implemented using arrays but it does

Is it possible to write shell command within Pharo smalltalk?

萝らか妹 提交于 2020-01-01 12:01:07
问题 Like in other programming language, is there a way of running linux shell command in Pharo smalltalk or a simple script ? I would like to have my Pharo image running a script that should be able to automate a tasks and return it to some value. I looked at almost all the documentation around and I couldn't find anything related. Maybe It does not allow such functionality. 回答1: Pharo does allow the OS interaction. The best way, in my eyes, is to use OSProcess (as MartinW already suggested).

Generating all combinations from collections in Smalltalk

好久不见. 提交于 2019-12-24 02:33:24
问题 I've seen this problem resolved for C# and other languages but not for Smalltalk. I have 3 collections, for example: a := #(3 4 5). b := #(4 1 2). c := #(5 2 3). and I need to make all possible combinations, i. e.: #(3 4 5) #(3 4 2) #(3 4 3) #(3 1 5) #(3 1 2) #(3 1 3) #(3 2 5) #(3 2 2) #(3 2 3) #(4 4 5) ... I have seen in Squeak and Pharo there is combinations:atATimeDo: but I don't get how to use it for this case. This is not homework. Any help? 回答1: here is the code from Smalltalk/X's class

Pharo Smalltalk: Reading from TextMorph

拟墨画扇 提交于 2019-12-23 19:08:19
问题 In Smalltalk using Pharo, I'm creating an application that reads the user input and does X. So far I've managed to make a TextMorph that a user could enter a value into, but I'm unsure of how to read from TextMorphs and then do something with the value. Any ideas? Thanks 回答1: Well, you can simply send text to your morph and get it's contents. So you could have a button and when button is pressed you do something with contents: input := TextMorph new. button := SimpleButtonMorph new target:

How can I remove diacritics (umlauts) from a String?

谁说我不能喝 提交于 2019-12-23 15:11:14
问题 How can I convert a string, such as Příliš žluťoučký kůň úpěl ďábelské ódy. into Prilis zlutoucky kun upel dabelske ody. ? The source string is in Unicode, so in principle it should be possible to use normalization/decomposition to separate the umlaut. Unfortunately I didn't see any library in Pharo (maybe Zinc hidden somewhere?) that would support either stripping umlauts or decomposition. 回答1: You can try Diacriticals package Installation Metacello new smalltalkhubUser: 'Pharo' project:

For loop for array in Pharo Smalltalk

时光怂恿深爱的人放手 提交于 2019-12-23 12:29:51
问题 I'm trying to make an array with random numbers (just 0 or 1), but when I run it, it just prints this: End of statement list encountered -> This is my code: GenList | lista | lista := Array new: 31. 1 to: 30 do: [ :i | lista at: i put: 2 atRandom - 1] ^lista What can I do? 回答1: Some interesting things to consider: 1. The method selector doesn't start with a lowercase letter It is a tradition for selectors to start with a lowercase letter. In this sense, genLista would be more correct than