11

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.

wiwo
  • 721
  • 1
  • 13
  • 18

1 Answers1

22

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.

matt
  • 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