Closed Felienne closed 3 years ago
Placing some thought for myself about this issue for later reference:
The reason this happens that is Hedy sometimes produces invalid Python. When the invalid code is ran, Skult produces an error, of which we output just "bad input". Sadly the more detailed info (f.e. SyntaxError or RunTimeError) is not (easily) available.
Here's a discussion for you @fpereiro to think about with me... The issue is that in Level 3 and up, we do not require '' around strings, but some kids use it (probably because they know it form other places/parents think it is needed or they generalize from print where it is needed.
What to do with this?? We can remove the ''?
Or escape so it ends up in the string?
What do you think? The final might make it more clear that they are not needed?
We can of course also catch and then give a warning (or error even, if we want?)
@Felienne interesting question!
I really like the second option, of consider quotes as non-special characters until they become part of the syntax. So, if you put quotes, we merely return them. It keeps things consistent: either the characters are non-special (non-syntactic) or they are. It also gives it an "arcade" feeling, of throwing something at Hedy and Hedy returning it back unchanged (unless the quote means something syntactically). And for those who know that quotes are used to, um, quote strings, it might surprise them too in a good way. If we can help along the realization that a character can stand for itself or as a syntactic entity, this would be amazing.
Implementation wise, it means we'd have to escape the quotes.
Do we require quotes at a certain level? (embarassing of me to ask at this stage!) If so, after that point, the quotes are mandatory and if you want to print quotes, you'll actually have to escape them!
I really like the second option, of consider quotes as non-special characters until they become part of the syntax. So, if you put quotes, we merely return them. It keeps things consistent: either the characters are non-special (non-syntactic) or they are. It also gives it an "arcade" feeling, of throwing something at Hedy and Hedy returning it back unchanged (unless the quote means something syntactically).
Yeah that was the same reasoning I though when I build that option! Let's go for it then.
And for those who know that quotes are used to, um, quote strings, it might surprise them too in a good way. If we can help along the realization that a character can stand for itself or as a syntactic entity, this would be amazing.
Yeah I was hoping that could happen sometimes too, let's see!
Implementation wise, it means we'd have to escape the quotes.
Yeah that's not hard, in fact I already build it, the images above were actual runs not photoshopped.
Do we require quotes at a certain level? (embarassing of me to ask at this stage!) If so, after that point, the quotes are mandatory and if you want to print quotes, you'll actually have to escape them!
They are mandatory from Level 3, but I am not sure if we want to teach quotes and also escaping at the same time! I could be a separate level... But that's for another day.
Hi @Felienne ! Agreed on all points. And escaping definitely should be done later. I like the idea of putting a cliffhanger there for kids that want to figure out how to print quotes when quotes become syntactic. It seems like that could be a level of its own, and quite later too.
Good to know there's no photoshop involved... I wonder what would take more effort, if photoshop or directly changing the grammar!
This change had already been merged into master (not sure when, oops) so this can be closed for now, although there might be other cases of bad input when invalid Python is generated.
f.e. this code at level4: