-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Smalltalk-style method chaining syntax #221
Comments
Looks good to me. Only quibble I have is on the macro implementation: if object_ast is something that performs a destructive operation (say, getting the next item off a queue or something), wouldn't the macro end up performing many of them, rather than just one? |
Oh, another thing. In ST |
Yes, you're right. More generally, with quasis in macros, whenever one is using the same value multiple times, one always wants to capture, with no exception that I've found so far. (Later edit: This is now discussed in #234 and #479.) Ok, here's a new implementation that does that:
|
Hm, you're right. The last method shouldn't return the invocant, because that's clearly useless, just like it's useful in earlier places in the chain. Let's see... postfixes nest like this: Under that scheme, Yes, this scheme is more ambitious, but I like it better, I think. |
Yup. In ST, if that's actually what you want, you can just call the identity method, i.e. |
Yeah, for maximum manipulexity you want to be able to choose between the invocant and the returned value. In ST it's solved by the chaining operator returning the last return value and having a method that just returns the invocant (called |
Smalltalk's syntax is different than the one I propose in OP. It uses semicolons and periods. I think I might have gotten the |
Courtesy of @arnsholt. Slightly made-up but complete example:
That is, even though those
printMumble
methods don't explicitly return theemployee
object (or somethis
equivalent), the..
call syntax allows them to be used as if they did.Here's a possible implementation:
The text was updated successfully, but these errors were encountered: