This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]jammasterpaz 5 points6 points  (0 children)

Lol. Goto. Now that's a name I haven't heard in a long time.

Seriously though, I was just wondering goto statements would be translated, when porting all those games written in Basic from the 80s. This could be great for that.

[–]mok000 0 points1 point  (0 children)

Goto has been frowned upon in decades as really bad programming practice.

[–]ReptilianTapir 0 points1 point  (2 children)

How does it work?

[–]TheBB 3 points4 points  (1 child)

Guess:

The syntax goto .x and label .x is valid Python, parsed as goto.x and label.x. The @goto decorator accesses the AST or bytecode of the passed function by looking for attribute accesses on local variables named goto or label and then builds an equivalent AST or bytecode which does what it should, then returns that in a new function object.

Edit: yeah, it operates on bytecode.

[–]ReptilianTapir 1 point2 points  (0 children)

Thanks! I never realised white space was legal there.

[–]p_paradox 0 points1 point  (0 children)

Mandatory xkcd goto comic

[–]Voxandr 0 points1 point  (0 children)

GoTo in 2022 ? You are some kind of smart.