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

Module where only first function is called

I've recently picked up F#, and am currently working on a command line utility to help automate some work related tasks. I have implemented a command parser, and a Union for my the different command options, and it all works fine. When I get to the…
Edgars
  • 11
  • 4
0
votes
1 answer

Nested FLET block inside LET block (and vice-versa)

Is it considered idiomatic or non-idiomatic to have a LET block nested inside aFLET/LABELS block ? Again, I may be coming at this all wrong, but I'm trying to mimic the generic where block in Haskell (so I have a defun and I want to write code that…
Krato Form
  • 15
  • 5
0
votes
1 answer

rspec - what is the syntax of before :each and before :all vs let! and let

When can I use let or let! and how can I then refer to variables inside the test? How does the usage of let and let! compare to using before :each and before :all?
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0
votes
1 answer

Ruby - how to replace a before :each with a let?

I have: describe "and for a given song" do before :each do srand(96) @random_song=@playlist.random_song end it "it can get the last letter" do expect(@playlist.ending(@random_song)).to eq 'a' end end I want to move the…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0
votes
4 answers

rspec - how can I refer to a let variable in the it description

I have specs that have: describe "can translate" do let(:from){591} it "#{from}" do expect(Translator.three_digits(from)).to eq 'five hundred ninety two' end end but 591 is hard-coded and repeated which I want to eliminate... so how can…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0
votes
2 answers

rspec - why does a let variable need an @ instance symbol in the it but not in the expect?

For this test: describe "can translate" do let(:from){592} it @from do expect(Translator.three_digits(from)).to eq 'five hundred ninety two' end end I need to refer to from as @from when using it in the it statement but as just from when…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0
votes
3 answers

Counts of repeated elements in a list

This program takes a list where elements are repeated, e.g L = (a a a b b b c c c d), and output a list of items and number of repetition e.g ((a 3)(b 3)(c 3) d) (define counter 0) (define (compress liste) (if (or (null? liste) (null? (cdr…
user3241846
  • 643
  • 3
  • 9
  • 26
0
votes
0 answers

Conditional let query using Entity framework

I have a query where I need to get the value from a view only if there are no results returned from a table used in the right side of a left outer join. Let's take 'left' to be the left table in the join, 'right' to be the right table and…
arviman
  • 5,087
  • 41
  • 48
0
votes
1 answer

OCaml - How to put a let binding inside a match expression?

I have the following code statement: let execute command = match command with |Skip -> () |Changestate (l,r) -> (let l = ref r) |_ -> failwith "Not a command" when I run this in the toplevel, I get the following error: 1 let execute command = 2…
Matt Pennington
  • 560
  • 1
  • 8
  • 21
0
votes
1 answer

RSPEC get ExampleGroup for binding ivars

This one is going to be a tinge interesting. After noting the peculiar behavior of let, I've decided to try and make a direct equivalent of the Lisp Let for RSPEC by binding instance variables to example groups. Here's the code for this so…
baweaver
  • 304
  • 1
  • 12
0
votes
1 answer

Clojure recursion through let binding

From core.clj, the definition of assoc (trimmed of metadata etc) (def assoc (fn assoc ([map key val] (. clojure.lang.RT (assoc map key val))) ([map key val & kvs] (let [ret (assoc map key val)] (if kvs (if (next kvs) …
stephensong
  • 277
  • 1
  • 12
0
votes
2 answers

rspec - how to use let! to setup 2 variables?

I currently have: describe 'least number of moves from x to y' do it 'has a populated chessboard' do @wp='white-pawn' @bp='black-pawn' expect(ChessBoard.new.populate_new_board).to eq [ …
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0
votes
4 answers

Producing a list of Lucas numbers in decreasing order (using let)

Lucas numbers are similar to Fib numbers except it starts with a 2 instead of a 1: 2, 1, 3, 4, 7, 11, 18, I want to write a function to produce a list of Lucas series numbers in decreasing order until the nth element. I wrote this but I traced it…
user3063864
  • 661
  • 2
  • 7
  • 18
0
votes
1 answer

leftmost and lm in Seasoned Schemer

The seasoned schemer on page 78 has the below definition of leftmost and lm. (define leftmost (lambda (l) (letcc skip (lm l skip)))) (define lm (lambda (l out) (cond ((null? l) (quote ())) ((atom? (car l)) (out (car…
user782220
  • 10,677
  • 21
  • 72
  • 135
0
votes
1 answer

gist-vim: change token location

I use gist-vim from mattn together with gVim. Works great and everything but I don't appreciate the auth token laying around in my home directory. So I started looking around in the plugin files and found the variable called s:configfile which the…
Sensei
  • 598
  • 1
  • 4
  • 13