Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'let' in swift mean? [closed]

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.

like image 924
wiwo Avatar asked Jan 19 '15 20:01

wiwo


People also ask

What is a let in Swift?

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.

What's the difference between LET and VAR in Swift?

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.

How do I change the LET value in Swift?

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.

What does .0 mean in Swift?

So the . 0 means the first or zeroth element of the tuple and . 1 means the second element.


1 Answers

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.

like image 195
matt Avatar answered Oct 22 '22 21:10

matt