DreamBerd
DreamBerd copied to clipboard
`else` statements after `when` statements are not documented
The hidden FizzBuzz example utilizes else when statements, but they're not documented anywhere in the spec. As a result, ChatGPT assumed the wrong semantics for them, deciding that an else when was identical to a when.
In order to resolve this, I suggest following ChatGPT's lead, and making else not do anything. So the current FizzBuzz example:
const var i: Int!
when (i % 3 = 0 && i % 5 = 0) "FizzBuzz"?
else when (i % 3 = 0) "Fizz"?
else when (i % 5 = 0) "Buzz"?
else i?
when (i < 20) i++!
i = 0!
would be semantically identical to:
const var i: Int!
when (i % 3 = 0 && i % 5 = 0) "FizzBuzz"?
when (i % 3 = 0) "Fizz"?
when (i % 5 = 0) "Buzz"?
i?
when (i < 20) i++!
i = 0!
By officially adopting ChatGPT's wrong assumption, you maximize the odds that ChatGPT will make the right assumption in the future.
Good idea! Would you like to make a PR to fix the example?
If #105 is implemented, ensure that when statements check the other conditions as well, since they are not guaranteed to be executed in this order.
when (i % 3 = 0 && i % 5 = 0) "FizzBuzz"?
else when (i % 3 = 0 && i % 5 ;= 0) "Fizz"?
else when (i % 5 = 0 && i % 3 ;= 0) "Buzz"?
else when (i % 5 ;= 0 && i % 3 ;= 0) i?