IUCompilerCourse / Essentials-of-Compilation

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

`Let` struct first field contract should be a `Var` #64

Closed iambrj closed 3 years ago

iambrj commented 3 years ago

Hello! I would first like to thank you for making such a wonderful resource available for free.

While I was going through the code, I noticed that the contract for the Let struct restricts the variable binding to any arbitrary symbol instead of just Var structs. Ins't the latter choice more appropriate here?

jsiek commented 3 years ago

Dear Bharathi,

Thank you for your interest in Essentials of Compilation!

Consider the following example:

(let ([x 5]) (+ x 2))

The Var struct represents uses of variables, such as x in (+ x 2).

The x in the (let ([x 5) ...) is different, it is a binding site for x, or put another way, it is the definition of x. In that context, the symbol x should be viewed as part of the Let AST and not a separate AST node.

Hope that helps! Jeremy