New to Pharo; a bunch of questions.
I have a course at my university where I have to use Pharo for assignments. I have a few questions about the Pharo environment. 1. Is it possible to turn off Pharo's "'" and "()" matching? If so how? 2. Is it possible to use system fonts in Pharo? If so how? 3. Is it possible to prevent Pharo from screwing up indenting of my class definitions when I save?(It keeps replacing leading spaces with a tab). If so how? 4. How can I create a Pharo package from Playground using code? 5. How can I create a Pharo class from Playground using code? I suspect 4 and 5 are possible because Pharo allows dynamic insertion/removal of methods from classes using the class method dictionary and runtime compile. Thanks ahead of time! -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi and welcome! 2016-10-01 18:29 GMT+02:00 CodeDmitry <dimamakhnin@gmail.com>:
I have a course at my university where I have to use Pharo for assignments.
I have a few questions about the Pharo environment.
1. Is it possible to turn off Pharo's "'" and "()" matching? If so how?
In Settings Browser (World menu -> System -> Settings) Code Browser - > Code Completion -> Smart Characters
2. Is it possible to use system fonts in Pharo? If so how?
Again, Sytem Browser Appearance -> Standard Fonts -> Select an entry , this will open the font chooser. In the font chooser presse "update" and it will load the available system fonts.
3. Is it possible to prevent Pharo from screwing up indenting of my class definitions when I save?(It keeps replacing leading spaces with a tab). If so how?
No, I don't think so. It just prints the class definition, not based on your input but just the definition. What is the problem with this, why do you need spaces instead of tabs?
4. How can I create a Pharo package from Playground using code?
5. How can I create a Pharo class from Playground using code?
The code for creating a class is just the same as the class definition you see in the system browser Object subclass: #NameOfYourNewClass instanceVariableNames: '' classVariableNames: '' package: '' You can evaluate this code in a playground and it will create this class
I suspect 4 and 5 are possible because Pharo allows dynamic insertion/removal of methods from classes using the class method dictionary and runtime compile.
Thanks ahead of time!
Feel free to ask more questions :) And take a look at the pharo books -> http://files.pharo.org/books/
-- View this message in context: http://forum.world.st/New-to- Pharo-a-bunch-of-questions-tp4917701.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
I don't like tabs because I always have my code have 4 space indenting, so when I add 2 spaces to Pharo's spacing to 4, it (1) when I backspace 3 times, it effectively removes the 2 spaces and then the tab, then when I press backspace for the fourth time, it puts me back on last line rather than removing the fourth "character", and it throws me off a bit. (2) it removes the spaces I added, and puts tabs instead. People deal with complexity through patterns, and allowing them to choose what patterns work for them greatly reduces astonishment and improves code quality since code behaves the way the programmer expects rather than how the environment thinks the programmer should expect it to behave. I can get used to it but it's always going to bother me and throw me off in other environments when I do(context switching). Thanks so much for that comment about classes. I realize now that that expression not only to just be a simple expression (Object subclass: x1 instanceVariableNames: x2 classVariableNames: x3 package: x4), something I haven't realized; but it also creates the package if the package does not exist. I can now write Pharo-environment setup scripts that I can run in playground to set up the whole pharo environment(which I can give to others instead of image/sources/changes files. -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917703.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Couple more answers. On Sat, Oct 01, 2016 at 09:29:51AM -0700, CodeDmitry wrote:
3. Is it possible to prevent Pharo from screwing up indenting of my class definitions when I save?(It keeps replacing leading spaces with a tab). If so how?
Yes and no, you can specify indent string in "Code Browsing > BlueInk Pretty Printing", however when you press "tab" it will still insert tab. This setting only applies to autoformatting. (ctrl+shift+f). As for class definition, the implementation is in ClassDescription>>definition, where you can see things like aStream cr; tab; nextPutAll: 'instanceVariableNames: '; store: self instanceVariablesString. so you would need to change >aStream cr; tab< into >aStream cr; nextPutAll: 'your indentation spaces'< Or you can do that en masse... newCode := (ClassDescription>>#definition) sourceCode copyReplaceAll: 'tab;' with: ''' '';'. ClassDescription compile: newCode. And add that code into a StartupScript or somewhere.
4. How can I create a Pharo package from Playground using code?
RPackage organizer createPackageNamed: 'Hello'.
I suspect 4 and 5 are possible because Pharo allows dynamic insertion/removal of methods from classes using the class method dictionary and runtime compile.
As a bonus in answer to "3." you can also see how to dynamically compile a method. :) Peter
Thanks Peter! I admit I couldnt really dynamically add methods to a class at runtime since I was doing it as follows: ([ (LOCell class) methodDict at: #mouseAction put: ((LOCell class) compile: mouseAction: a ^ mouseAction := a ). ] value). Which caused constant harassment by Pharo until I typed: (LOCell class) removeAllKeys. or (LOCell class) removeKey: #mouseAction. I'll try your method in a bit to see if it works better. -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917706.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Ok I got the proof of concept down, but I can't get it all to run at once since Pharo realizes that the class does not exist(at the time of running), even though it will exist by the time it gets to that line. Is there a way to modify the following Transcript code make the following code run "at once". Ignoring the fact that classes are not created at time of writing? ([ SimpleSwitchMorph subclass: #LOCell instanceVariableNames: 'mouseAction' classVariableNames: '' package: 'PBE-LightsOut' ] value). ([ BorderedMorph subclass: #LOGame instanceVariableNames: 'cells' classVariableNames: '' package: 'PBE-LightsOut' ] value). ([ LOCell compile: 'mouseAction: a', (String cr), ' ^ mouseAction := a'. ] value). ([ LOCell compile: 'mouseUp: e', (String cr), ' mouseAction value' ] value). ([ LOCell compile: 'initialize', (String cr), ' super initialize.', (String cr), ' self label: ''''.', (String cr), ' self borderWidth: 2.', (String cr), ' bounds := (0@0) corner: (16@16).', (String cr), ' offColor := Color paleYellow.', (String cr), ' onColor := Color paleBlue darker.', (String cr), ' self useSquareCorners.', (String cr), ' self turnOff.' ] value). ([ LOGame compile: 'cellsPerSide', (String cr), ' ^10' ] value). ([ LOGame compile: 'toggleNeighboursOfCellAt: i at: j', (String cr), ' (i > 1) ifTrue: [', (String cr), ' (cells at: i - 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (i < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i + 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j > 1) ifTrue: [', (String cr), ' (cells at: i at: j - 1) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i at: j + 1) toggleState.', (String cr), ' ].' ] value). ([ LOGame compile: 'newCellAt: i at: j', (String cr), ' | c origin | ', (String cr), (String cr), ' c := LOCell new.', (String cr), ' origin := self innerBounds origin.', (String cr), (String cr), ' self addMorph: c.', (String cr), ' ', (String cr), ' c position: ([', (String cr), ' | x_index y_index c_width c_height |', (String cr), (String cr), ' x_index := i - 1.', (String cr), ' y_index := j - 1.', (String cr), ' c_width := c width.', (String cr), ' c_height := c height.', (String cr), ' ', (String cr), ' (x_index * c_width)@(y_index * c_height) + origin', (String cr), ' ] value).', (String cr), (String cr), ' c mouseAction: [', (String cr), ' self toggleNeighboursOfCellAt: i at: j.', (String cr), ' ].', (String cr), ' ^ c.', (String cr) ] value). ([ LOGame compile: 'initialize', (String cr), ' | sampleCell width height n |', (String cr), (String cr), ' super initialize.', (String cr), ' n := self cellsPerSide.', (String cr), (String cr), ' sampleCell := LOCell new.', (String cr), ' width := sampleCell width.', (String cr), ' height := sampleCell height.', (String cr), (String cr), ' self bounds: ', (String cr), ' ((5@5) extent:', (String cr), ' (width * n)@(height * n) + ', (String cr), ' (2 * (self borderWidth))).', (String cr), (String cr), ' cells := Matrix new: n tabulate: [:i :j |', (String cr), ' self newCellAt: i at: j.', (String cr), ' ].' ] value). -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917707.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
You see Pharo as a file syntax too. You did all that because you do not like you use the code browser but you should try it. because coding in the playground for now does not really scales. Le 1/10/16 à 22:39, CodeDmitry a écrit :
Ok I got the proof of concept down, but I can't get it all to run at once since Pharo realizes that the class does not exist(at the time of running), even though it will exist by the time it gets to that line.
Is there a way to modify the following Transcript code make the following code run "at once". Ignoring the fact that classes are not created at time of writing?
([ SimpleSwitchMorph subclass: #LOCell instanceVariableNames: 'mouseAction' classVariableNames: '' package: 'PBE-LightsOut' ] value).
([ BorderedMorph subclass: #LOGame instanceVariableNames: 'cells' classVariableNames: '' package: 'PBE-LightsOut' ] value).
([ LOCell compile: 'mouseAction: a', (String cr), ' ^ mouseAction := a'. ] value).
([ LOCell compile: 'mouseUp: e', (String cr), ' mouseAction value' ] value).
([ LOCell compile: 'initialize', (String cr), ' super initialize.', (String cr), ' self label: ''''.', (String cr), ' self borderWidth: 2.', (String cr), ' bounds := (0@0) corner: (16@16).', (String cr), ' offColor := Color paleYellow.', (String cr), ' onColor := Color paleBlue darker.', (String cr), ' self useSquareCorners.', (String cr), ' self turnOff.' ] value).
([ LOGame compile: 'cellsPerSide', (String cr), ' ^10' ] value).
([ LOGame compile: 'toggleNeighboursOfCellAt: i at: j', (String cr), ' (i > 1) ifTrue: [', (String cr), ' (cells at: i - 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (i < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i + 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j > 1) ifTrue: [', (String cr), ' (cells at: i at: j - 1) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i at: j + 1) toggleState.', (String cr), ' ].' ] value).
([ LOGame compile: 'newCellAt: i at: j', (String cr), ' | c origin | ', (String cr), (String cr), ' c := LOCell new.', (String cr), ' origin := self innerBounds origin.', (String cr), (String cr), ' self addMorph: c.', (String cr), ' ', (String cr), ' c position: ([', (String cr), ' | x_index y_index c_width c_height |', (String cr), (String cr), ' x_index := i - 1.', (String cr), ' y_index := j - 1.', (String cr), ' c_width := c width.', (String cr), ' c_height := c height.', (String cr), ' ', (String cr), ' (x_index * c_width)@(y_index * c_height) + origin', (String cr), ' ] value).', (String cr), (String cr), ' c mouseAction: [', (String cr), ' self toggleNeighboursOfCellAt: i at: j.', (String cr), ' ].', (String cr), ' ^ c.', (String cr) ] value).
([ LOGame compile: 'initialize', (String cr), ' | sampleCell width height n |', (String cr), (String cr), ' super initialize.', (String cr), ' n := self cellsPerSide.', (String cr), (String cr), ' sampleCell := LOCell new.', (String cr), ' width := sampleCell width.', (String cr), ' height := sampleCell height.', (String cr), (String cr), ' self bounds: ', (String cr), ' ((5@5) extent:', (String cr), ' (width * n)@(height * n) + ', (String cr), ' (2 * (self borderWidth))).', (String cr), (String cr), ' cells := Matrix new: n tabulate: [:i :j |', (String cr), ' self newCellAt: i at: j.', (String cr), ' ].' ] value).
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917707.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi, a) creating a class is message send like any other... and the returned value is the newly created class. So you can do locellClass := Object subclass: #LOCell. locellClass compile: 'myMethod'. b) Alternatively (what I usually do), is `#MyClass asClass` (or Smalltalk classNamed: #MyClass). Note that using the former (`asClass`) is (justly) frowned upon when used in regular code, but it is perfectly fine in Playground. (Just like 'MyPackage' asPackage, etc.) As for distribution (which you've mentioned in another mail), I write code like this in my startup scripts, e.g. https://github.com/peteruhnak/pharo-scripts/blob/master/config/5.0/roassal-z... Likewise you can just file-out a method, class, or package(s) and send that to another person, who can just file it in. Final note regarding your string operations... try to avoid using comma to concat many strings, using stream is preferable (from both performance and readability), e.g. LOCell compile: (String streamContents: [ :stream | stream nextPutAll: 'initialize'; cr; nextPutAll: ' super initialize.'; cr. ]). Also Pharo understands multiline strings just fine, so you can do this: LOCell compile: 'initialize super initialize. self label: ''''. self borderWidth: 2' If you need to specify parameters, take a look at String>>format: 'Today is {1}.' format: {Date today}. 'Today is {date}.' format: (Dictionary with: #date->Date today). Peter On Sat, Oct 01, 2016 at 12:39:26PM -0700, CodeDmitry wrote:
([ LOCell compile: 'initialize', (String cr), ' super initialize.', (String cr), ' self label: ''''.', (String cr), ' self borderWidth: 2.', (String cr), ' bounds := (0@0) corner: (16@16).', (String cr), ' offColor := Color paleYellow.', (String cr), ' onColor := Color paleBlue darker.', (String cr), ' self useSquareCorners.', (String cr), ' self turnOff.' ] value).
([ LOGame compile: 'cellsPerSide', (String cr), ' ^10' ] value).
([ LOGame compile: 'toggleNeighboursOfCellAt: i at: j', (String cr), ' (i > 1) ifTrue: [', (String cr), ' (cells at: i - 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (i < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i + 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j > 1) ifTrue: [', (String cr), ' (cells at: i at: j - 1) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i at: j + 1) toggleState.', (String cr), ' ].' ] value).
([ LOGame compile: 'newCellAt: i at: j', (String cr), ' | c origin | ', (String cr), (String cr), ' c := LOCell new.', (String cr), ' origin := self innerBounds origin.', (String cr), (String cr), ' self addMorph: c.', (String cr), ' ', (String cr), ' c position: ([', (String cr), ' | x_index y_index c_width c_height |', (String cr), (String cr), ' x_index := i - 1.', (String cr), ' y_index := j - 1.', (String cr), ' c_width := c width.', (String cr), ' c_height := c height.', (String cr), ' ', (String cr), ' (x_index * c_width)@(y_index * c_height) + origin', (String cr), ' ] value).', (String cr), (String cr), ' c mouseAction: [', (String cr), ' self toggleNeighboursOfCellAt: i at: j.', (String cr), ' ].', (String cr), ' ^ c.', (String cr) ] value).
([ LOGame compile: 'initialize', (String cr), ' | sampleCell width height n |', (String cr), (String cr), ' super initialize.', (String cr), ' n := self cellsPerSide.', (String cr), (String cr), ' sampleCell := LOCell new.', (String cr), ' width := sampleCell width.', (String cr), ' height := sampleCell height.', (String cr), (String cr), ' self bounds: ', (String cr), ' ((5@5) extent:', (String cr), ' (width * n)@(height * n) + ', (String cr), ' (2 * (self borderWidth))).', (String cr), (String cr), ' cells := Matrix new: n tabulate: [:i :j |', (String cr), ' self newCellAt: i at: j.', (String cr), ' ].' ] value).
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917707.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
On Sun, Oct 2, 2016 at 8:10 PM, Peter Uhnak <i.uhnak@gmail.com> wrote:
Hi,
a) creating a class is message send like any other... and the returned value is the newly created class.
So you can do
locellClass := Object subclass: #LOCell. locellClass compile: 'myMethod'.
b) Alternatively (what I usually do), is `#MyClass asClass` (or Smalltalk classNamed: #MyClass).
Note that using the former (`asClass`) is (justly) frowned upon when used in regular code, but it is perfectly fine in Playground. (Just like 'MyPackage' asPackage, etc.)
As for distribution (which you've mentioned in another mail), I write code like this in my startup scripts, e.g. https://github.com/peteruhnak/pharo-scripts/blob/master/config/5.0/roassal-z...
Likewise you can just file-out a method, class, or package(s) and send that to another person, who can just file it in.
Final note regarding your string operations... try to avoid using comma to concat many strings, using stream is preferable (from both performance and readability), e.g.
The performance aspect is not absolute and depends on usage... http://forum.world.st/Stream-instead-of-string-concatenation-td4856891.html http://forum.world.st/When-to-use-a-stream-for-concatenating-text-td4811093.... cheers -ben
LOCell compile: (String streamContents: [ :stream | stream nextPutAll: 'initialize'; cr; nextPutAll: ' super initialize.'; cr. ]).
Also Pharo understands multiline strings just fine, so you can do this:
LOCell compile: 'initialize super initialize. self label: ''''. self borderWidth: 2'
If you need to specify parameters, take a look at String>>format:
'Today is {1}.' format: {Date today}. 'Today is {date}.' format: (Dictionary with: #date->Date today).
Peter
On Sat, Oct 01, 2016 at 12:39:26PM -0700, CodeDmitry wrote:
([ LOCell compile: 'initialize', (String cr), ' super initialize.', (String cr), ' self label: ''''.', (String cr), ' self borderWidth: 2.', (String cr), ' bounds := (0@0) corner: (16@16).', (String cr), ' offColor := Color paleYellow.', (String cr), ' onColor := Color paleBlue darker.', (String cr), ' self useSquareCorners.', (String cr), ' self turnOff.' ] value).
([ LOGame compile: 'cellsPerSide', (String cr), ' ^10' ] value).
([ LOGame compile: 'toggleNeighboursOfCellAt: i at: j', (String cr), ' (i > 1) ifTrue: [', (String cr), ' (cells at: i - 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (i < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i + 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j > 1) ifTrue: [', (String cr), ' (cells at: i at: j - 1) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i at: j + 1) toggleState.', (String cr), ' ].' ] value).
([ LOGame compile: 'newCellAt: i at: j', (String cr), ' | c origin | ', (String cr), (String cr), ' c := LOCell new.', (String cr), ' origin := self innerBounds origin.', (String cr), (String cr), ' self addMorph: c.', (String cr), ' ', (String cr), ' c position: ([', (String cr), ' | x_index y_index c_width c_height |', (String cr), (String cr), ' x_index := i - 1.', (String cr), ' y_index := j - 1.', (String cr), ' c_width := c width.', (String cr), ' c_height := c height.', (String cr), ' ', (String cr), ' (x_index * c_width)@(y_index * c_height) + origin', (String cr), ' ] value).', (String cr), (String cr), ' c mouseAction: [', (String cr), ' self toggleNeighboursOfCellAt: i at: j.', (String cr), ' ].', (String cr), ' ^ c.', (String cr) ] value).
([ LOGame compile: 'initialize', (String cr), ' | sampleCell width height n |', (String cr), (String cr), ' super initialize.', (String cr), ' n := self cellsPerSide.', (String cr), (String cr), ' sampleCell := LOCell new.', (String cr), ' width := sampleCell width.', (String cr), ' height := sampleCell height.', (String cr), (String cr), ' self bounds: ', (String cr), ' ((5@5) extent:', (String cr), ' (width * n)@(height * n) + ', (String cr), ' (2 * (self borderWidth))).', (String cr), (String cr), ' cells := Matrix new: n tabulate: [:i :j |', (String cr), ' self newCellAt: i at: j.', (String cr), ' ].' ] value).
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917707.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
CodeDmitry wrote
Ok I got the proof of concept down, but I can't get it all to run at once since Pharo realizes that the class does not exist(at the time of running), even though it will exist by the time it gets to that line.
Is there a way to modify the following Transcript code make the following code run "one block at a time". Ignoring the fact that classes are not created at time of writing?
I think I need some way to "reflectively find a class by class name at runtime".
steps.st
([ SimpleSwitchMorph subclass: #LOCell instanceVariableNames: 'mouseAction' classVariableNames: '' package: 'PBE-LightsOut' ] value).
/
<snip> / Well, that was an excruciating read. Did you find it easy to read? I'll bet you also found it hard to write.
If you look at the file-out format (also called chunk format), you can just simply write the code you want as a result and it would be infinitely more comprehensible to you and to those you would share it with. There are times when writing things along the lines that you have are essential. For example, if you are writing a code generator you would want to generate source strings and compile them. -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917927.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Or just use the st command line handler to load your code. pharo-ui someimage.image st blah.st I do not know if it loads in Pharo5 but I had this working in Pharo3 that extends the File Browser in Pharo with additional buttons that allow you to edit external files easily. You can also steal this thing: https://github.com/vim-scripts/st.vim/blob/master/syntax/st.vim Useful for writing scripts indeed. Pharo can be used like Python, Perl, or Tcl for scripting from the command line. VTermOutputDriver is an interesting class to look at for that (does nice colors). Phil On Mon, Oct 3, 2016 at 10:40 PM, Richard Sargent < richard.sargent@gemtalksystems.com> wrote:
CodeDmitry wrote
Ok I got the proof of concept down, but I can't get it all to run at once since Pharo realizes that the class does not exist(at the time of running), even though it will exist by the time it gets to that line.
Is there a way to modify the following Transcript code make the following code run "one block at a time". Ignoring the fact that classes are not created at time of writing?
I think I need some way to "reflectively find a class by class name at runtime".
steps.st
([ SimpleSwitchMorph subclass: #LOCell instanceVariableNames: 'mouseAction' classVariableNames: '' package: 'PBE-LightsOut' ] value).
/
<snip> / Well, that was an excruciating read. Did you find it easy to read? I'll bet you also found it hard to write.
If you look at the file-out format (also called chunk format), you can just simply write the code you want as a result and it would be infinitely more comprehensible to you and to those you would share it with.
There are times when writing things along the lines that you have are essential. For example, if you are writing a code generator you would want to generate source strings and compile them.
-- View this message in context: http://forum.world.st/New-to- Pharo-a-bunch-of-questions-tp4917701p4917927.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
But why do you want that? Why do you want to code everything in the playground? Le 1/10/16 à 21:58, CodeDmitry a écrit :
Thanks Peter! I admit I couldnt really dynamically add methods to a class at runtime since I was doing it as follows:
([ (LOCell class) methodDict at: #mouseAction put: ((LOCell class) compile: mouseAction: a ^ mouseAction := a ). ] value).
Which caused constant harassment by Pharo until I typed:
(LOCell class) removeAllKeys.
or
(LOCell class) removeKey: #mouseAction.
I'll try your method in a bit to see if it works better.
But you are using black magic incantation instead of using the class browser So do not complain if you shoot in your feet in the future. I would not code like that because you will just get frustrated and you will think pharo is bad while we are all using hyper fast and safe and we keep black magic for the place we want it. Stef
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917706.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
This a problem I have long identified with Smalltalk that Pharo inherits. The fact that workspace is disconnected from System Browser. But I never bothered fixing because of other priorities. Personally I am suprised you ask why one would want a more close connection between System Browser and Workspace/Playground , isn't it obvious it would speed up workflow considerably ? My workaround has been not to use Playground at all and instead work directly with System Browser. I use playground only to trigger class execution. Even that is not necessary because of the script pragma which makes possible to trigger execution directly from System Browser. This is not just a problem of Workspace only , all tools inside Smaltalkl are disconnected with exception of inspector and debugger . The king of integration and the best example of how to connect a tool with others is GTSpotter. Of course that is also what makes GTSpotter so popular. On Sun, 2 Oct 2016 at 08:19, stepharo <stepharo@free.fr> wrote:
But why do you want that? Why do you want to code everything in the playground?
Le 1/10/16 à 21:58, CodeDmitry a écrit :
Thanks Peter! I admit I couldnt really dynamically add methods to a class at runtime since I was doing it as follows:
([ (LOCell class) methodDict at: #mouseAction put: ((LOCell class) compile: mouseAction: a ^ mouseAction := a ). ] value).
Which caused constant harassment by Pharo until I typed:
(LOCell class) removeAllKeys.
or
(LOCell class) removeKey: #mouseAction.
I'll try your method in a bit to see if it works better.
But you are using black magic incantation instead of using the class browser So do not complain if you shoot in your feet in the future.
I would not code like that because you will just get frustrated and you will think pharo is bad while we are all using hyper fast and safe and we keep black magic for the place we want it.
Stef
-- View this message in context:
http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917706.ht...
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
It's just nice to have a standalone code that I can give to my friends that they can read and run to create the structure without having to setup everything themselves, but at the same time not needing to use a package. A standalone script is quite elegant for situations like that, since it well encapsulates the automation without forcing people to understand packaging. -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917764.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Better use the fileout menu you will get all the code of your class/package inside a file. Stef Le 2/10/16 à 12:02, CodeDmitry a écrit :
It's just nice to have a standalone code that I can give to my friends that they can read and run to create the structure without having to setup everything themselves, but at the same time not needing to use a package. A standalone script is quite elegant for situations like that, since it well encapsulates the automation without forcing people to understand packaging.
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917764.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
CodeDmitry wrote
It's just nice to have a standalone code that I can give to my friends that they can read and run to create the structure without having to setup everything themselves, but at the same time not needing to use a package.
A standalone script is quite elegant for situations like that, since it well encapsulates the automation without forcing people to understand packaging.
I don't mind shooting myself in the foot, I want to understand how Pharo runtime works, it has this strange circularity to it that I can't quite wrap my mind around.
I just like doing everything in Code if possible. I see no reason to use the browser other to inspect system state at the moment.
Bear in mind, the browsers were created by the original authors to facilitate repetitive actions. They are tools for interacting with the objects in the system, just as are the debugger and inspector. That being said, I do agree i is important to understand how the tools do what they do. You should definitely browse the Behavior hierarchy. It contains all the code for creating classes, compiling (and installing!) methods, removing methods, and so on. Also, I noticed in your examples that you like to write ([ ... ] value). Why? Why not just write the actual code (shown as ... in my example)?
Personally I've never had more fun with Smalltalk as I did writing this proof of concept.
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917926.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Complete proof of concept(all I needed was Smalltalk classNamed: x) to reflect the class at runtime so that the playground script doesn't get confused since the classes don't exist before script is evaluated. ([ "create the classes." ([ SimpleSwitchMorph subclass: #LOCell instanceVariableNames: 'mouseAction' classVariableNames: '' package: 'PBE-LightsOut'. BorderedMorph subclass: #LOGame instanceVariableNames: 'cells' classVariableNames: '' package: 'PBE-LightsOut'. ] value). "create LOCell methods." ([:this | this compile: 'mouseAction: a', (String cr), ' ^ mouseAction := a'. this compile: 'mouseUp: e', (String cr), ' mouseAction value'. this compile: 'initialize', (String cr), ' super initialize.', (String cr), ' self label: ''''.', (String cr), ' self borderWidth: 2.', (String cr), ' bounds := (0@0) corner: (16@16).', (String cr), ' offColor := Color paleYellow.', (String cr), ' onColor := Color paleBlue darker.', (String cr), ' self useSquareCorners.', (String cr), ' self turnOff.'. ] value: (Smalltalk classNamed: 'LOCell')). ([:this | this compile: 'cellsPerSide', (String cr), ' ^10'. this compile: 'toggleNeighboursOfCellAt: i at: j', (String cr), ' (i > 1) ifTrue: [', (String cr), ' (cells at: i - 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (i < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i + 1 at: j) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j > 1) ifTrue: [', (String cr), ' (cells at: i at: j - 1) toggleState.', (String cr), ' ].', (String cr), (String cr), ' (j < self cellsPerSide) ifTrue: [', (String cr), ' (cells at: i at: j + 1) toggleState.', (String cr), ' ].'. this compile: 'newCellAt: i at: j', (String cr), ' | c origin | ', (String cr), (String cr), ' c := LOCell new.', (String cr), ' origin := self innerBounds origin.', (String cr), (String cr), ' self addMorph: c.', (String cr), ' ', (String cr), ' c position: ([', (String cr), ' | x_index y_index c_width c_height |', (String cr), (String cr), ' x_index := i - 1.', (String cr), ' y_index := j - 1.', (String cr), ' c_width := c width.', (String cr), ' c_height := c height.', (String cr), ' ', (String cr), ' (x_index * c_width)@(y_index * c_height) + origin', (String cr), ' ] value).', (String cr), (String cr), ' c mouseAction: [', (String cr), ' self toggleNeighboursOfCellAt: i at: j.', (String cr), ' ].', (String cr), ' ^ c.', (String cr). this compile: 'initialize', (String cr), ' | sampleCell width height n |', (String cr), (String cr), ' super initialize.', (String cr), ' n := self cellsPerSide.', (String cr), (String cr), ' sampleCell := LOCell new.', (String cr), ' width := sampleCell width.', (String cr), ' height := sampleCell height.', (String cr), (String cr), ' self bounds: ', (String cr), ' ((5@5) extent:', (String cr), ' (width * n)@(height * n) + ', (String cr), ' (2 * (self borderWidth))).', (String cr), (String cr), ' cells := Matrix new: n tabulate: [:i :j |', (String cr), ' self newCellAt: i at: j.', (String cr), ' ].'. ] value: (Smalltalk classNamed: 'LOGame')). ] value). -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917710.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi: Welcome to Pharo. Which university is teaching you Smalltalk? What is the course title? Are the students appreciating the features of Smalltalk? Hope you are. All the best, Aik-Siong Koh -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917803.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
@askoh Ryerson University, Pragmatic Programming Languages teaches smalltalk, and Introduction to Object Oriented Programming does too. -- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917808.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Excellent :) We did not know that Ryerson was using Pharo! Stef
@askoh
Ryerson University, Pragmatic Programming Languages teaches smalltalk, and Introduction to Object Oriented Programming does too.
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917808.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
CodeDmitry wrote
@askoh
Ryerson University, Pragmatic Programming Languages teaches Smalltalk, and Introduction to Object Oriented Programming does too.
Well, be sure to check out the Toronto Smalltalk User Group! http://www.smalltalk.ca/ says they meet at Ryerson. I'm not sure that's always / still true. But you will be welcomed.
There was also a club I think where people did Smalltalk coding, but I never really visited it so I may have been lied to.
@stepharo
heh you're right! I haven't noticed that feature, it's handy.
Umm I created a category Dummy, with class Dumbo, with method meep that does trivial text printing, and file-out'd it, but I don't know how to put it back in, it's not a valid Playground-script.
Object subclass: #Dumbo instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Dummy'!
!Dumbo methodsFor: 'as yet unclassified' stamp: 'Anonymous 10/2/2016 21:19'! meep Transcript show: 'Hello, World!!'.! !
-- View this message in context: http://forum.world.st/New-to-Pharo-a-bunch-of-questions-tp4917701p4917925.ht... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
participants (9)
-
askoh -
Ben Coman -
CodeDmitry -
Dimitris Chloupis -
Nicolai Hess -
Peter Uhnak -
phil@highoctane.be -
Richard Sargent -
stepharo