On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote:
>const char = if (current < input.len)
input[current]
else
break;
It's too ugly!
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
It's too ugly! |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like I think this does not give intuitively what char value will be: undefined, 0 ? |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 4 June 2022 at 16:24:10 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like I think this does not give intuitively what char value will be: undefined, 0 ? In that case, no assignment would occur. Control flow was interrupted before the assignment. |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Saturday, 4 June 2022 at 16:28:07 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 16:24:10 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like I think this does not give intuitively what char value will be: undefined, 0 ? In that case, no assignment would occur. Control flow was interrupted before the assignment. yes, this is what I observe
> 66 I had no idea. Not mind changing however. |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On 6/4/2022 3:13 AM, rikki cattermole wrote:
> How much work would it take to make it work for lets just say if, foreach and switch?
Using lambdas would be better.
|
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SealabJaster | On Saturday, 4 June 2022 at 10:01:31 UTC, SealabJaster wrote: >While I do agree that's more readable, I wonder if the OP was thinking more along the lines of this, which is what you can see in languages like F# where if statements are expressions:
|
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 4 June 2022 at 16:55:37 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:28:07 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 16:24:10 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like I think this does not give intuitively what char value will be: undefined, 0 ? In that case, no assignment would occur. Control flow was interrupted before the assignment. yes, this is what I observe
> 66 I had no idea. Not mind changing however. So actually there's not even something like a common type involved. The "then" part is used as assign rhs and the "else" part is just unrelated. well "Okay" let's say ;) What a strange language tho. |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 4 June 2022 at 20:11:09 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:55:37 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:28:07 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 16:24:10 UTC, user1234 wrote: >On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote: >On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote: >
Just like I think this does not give intuitively what char value will be: undefined, 0 ? In that case, no assignment would occur. Control flow was interrupted before the assignment. yes, this is what I observe
> 66 I had no idea. Not mind changing however. So actually there's not even something like a common type involved. The "then" part is used as assign rhs and the "else" part is just unrelated. well "Okay" let's say ;) What a strange language tho. imagine using a switch as assign lhs too:
that whole thing of mixing expressions and statements looks really absurd even if there are special cases that may appear appealing. In this last example you'd have to check that every case yields a compatible lvalue. Now maybe you also want chained assignments.
No way. |
June 04, 2022 Re: Do you think if statement as expression would be nice to have in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dukc | On Saturday, 4 June 2022 at 19:54:48 UTC, Dukc wrote: >
This next question comes from a place of ignorance: What is the codegen like for this code? Would is allocate a closure on the GC before performing the execution, or are the compilers smart enough to inline the entire thing? |