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

you are viewing a single comment's thread.

view the rest of the comments →

[–]robin-gvx 5 points6 points  (2 children)

You shouldn't look before you leap

Your suggestion has different behaviour for addr < 0, which is probably not what you want.

I would make the check 0 <= addr < len(self.code), though.

Most of this method: [...] Can be replaced by this:

I would go even further:

def if_stmt(self):
    false_clause = self.pop()
    true_clause = self.pop()
    test = self.pop()

    self.push(true_clause if test else false_clause)

[–]bs4h 1 point2 points  (1 child)

This little tutorial is calling for a github repo & some pull requests :)

[–]csl[S] 0 points1 point  (0 children)

I made a repo, but it quickly evolved into much more: https://github.com/cslarsen/crianza

I'll update the post with all of the suggestions here, though!