DreamBerd icon indicating copy to clipboard operation
DreamBerd copied to clipboard

`else` statements after `when` statements are not documented

Open Cifram opened this issue 2 years ago • 2 comments

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.

Cifram avatar Jun 07 '23 10:06 Cifram

Good idea! Would you like to make a PR to fix the example?

TodePond avatar Jun 07 '23 10:06 TodePond

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?

ThePython10110 avatar Jul 06 '24 00:07 ThePython10110