Re:Children's mental models of recursive LOGO programs (1985)
by Jensson on Thursday July 11, 2024 @04:14PM
(#40940210)
In a brace language you paste the bracers as well and it works, as long as all names are fully qualified and you ignore visibility restrictions.
[ Parent
| on HN ]
Re:Children's mental models of recursive LOGO programs (1985)
by trealira on Thursday July 11, 2024 @04:59PM
(#40940557)
Most programming languages today don't have dynamic scoping. Here's something you could do in a language that had it.
print_x() {
print(x);
}
foo(msg) {
let x = msg;
print_x();
}
main() {
let x = "Hello!";
print_x();
foo("Goodbye!");
print_x();
}
In a language with dynamic scoping, this would print: Hello!
Goodbye!
Hello!
With lexical scoping, most dynamically scoped code would either be a compilation error, or it wouldn't work. In this case, the language would complain that x wasn't defined in the scope of "print_x()". With lexical scope, you'd have to make x a global variable, and then the function foo() would just be equivalent to calling print_x().
Re:Children's mental models of recursive LOGO programs (1985)
by antonvs on Friday July 12, 2024 @02:52PM
(#40948340)
Aside from the dynamic scope issue I mentioned (which someone else has expanded on), this doesn't work for languages that support closures. "Fully qualifying" names doesn't help there. And OO languages would have similar issues for much the same reason.