Re:Swift as a C Language REPL
by dlivingston on Thursday January 02, 2020 @12:55PM
(#21937781)
In Swift, IIRC, `let` defines a constant reference to a value within the current scope.
[ Parent
| on HN ]
Correct. `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.)