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
0
votes
2 answers

Let variables and block scope

Why does the first console log print out "James" when it should print out "Ken"? Shouldn't the let 'student' variable be scope to the 'if-statement' and retain its value as "Ken"? Also, shouldn't there be an error as I'm redeclaring the same…
Johnny G.
  • 447
  • 3
  • 7
  • 12
0
votes
2 answers

Common Lisp let function

I'm just starting to program in Common Lisp and going back through programs that I coded during some of my previous classes to learn and I am having trouble understanding the problem in my code. (defun input-1 () (defvar *message*…
Mitchell
  • 15
  • 1
  • 6
0
votes
2 answers

How to use let declarations as expressions?

I want to use let expressions, but the following code doesn't work: true ? (let x=1, let y=2, x+y) : (let x=3, let y=4, x-y); // SyntaxError How am I supposed to do this?
user6445533
0
votes
1 answer

Rspec let hash key unexpected =>, expecting '}'

I am confusing in using ruby hash key format and let. This works in normal case. { "id" => 1, "description" => "test 3", "difficulty" => { "id" => 1, "description" => "easy" }, } but fails in let block Here's the code: describe…
rj487
  • 4,476
  • 6
  • 47
  • 88
0
votes
1 answer

Undefined symbols for architecture x86_64 flex/bison

I am trying to make a simple toy (LET) language as practice using flex/bison. However, I keep getting the following error when I run the command g++ -Wall -std=c++11 repl.cpp -v -o LET: Undefined symbols for architecture x86_64: …
M. Barbieri
  • 512
  • 2
  • 13
  • 27
0
votes
2 answers

Scheme using input parameter in inner function

I'm new to Scheme and to functional programming in general. As part of an exercise, I try to implement a function that that takes a number n and prints line by line first n Fibonacci numbers The problem is that when the program reaches the recursive…
Noam
  • 1,640
  • 4
  • 26
  • 55
0
votes
1 answer

Haskell let ..... in let ..... in let

got some code to complete. But I don't know how to handle the nasted let in expression. Thats the code: data Zutat = Tomate | Fleisch | Salat data Bun = Weizen | Roggen data Sosse = Ketchup Sosse | Mayo Sosse | Keine data Burger = Burger Bun…
0
votes
1 answer

Clojure, replacing vars in let bindings causes performance issue?

Let's say there is a function and it received a json string which contains about 100KB of data. The string gets converted to a map and then it keeps associating new keys to that map and replacing the var in let bindings like below: (defn myfn …
gini09
  • 259
  • 3
  • 13
0
votes
0 answers

Unable to declare a variable within *ngFor angular2

I am trying to declare a variable of my own within *ngFor but it throws error and is not working. I loop through a collection of buttons, and show icon whenever the condition inside *ngIf is satisfied.
0
votes
1 answer

Why 'if let' does not seem to unbox a value as before in Swift 3 in Xcode 8.3 beta?

Unlike before, I was surprised to see that 'title' is now an optional (the compiler now generates the waning : String interpolation produces a debug description for an optional value; did you mean to make this explicit?). How it comes the 'if let…
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
0
votes
2 answers

Ocaml syntax error in a simple if-then-else

I want to change some code written in C into Ocaml Here is a C code int a, b; if(m > n) { a = n; b = m; } else { a = m; b = n; } and I tried to change it into Ocaml but somehow I got a syntax error at the second line. let rec gcd…
Dagoo Mong
  • 107
  • 1
  • 12
0
votes
0 answers

Mozilla Possible let vs var Bug

Please consider the following JavaScript code: let funcs = [] for(let x of [1,2,3]) { funcs[x] = function(){ console.log("test:", x) } } funcs[1]() funcs[2]() funcs[3]() When I run this code in Google Chrome V55.0 it generates the…
d3newguy
  • 11
  • 4
0
votes
1 answer

If let statement error

Im trying to build a todo list with coreData, my goal is to have an error pop-up notification if a user tries to just click the "add" button without entering any text in the text-field. I currently have the pop-up notification working but once i…
0
votes
0 answers

Is let a get only variable?

I'm a little bit confused with this. We have variables in swift that can have a setter, getter or both and constants which can't change his own initial value, So, is a var with only a getter the same as a let? If it is, what is the idea in a…
user3175133
  • 325
  • 3
  • 8
0
votes
1 answer

let: bad syntax (not an identifier and expression for a binding) in: wordslist ###scheme

(define (most-common-word str) (let (wordslist str-split str " "))) I am trying to do a inner variable of lists of strings. but I get the error "bad syntax". I looked for answers here but the things I changed, didn't help. str-split returns a…
shay C
  • 51
  • 2
  • 7