Open astares opened 2 years ago
@astares thanks for sharing. Here is a POC implementation of this: https://gist.github.com/zeroflag/1634116227c3b811f0692db4f2889634
GistGitHub Gist: instantly share code, notes, and snippets.
using DNU for this is not that good because it requires 2 lookups for each chained message.
I think from all the extensions shown, destructuring assignments are the easiest to integrate:
It would be nice that somebody writes a Phep on this (or in the more complex one). The slides can be a starting point!
@astares thanks for sharing. Here is a POC implementation of this: https://gist.github.com/zeroflag/1634116227c3b811f0692db4f2889634
Gistchain.stGitHub Gist: instantly share code, notes, and snippets.
Yes, if you look at the https://github.com/dvmason/Pharo-Functional repo, you will see that we already have that as well, but as @LucFabresse mentions, this requires a DNU and perform:
for each message, neither of which are super-fast operations!
GistGitHub Gist: instantly share code, notes, and snippets.
GitHubFunctional support for Pharo. Contribute to dvmason/Pharo-Functional development by creating an account on GitHub.
I think from all the extensions shown, destructuring assignments are the easiest to integrate:
- less parser friction, it should be implemented without breaking the parser
- backwards compatible, it relies on syntax that is currently invalid so it will not break existing programs
- no extra runtime cost (just syntax sugar for collection accesses)
It would be nice that somebody writes a Phep on this (or in the more complex one). The slides can be a starting point!
All of the syntax proposals are backwards compatible... they all are invalid syntax in a standard parser. And all the code and implementation is in the repo: https://github.com/dvmason/Pharo-Functional
I would argue that of the proposals, the parrot operator and collection literals are the easiest, zero-cost options. Destructuring assignments also have the same cost as writing them out.
Initializing locals at point of declaration is also zero-cost and I'd love to see them.
Expressions as messages are more of a mental shift. They can make for some very elegant code, but they aren't quite zero-cost, and the more elegant code may be a matter of taste.
At ESUG 2022 there was discussed about syntactic sugar to make programming in a functional style easier. Eliminating the ().
See https://twitter.com/StOnSoftware/status/1562411468901031937
Attila Magyar suggested on Twitter that this can be implemented as a proxy with DNU handler, without adding new syntax. See https://twitter.com/zeroflag/status/1562414140639137792
We could provide such a feature in the standard image if people need and upvote this.