haasn / -g-pl

/g/ programming language
13 stars 2 forks source link

gb2 needs a rework #13

Closed haasn closed 13 years ago

haasn commented 13 years ago

At the moment, “gb2” works like a “break” statement in other languages does - it breaks out of the current block (eg. conditionals, loops, evaluation blocks, functions etc.). This, however, means that there's no equivalent to a “return” statement.

We will effectively have to create a second alternative to gb2 and have one serve as a “break” and the other as a “return”. Ideas for what this “return” (or “break”) statement could look like?

graydude commented 13 years ago

Could you please post an example of how you see gb2 being used? I really see this as a return/exit. On the highest level, it exits the process and if the variable passed is an integer that's the exit code, in functions it is used as a return.

If we don't implement threads, /thread could be a break.

daskterpthrad commented 13 years ago

I preferred [expression].jpg for return, especially with the new void value. Any function returning void:

forever alone.jpg

graydude commented 13 years ago

That would be nice. But I'd still like gb2 for top level stuff.

haasn commented 13 years ago

Then .jpg shall be break? I assume this means we have to disallow . in names as well?

graydude: As it's in the spec right now, “gb2” will break out of blocks (and as mentioned, the top level file behaves like a huge block, the { and } are added during preprocessing). This means a function like >function { >mfw "this and" gb2 "that" } will return "that" because the { } block surrounding it belongs to the function. It doesn't explicitly deal with functions, a function that simply returns "that" could have been written >function "that". It will thus have the (potentially undesired) effect of also breaking out of conditionals or other blocks.

haasn commented 13 years ago

Closing this, see issue #12 for more information.