munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.42k stars 1.01k forks source link

Question about challenge 10.3 #1151

Closed ppk03 closed 4 months ago

ppk03 commented 6 months ago

Since variable redifinition is allowed in Lox, this code seems to be valid:

fun scope(a) { // put "a" into environment
  var a = "local"; // redefine is allowed
}
var a = "global";
scope(a);
munificent commented 5 months ago

Lox only allows redefining top level global variables, not locals.

ppk03 commented 4 months ago

This really solve my question, thanks.