Smalltalk Syntax in a Postcard contest
As there was a recent discussion about the Smalltalk Syntax in a Postcard, i added a contest on the Stackoverflow Programming Puzzles & Code Golf site: http://codegolf.stackexchange.com/questions/33050/smalltalk-syntax-in-a-post... -- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Yes I would love to have a method doing something useful and showing the complete syntax ") On 6/7/14 18:16, MartinW wrote:
As there was a recent discussion about the Smalltalk Syntax in a Postcard, i added a contest on the Stackoverflow Programming Puzzles & Code Golf site: http://codegolf.stackexchange.com/questions/33050/smalltalk-syntax-in-a-post...
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
The contest is gone? Anyway, the closest useful method I have found by iterating all ASTs in standard 3.0 image : - Declares arguments - Has assignment - Has sequence - Has blocks with 0 and 2 arguments - Declares temporaries - Has binary messages - Has unary messages - Has keyword messages - Has super messages - Has cascade - Has return - Uses String and Integer and this is the winner: RBMessageNode>>replaceSourceWithMessageNode: aNode | isBinaryToKeyword | self numArgs = aNode numArgs ifFalse: [^super replaceSourceWith: aNode]. self arguments with: aNode arguments do: [:old :new | (self mappingFor: old) = new ifFalse: [^super replaceSourceWith: aNode]]. (self mappingFor: self receiver) = aNode receiver ifFalse: [(self receiver isVariable and: [aNode receiver isVariable]) ifFalse: [^super replaceSourceWith: aNode]. self addReplacement: (RBStringReplacement replaceFrom: self receiver start to: self receiver stop with: aNode receiver name)]. (isBinaryToKeyword := self isBinary and: [aNode isKeyword]) ifTrue: [(self hasParentheses not and: [self parent precedence <= aNode precedence]) ifTrue: [self addReplacement: (RBStringReplacement replaceFrom: self start to: self start - 1 with: '('); addReplacement: (RBStringReplacement replaceFrom: self stop + 1 to: self stop with: ')')]]. self selectorParts with: aNode selectorParts do: [:old :new | old value ~= new value ifTrue: [self addReplacement: (RBStringReplacement replaceFrom: old start to: old stop with: ((isBinaryToKeyword and: [(self source at: old start - 1) isSeparator not]) ifTrue: [' ' , new value] ifFalse: [new value]))]] Cheers, Hernán 2014-07-06 13:16 GMT-03:00 MartinW <wm@fastmail.fm>:
As there was a recent discussion about the Smalltalk Syntax in a Postcard, i added a contest on the Stackoverflow Programming Puzzles & Code Golf site:
http://codegolf.stackexchange.com/questions/33050/smalltalk-syntax-in-a-post...
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Sometimes StackExchange-related guys are really stupid⦠I think that we should put this contest in a visible place. And thanks Hernán, I think that itâs also cool that you can search for desired method like that in the image. Uko On 08 Jul 2014, at 09:07, Hernán Morales Durand <hernan.morales@gmail.com> wrote:
The contest is gone?
Anyway, the closest useful method I have found by iterating all ASTs in standard 3.0 image :
- Declares arguments - Has assignment - Has sequence - Has blocks with 0 and 2 arguments - Declares temporaries - Has binary messages - Has unary messages - Has keyword messages - Has super messages - Has cascade - Has return - Uses String and Integer
and this is the winner:
RBMessageNode>>replaceSourceWithMessageNode: aNode
| isBinaryToKeyword | self numArgs = aNode numArgs ifFalse: [^super replaceSourceWith: aNode]. self arguments with: aNode arguments do: [:old :new | (self mappingFor: old) = new ifFalse: [^super replaceSourceWith: aNode]]. (self mappingFor: self receiver) = aNode receiver ifFalse: [(self receiver isVariable and: [aNode receiver isVariable]) ifFalse: [^super replaceSourceWith: aNode]. self addReplacement: (RBStringReplacement replaceFrom: self receiver start to: self receiver stop with: aNode receiver name)]. (isBinaryToKeyword := self isBinary and: [aNode isKeyword]) ifTrue: [(self hasParentheses not and: [self parent precedence <= aNode precedence]) ifTrue: [self addReplacement: (RBStringReplacement replaceFrom: self start to: self start - 1 with: '('); addReplacement: (RBStringReplacement replaceFrom: self stop + 1 to: self stop with: ')')]]. self selectorParts with: aNode selectorParts do: [:old :new | old value ~= new value ifTrue: [self addReplacement: (RBStringReplacement replaceFrom: old start to: old stop with: ((isBinaryToKeyword and: [(self source at: old start - 1) isSeparator not]) ifTrue: [' ' , new value] ifFalse: [new value]))]]
Cheers,
Hernán
2014-07-06 13:16 GMT-03:00 MartinW <wm@fastmail.fm>: As there was a recent discussion about the Smalltalk Syntax in a Postcard, i added a contest on the Stackoverflow Programming Puzzles & Code Golf site: http://codegolf.stackexchange.com/questions/33050/smalltalk-syntax-in-a-post...
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
On 08 Jul 2014, at 11:08, Frank Shearar <frank.shearar@gmail.com> wrote:
On 8 July 2014 08:12, Yuriy Tymchuk <yuriy.tymchuk@me.com> wrote:
Sometimes StackExchange-related guys are really stupidâ¦
That missing contest page has this: "This question was voluntarily removed by its author.â
No, the thing is that I followed discussion when the question was present. They had a valid question that maybe wasnât perfect in terms of site, but they could get some impact from it. Now they donât have it. Once I proposed a new Q/A site, and proposal was quite popular. Now they donât have it⦠Uko
frank
Uko
I removed the question, but only after it was already marked to be closed by several people. Their argument was, that the question was "to broad". Once a discussion like this starts on Stackexchange sites there's always a herd behavior that's hard to stop. Can you share the code you used for your search, Hernán? Hernán Morales Durand wrote
The contest is gone?
Anyway, the closest useful method I have found by iterating all ASTs in standard 3.0 image :
- Declares arguments - Has assignment - Has sequence - Has blocks with 0 and 2 arguments - Declares temporaries - Has binary messages - Has unary messages - Has keyword messages - Has super messages - Has cascade - Has return - Uses String and Integer
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793p47671... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hello Martin, I have refined the search a little bit, and we have a new winner with Stephane Ducasse as author in annotations. PSMCMergeMorph>>model: aMerger "Set the model and update the window." |grouped sorted| super model: aMerger. grouped := aMerger operations groupBy: [:o | o targetClassName ifNil: [o shortSummary]] having: [:g | true]. sorted := OrderedCollection new. grouped keys asSortedCollection do: [:k | sorted addAll: ((grouped at: k) asSortedCollection: [:a :b | a shortSummary <= b shortSummary])]. self patchMorph model: sorted This is the code I have used: | allMethods | allMethods := SystemNavigation default allMethods. UIManager default displayProgress: 'Scanning all methods...' from: 1 to: allMethods size during: [ : bar | | current | current := 0. allMethods select: [ : each | current := current + 1. bar value: current. each ast arguments notEmpty and: [ (each ast allChildren anySatisfy: #isAssignment) and: [ (each ast allChildren anySatisfy: #isBlock) and: [ each ast temporaries notEmpty and: [ each ast superMessages notEmpty and: [ (each ast allChildren anySatisfy: [ : node | node isMessage and: [ node selector isUnary ] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isMessage and: [ node selector isBinary ] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isBlock and: [ node arguments size = 2] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isBlock and: [ node arguments size = 1] ]) ] ] ] ] ] ] ] ] ] ]. Cheers, Hernán 2014-07-08 18:48 GMT-03:00 MartinW <wm@fastmail.fm>:
I removed the question, but only after it was already marked to be closed by several people. Their argument was, that the question was "to broad". Once a discussion like this starts on Stackexchange sites there's always a herd behavior that's hard to stop.
Can you share the code you used for your search, Hernán?
Hernán Morales Durand wrote
The contest is gone?
Anyway, the closest useful method I have found by iterating all ASTs in standard 3.0 image :
- Declares arguments - Has assignment - Has sequence - Has blocks with 0 and 2 arguments - Declares temporaries - Has binary messages - Has unary messages - Has keyword messages - Has super messages - Has cascade - Has return - Uses String and Integer
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793p47671... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
I forgot to add each ast allChildren anySatisfy: [ : node | node isCascade ] which in that case, there is no method in the Pharo 3 image. Maybe a package out there... Anyway, who can load all packages? :) Hernán PS: One problem with StackExchange is there are very few smalltalkers registered. 2014-07-08 21:20 GMT-03:00 Hernán Morales Durand <hernan.morales@gmail.com>:
Hello Martin,
I have refined the search a little bit, and we have a new winner with Stephane Ducasse as author in annotations.
PSMCMergeMorph>>model: aMerger "Set the model and update the window."
|grouped sorted| super model: aMerger. grouped := aMerger operations groupBy: [:o | o targetClassName ifNil: [o shortSummary]] having: [:g | true]. sorted := OrderedCollection new. grouped keys asSortedCollection do: [:k | sorted addAll: ((grouped at: k) asSortedCollection: [:a :b | a shortSummary <= b shortSummary])]. self patchMorph model: sorted
This is the code I have used:
| allMethods | allMethods := SystemNavigation default allMethods. UIManager default displayProgress: 'Scanning all methods...' from: 1 to: allMethods size during: [ : bar | | current | current := 0. allMethods select: [ : each | current := current + 1. bar value: current. each ast arguments notEmpty and: [ (each ast allChildren anySatisfy: #isAssignment) and: [ (each ast allChildren anySatisfy: #isBlock) and: [ each ast temporaries notEmpty and: [ each ast superMessages notEmpty and: [ (each ast allChildren anySatisfy: [ : node | node isMessage and: [ node selector isUnary ] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isMessage and: [ node selector isBinary ] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isBlock and: [ node arguments size = 2] ]) and: [ (each ast allChildren anySatisfy: [ : node | node isBlock and: [ node arguments size = 1] ]) ] ] ] ] ] ] ] ] ] ].
Cheers,
Hernán
2014-07-08 18:48 GMT-03:00 MartinW <wm@fastmail.fm>:
I removed the question, but only after it was already marked to be closed
by several people. Their argument was, that the question was "to broad". Once a discussion like this starts on Stackexchange sites there's always a herd behavior that's hard to stop.
Can you share the code you used for your search, Hernán?
Hernán Morales Durand wrote
The contest is gone?
Anyway, the closest useful method I have found by iterating all ASTs in standard 3.0 image :
- Declares arguments - Has assignment - Has sequence - Has blocks with 0 and 2 arguments - Declares temporaries - Has binary messages - Has unary messages - Has keyword messages - Has super messages - Has cascade - Has return - Uses String and Integer
-- View this message in context: http://forum.world.st/Smalltalk-Syntax-in-a-Postcard-contest-tp4766793p47671... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
participants (5)
-
Frank Shearar -
Hernán Morales Durand -
MartinW -
stepharo -
Yuriy Tymchuk