-
Notifications
You must be signed in to change notification settings - Fork 0
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
Discontinuity in if
vs loop
syntaxes
#1
Comments
Yeah I had considered Additionally, the current syntax gels well with
is allowed, so you don't need to do this:
But I like your idea of using a label at the start of a codeblock to signify that it loops. What do you think of this?
The reason I put the label inside the braces is that |
That's some great reasons, I can understand your thought process. Why can't gotos jump backwards? Is it like a lint bug, that can easily result in infinite loops, so it's banned altogether? Love what you're doing with this language too btw, I've been intrigued by gotos ever since I read about them in the goto Design Note on Crafting Interpreters, which also has a really tidy use case for goto as well. |
The main reason is to try to keep the code understandable. Early return and breaking out of a nested loop are two valid use cases for gotos, and they both only require jumping forward. I think backwards jumps, especially when they cross eachother like
get very unintuitive very quickly. Jumps that are not attached to their own scopes (like
This is perfectly valid if
you can point to the Anyway that's just me rambling. Glad that you like the language. |
That's a really interesting thought process, I never thought about combine scopes with gotos before, it kind of makes sense, but at the same time, I kind of doesn't. I supppose with the loop syntax you currently have (as opposed to using a goto to explicitly go back) makes a lot more sense with scoping, but if the user were to try and explicitly go back for whatever reason and result in defining
And that's essentially how the goto would work from another perspective. And creating a whole new "call frame" for each goto is definitely not the way to go, but that would solve this problem. Certainly an interesting conundrum. And you're welcome! ^^ |
At the moment, you'd need to scan down to the end of a block to see if it
loop
s, whereas with anif
, you can tell right from the start that the following scope can have a possibly of not running, as well as what condition is required to make it do so.Perhaps instead of putting the
loop;
at the end of the block, it would be easier to read putting it near the start. Perhaps something like:(example taken from your readme).
Another option is, instead of using
loop
, you could instead use the wordforever
as it gives more of an idea as to what happens.I can understand why not though, as
goto
statements go at the end of the code to repeat. But then again if that's the case, why not use this syntax and remove loop altogether?The text was updated successfully, but these errors were encountered: