[squeak-dev] playing with syntax alternatives

Marcel Taeumel marcel.taeumel at hpi.de
Sun Apr 18 17:20:47 UTC 2021


Hi Francisco,

have you checked out Ohm/S yet?
https://github.com/hpi-swa/Ohm-S [https://github.com/hpi-swa/Ohm-S]


Best,
Marcel
Am 17.04.2021 11:48:19 schrieb Francisco Garau <francisco.garau at gmail.com>:
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










-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210418/1f06109e/attachment.html>


More information about the Squeak-dev mailing list