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-postcard-that-actually-does-something-interesting



--
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.