Re:Some Insights from a Julia Developer
by kazinator on Sunday October 15, 2017 @08:52PM
(#15480179)
The article is not convicing me that the language is obeying any poorly designed requirements.
The function f contains a free reference to a variable called a. This is satisfied in some sort of global environment.
Later, f is called from a function in which there is a local a bound to 100. Of course, this a which is local to that function is invisible to the free reference in f which continues to refers to the global a that contains 10.
It could be there is some problem in R, but whatever that is, this article isn't exposing it in a convincing way.
Same thing in Common Lisp (using CLISP):
[1]> (defun f (x) (* a x))
F
[2]> (setf a 10)
10
[3]> (f 3)
30
[4]> (defun g (y) (let ((a 100)) (f y)))
G
[5]> (g 3)
30
The surprise is supposed to be that `(g 3)` doesn't produce 100. Why should it?(It could produce 100 if the symbol a were marked for binding as a special variable; but it isn't. Thus it's just a free variable in f resolved in the global environment, and a lexical binding in g).
Re:Some Insights from a Julia Developer
by icebraining on Saturday October 14, 2017 @01:13PM
(#15473097)
Ah, fair enough, that's definitively weird.
[0] http://andrewgelman.com/2014/01/29/stupid-r-tricks-random-sc...