Questions tagged [let]

In Lisp-like and functional languages, introduces a list of local variables, each (possibly optionally) with its initial value.

In Lisp-like and functional languages, introduces a list of local variables, each (possibly optionally) with its initial value. It is illegal to refer to any of the new variables while calculating their initial values ( lets you do that), though in Haskell it is legal (its let is actually letrec).

LET is a special form in Common Lisp, Scheme, Clojure and other Lisp dialects which introduces a list of local variables as pairs of name-value bindings, for use within its body. For instance, in this expression:

(let ((variable1 (+ 1 1)))
  variable1)

variable1 gets bound to the 2 value, and the whole expression returns 2 as a result.

728 questions
21
votes
3 answers

Why is var not deprecated?

Lately after ES6 released, many sources suggested that I use "const" and "let" instead of "var", and that I should stop using "var" in my JavaScript. What I wonder is, if "var" has no advantage over "let" in all points of view, then why didn't they…
Leonard Li
  • 257
  • 1
  • 2
  • 5
20
votes
1 answer

Setting Vim Options with Variables

I've a question that should be fairly simple, but I have yet to find a solution for. I'm editing my .vimrc and would like to set an option using results saved in a variable. For example, I would like to aggregate all my temporary files in…
duckworthd
  • 14,679
  • 16
  • 53
  • 68
19
votes
3 answers

What is the difference between a let block statement and an equivalent with statement?

OBSOLETE The block version of the let statement was dropped from ES6 before it was finalized, and it has been removed from the browsers that supported it. This question is now only of historic interest. Is there any difference between using an…
Jeremy
  • 1
  • 85
  • 340
  • 366
19
votes
1 answer

A javascript 'let' global variable is not a property of 'window' unlike a global 'var'

I used to check if a global var has been defined with: if (window['myvar']==null) ... or if (window.myvar==null) ... It works with var myvar Now that I am trying to switch to let, this does not work anymore. var…
Fai Ng
  • 760
  • 1
  • 6
  • 14
18
votes
2 answers

JS global "let" variable not updating in function?

Edit: I've reported this as a Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=668257 I'm creating a little canvas game in JS with enemies that can shoot. For testing, I created a flag, declared globally as let fancy = true;, to…
qxz
  • 3,814
  • 1
  • 14
  • 29
16
votes
3 answers

Swift 5.5 async let - error: expression is 'async' but is not marked with 'await'

WWDC21 introduces Swift 5.5, with async/await. Following the Explore structured concurrency in Swift and Meet async/await in Swift WWDC21 sessions, I'm trying to use the async let function. Here's my Playground code: func doIt() async -> String { …
drewster
  • 5,460
  • 5
  • 40
  • 50
16
votes
3 answers

ES6 JavaScript - const inside or let outside loop?

For performance purposes, I want to know what the difference is in ES6 JavaScript between: var list = [...]; let item; //let outside the loop for (let i = 0; i < list.length; i++) { item = list[i]; } and var list = [...]; for (let i = 0; i <…
Max K
  • 656
  • 1
  • 6
  • 22
15
votes
1 answer

Difference between where bindings, let bindings and the single assignment operator (<-)

I do not understand the difference between the three syntaxes: where a = f (b) do a <- f (b) do let a = f (b) I do understand somehow though that a <- f(b) is different from the other two, in most cases where I tried all three worked.…
J Fritsch
  • 3,338
  • 1
  • 18
  • 40
15
votes
4 answers

Better to use "and" or "in" when chaining "let" statements?

I realize this is probably a silly question, but... If I'm chaining a bunch of let statements which do not need to know each other's values, is it better to use and or in? For example, which of these is preferable, if any: let a = "foo" and b =…
koschei
  • 819
  • 6
  • 13
15
votes
4 answers

How properly declare a variable in Swift?

I found quite interesting these different ways to declare a variable in Swift: // METHOD 1 var dogName: String = "Charlie" // METHOD 2 var dogName: String { return "Charlie" } // METHOD 3 let dogName = { return "Charlie" } // METHOD 4 var…
Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54
15
votes
2 answers

Initializer for conditional binding must have Optional type, not 'AnyObject - Approach

The following code throws a message which says "Initializer for conditional binding must have Optional type, not 'AnyObject'" func parseData2(){ var data:NSData? if let data2 = data { do { let…
NNikN
  • 3,720
  • 6
  • 44
  • 86
15
votes
1 answer

let var or var to let

In the last couple of months, I've been learning a lot about JavaScript. Having abused the languages for years, I dare say that I now have a better understanding of the language and I've come to love the benefits of its functional nature. Lately…
Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
14
votes
2 answers

What is the scope of let when used without in?

In a Haskell tutorial I ran across the following code: do [...] let atom = [first] ++ rest return $ case atom of Note that the let expression does not have an in block. What is the scope of such a let expression? The next line?
mdm
  • 5,528
  • 5
  • 29
  • 28
14
votes
2 answers

Clojure: let scope and function return value

I am having some troubles figuring how to use the "let" form. In the example below, I would like to locally bind the value "cols" in order to work on it later in the function. What I am noticing, however, is that if I use "let" the function…
kfk
  • 831
  • 2
  • 12
  • 25
14
votes
2 answers

as keyword in angular 4?

Currently am learning about Angular 4 introduced a new keyword : as. AS keyword – A new addition to the template syntax is the as keyword is use to simplify to the let syntax. I have just implement this below code.
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
1 2
3
48 49