On Sun, Apr 4, 2021 at 3:17 AM Stephen J. Turnbull <[email protected]> wrote: > One practical problem with RPN is that one way to break up and "mark" > subexpressions *without* temporary variables is to use (physical) > newlines and indentation. With infix notation > > (minuend # note: parentheses are idiomatic Python line > - subtrahend # continuation > + multiplicand > * multiplier) > > reads well and parses easily in-brain.
Something worth noting - and it's not closely related to this section, but it's near enough and I'm going to quote this as an example - is that complicated expressions can be logically grouped, just like prose can. You have sentences, phrases, words. In the example you give here, "multiplicand * multiplier" needs to be a phrase, since it will be evaluated before the addition and subtraction are. Ideally, the way you lay out the code should correspond to its logical meaning; at very least, it shouldn't contradict it. (minuend - subtrahend + multiplicand * multiplier) Or alternatively: (minuend - subtrahend + multiplicand * multiplier) Algebra gives us a HIGHLY compact notation (far too compact to be truly useful in computing, as it's very blackboard/paper oriented) that does a great job of grouping terms (words) and subexpressions (phrases). Take, for example, this explanation of the Basel problem: https://youtu.be/d-o3eB9sfls?t=881 It's extremely clear that you are summing a series of terms, where each term is the inverse of a square. On the positive side, it's compact and elegant; on the negative side, parentheses group it to make sure you don't negate at the wrong time. But algebra, like shell languages, is ill-suited to general purpose programming. That's why we don't write our code using abuttal to indicate multiplication, or multi-line text with fraction bars inside fraction bars and different sizes of text. Still, the idea of grouping should be the same. Find the parts that logically represent a "phrase" within your "sentence", and gather those together. For instance, here's how I invoke ffmpeg to create a movie clip: subprocess.run([ "ffmpeg", "-i", inputfile, "-ss", str(last_end + int(args.get("trimstart", 0))), "-t", str(start - last_end - int(args.get("trimend", 0))), "-c", "copy", output, "-y", "-loglevel", "quiet", "-stats", ], check=True) Each line is a logical phrase. Run ffmpeg on this file; start at this point; go for this length; copy it to this file; and shut up, I don't need all the noise. Oh, and make sure it succeeds, else bomb. Doing that with RPN doesn't work. It doesn't even make sense. RPN is the assembly code of algebra - it's good at identifying minute steps in a process, it's easy to write an interpreter for it, but it sucks at actually describing someone's intentions. ChrisA _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/CA3K3SRGL2ZSG53JYYW3KYY7C6MSKQH4/ Code of Conduct: http://python.org/psf/codeofconduct/
