5 ms·
So `let` is being used to define a var that is lexically scoped to... the global environment?! I've noticed you can do this in Javascript as well. As a Lisp pro
by j_m_b 7y ago
So `let` is being used to define a var that is lexically scoped to... the global environment?! I've noticed you can do this in Javascript as well. As a Lisp programmer, its very jarring and seems like a bad practice. Is there a reason you would do this?
- dlivingston 7y agoIn Swift, IIRC, `let` defines a constant reference to a value within the current scope.
- hhas01 7y agoCorrect. `let` = constant binding, `var` = variable binding, and except for top-level (global) declarations they are always block scoped. BUT, there is a gotcha: this “constantness” only applies to the name-value binding, not to the value itself. Thus you can still mutate the content of a let-bound value when that value is a class or class instance. Which kinda defeats the point of having the let/var distinction in the first place. C’s `const` may have its priorities backwards, but least it does what it says on the tin. (And let’s not mention what a PITA Swift gets when you want to work with the contents of complex nested struct-based collections in a language that doesn’t have native pointers/references. Again, it makes C look good.)
- jakear 7y agoOnly because the current scope was the global one.
- zapzupnz 7y ago> As a Lisp programmer, its very jarring and seems like a bad practice. As a programmer of any language, guessing at what something does, not verifying that the guess was right, and then complaining about it seems like a bad practice.