-
Notifications
You must be signed in to change notification settings - Fork 59
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
Trailing Block Expressions #100
base: master
Are you sure you want to change the base?
Conversation
Why does it have to be a macro function, couldn't it be expanded for any lambda function? |
Could you clarify what you mean? Do you mean a Kotlin-like feature of allowing trailing blocks to be treated as lambdas that are passed as the final argument to a normal function? |
Correct |
As a syntax-sugar lover I would certainly not be opposed to it, and I mentioned trailing lambdas in the "Unresolved Questions" section because I want it to be a part of the discussion, but I personally felt including it as a feature in the proposal would hurt the chances of it being accepted. I figure it's safer to shoot for the syntax first, and if accepted, later proposals for how the trailing blocks can be interpreted for normal functions can be submitted/discussed. And even if those aren't accepted, this proposal still opens the ability to replicate such capabilities using The reasons I feel trailing lambdas would be shot down are:
|
I think this makes it difficult to read in most cases and even creates ambiguous reading. In your example, the "simple" way of reading the last line (without reading the first one) would be that myMacroFunc has a signature comparable to Int->(TrailingExpr->Void)->Expr. Which is exactly what your first line means but wouldn't it be possible for MyMacroFunc to have the following signature : Int->(TrailingExpr->Expr) ? |
Pass block expressions to macro functions like this:
Rendered version