Hello -- I want to do some experimentation with alternative syntax for Smalltalk. My main motivation is trying to unify the block and method syntax. I see a block as an in-lined method with an empty selector. This syntax helps to visualize that an object is basically a closure over its instance variables.
To make this work, I would also need to make Blocks understand the message #: (which would be equivalent to the current #value:).
Some examples will be more clear than I can describe.
Currently:
succ := [:n | n + 1].
(succ value: 3) = 4.
addTo := [:a :b | a + b].
(addTo value: 3 value: 4) = 7.
Proposal:
[succ: n | n + 1].
(succ :3) = 4.
[add: a to: b | a + b].
(add :3 to : 4) = 7.
Class declaration syntax:
[Point << Object |
| x y |
[hash | ^x hash + y hash].
[extent: aPoint | ^Rectangle origin: self extent: aPoint].
[distance: aPoint |
| dx dy |
dx := aPoint x - x.
dy := aPoint y - y.
^((dx * dx) + (dy * dy)) sqrt].
].
I am reaching out for ideas or direction on how to do such experiments. I would rather avoid touching the current compiler. Maybe defining this alternative syntax that compiles to regular Smalltalk. Nowadays PEG parsers are very trendy. Is there one available for any of the Squeak/Smalltalk flavours?
Thanks,
Francisco