I'm learning swift, but i'm not a native english speaker and just want to ask what does 'let' mean? I know its a constant but then why it's not 'cons'? Is 'let' an abbrevation of some word? I won't die without knowing it, i'm just curious ;) Thanks.
Swift employs the keywords let and var for naming variables. The let keyword declares a constant, meaning that it cannot be re-assigned after it's been created (though its variable properties can be altered later). The var keyword declares a new variable, meaning that the value it holds can be changed at a later time.
To declare constants/variables in Swift: let is used to declare an immutable constant. You cannot change the value of it later. var is used to create a mutable variable that you can change later.
In swift, we use the let keyword to declare a constant variable, a constant is a variable that once declared, the value can not be changed.
So the . 0 means the first or zeroth element of the tuple and . 1 means the second element.
There are other languages where let
is used as a keyword before a variable declaration, such as BASIC and LISP (or Scheme), and I presume it was taken from there. It's not an abbreviation; it's the normal English word "let", used to introduce a command, as in "Let there be light;" in mathematics it is common to announce a symbol this way, as in "Let x
be the unknown number of years we are trying to calculate."
To answer your question a little more fully, though: in my view, there is nothing about this word that makes it particularly suitable for constants. They seems to have made an arbitrary choice. var
makes sense for a "variable" that can vary (get it?), so now they just needed another word, and they picked let
. Personally, I think const
would have been better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With