Why the free variables in function body don't get bound at function definition time?

It doesn’t happen every day, but debating what-ifs or potential v2 behaviors isn’t off-topic. I’ve debated variable scoping, never got moved to off-topic. It might be moved to Internals and Design, but that’s not necessary either.

To prevent people jumping into the debate with unrelated concepts again, e.g. the confusion over what “transparency” means. Granted, you have a point about programming terminology depending on context, but those contexts are specified and agreed upon, not individually generated. Even disagreements warrant the respect of mutually intelligible discussion.

See how Base.stdout (but not stderr) is assigned to a different stream depending on how the Julia process is piped in the command line? Let’s put that in practice:

PS C:\#=not where you want=#> cd #=wherever you want=#
PS C:\#=wherever you want=#> julia -e 'println(""Hello world"")'
Hello world
PS C:\#=wherever you want=#> julia -e 'println(""Hello world"")' > hello.txt

(Excuse the double quotes, I’m on Windows and using Powershell.) No printout the second time, but now we have a hello.txt file in the path. If we open it, we find the text Hello world. That happened with the exact same println(x) code, so we didn’t need (or want to) refactor everything to println(io, x) inside explicit file-handling. That’s especially important for code we didn’t write, which often don’t have methods taking an extra IO argument (in fact, macro bodies can’t, only generate function calls that can). This is an expected feature of printing in particular.

1 Like