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.
-
2Already described here: http://stackoverflow.com/questions/24002999/how-exactly-let-keyword-works-in-swift – gagarwal Jan 19 '15 at 20:06
-
1let is itself an English word. Not abbreviated. – Catfish_Man Jan 19 '15 at 20:09
-
@gagarwal No, he's not asking how it's used, he's asking what the term itself means in a foreign language (English). – matt Jan 19 '15 at 20:16
-
http://en.wiktionary.org/wiki/let#Etymology_1 – famousgarkin Jan 19 '15 at 20:16
-
Note that in @famousgarkin's etymology link, case 6 is the point of interest. – David Berry Jan 19 '15 at 20:45
-
2I think this may be off-topic because it's about the vagaries of the English language and not programming. – David Berry Jan 19 '15 at 20:45
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.

- 515,959
- 87
- 875
- 1,141
-
However, at that point we have sunk into the realm of opinion and guesswork, which is not a suitable topic for Stack Overflow. – matt Jan 19 '15 at 20:19
-
My guess is actually that it stems from the functional/haskell background of swift, where "=" in a declaration is pronounced "is" or "be", similar to pascal and meta languages which use <- or := as pronounced "becomes" Fundamental to functional programming is the lack of variables, instead only having constants, hence "let" is a normal constant expression. "var" denotes an exception to the declaration rules allow modification. "let a = 10" is then pronounced "let b be 10" and it makes sense. – David Berry Jan 19 '15 at 20:43
-
@David Thanks, I wondered if it might be some language I didn't know (though my mention of LISP, which is purely functional as you can get, does cover it). – matt Jan 19 '15 at 20:53
-
Yeah, the usage at that point is really very similar to the math usage of the term. – David Berry Jan 19 '15 at 20:58