IUCompilerCourse / Essentials-of-Compilation

A book about compiling Racket and Python to x86-64 assembly
1.27k stars 137 forks source link

Python version: why is an arbitrary bare expression a statement? #134

Closed AndrewTolmach closed 11 months ago

AndrewTolmach commented 1 year ago

Why is $exp$ (other than print(...)) allowed as a form of $stmt$ in $\mathcal{L}_{int}$ and subsequent languages up through Ch.7? This seems to complicate the languages with no benefit. And since the results of these expressions are thrown away, these expressions cannot be tested (beyond testing that an input_int() expression evaluates; there are no other relevant side-effects until we get functions in Ch. 8.)

jsiek commented 1 year ago

You make a compelling argument.

The main reason it was done that way was to avoid needing to later change the grammar, interpreters, etc. in Ch. 8 and beyond.

It's not clear to me that all the work of making those later changes would be worth it to avoid having a language feature that is slightly more general than it needs to be.