let

Scheme let statement

落爺英雄遲暮 提交于 2019-12-06 01:09:03
问题 In scheme which is a functional programming language, there is no assignment statement. But in a let statement (let ((x 2)) (+ x 3)) You are assigning 2 to x , so why doesn't this violate the principle that there is no assignment statements in functional programming? 回答1: The statement "Scheme which is a functional programming language" is incorrect. In Scheme, a functional-programming style is encouraged, but not forced. In fact, you can use set! (an assignment statement!) for modifying the

Better to use “and” or “in” when chaining “let” statements?

≯℡__Kan透↙ 提交于 2019-12-05 12:44:41
问题 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 = "bar" and c = "baz" in (* etc. *) or let a = "foo" in let b = "bar" in let c = "baz" in (* etc. *) My intuition tells me the former ought to be "better" (by a very petty definition of "better") because it creates the minimum number of scopes necessary

Avoid expansion of * in bash builtin function let

扶醉桌前 提交于 2019-12-05 12:05:49
I have a problem with a bash script. I have to use the operator * to multiplicate. Instead the script bugs me with expansion and using as operator the name of the script itself. I tried with single quotes but it doesn't work :( Here's the code #!/bin/bash -x # Bash script that calculates an arithmetic expression # NO PRECEDENCE FOR OPERATORS # Operators: + - * if [ "$#" -lt "3" ] then echo "Usage: ./calcola.scr <num> <op> <num> ..." exit 1 fi result=0 op=+ j=0 for i in "$@" do if [ "$j" -eq "0" ] then # first try #result=$(( $result $op $i )) # second try let "result$op=$i" j=1 else op=$i j=0

Using the “let” kewword in a LINQ Query with EF 4.3

点点圈 提交于 2019-12-05 11:10:45
I have simple LINQ problem that I can't figure out. I have a table Users and a table Employees . One User can have 0...n employees. I'd like to do something like this: var result = from u in context.users where u.UsrId = 2 let e = u.Employees.First() select new { UserId = u.UsrId, FirstName = e.FirstName }; That does not work of course becasue the First() call is illegal. First() can only come at the end of a select . What also did not work is to select the employee in a previous query like so: var employee = from e. in context.Employees..... ...and then say let e = employee instead of let e =

Block scope, function scope and local scope in Javascript

北战南征 提交于 2019-12-05 03:24:41
Is block scope sometimes the same as function scope ? I know function scope is for everything inside a function, but don't get what exactly a block scope is. For Javascript, is it currently recommended to use let / const instead of var for future maintenance? (This was from Airbnb Style Guide ) I'm not sure you really got your questions answered yet: Is block scope sometimes the same as function scope? I know function scope is for everything inside a function, but don't get what exactly a block scope is. Yes , a block scope is sometimes the same as a function scope. Block scope is everything

How can I check if a `let` variable has been declared on ES6?

落爺英雄遲暮 提交于 2019-12-05 02:51:54
Unlike traditional var-declared variables, which are attached to the entire enclosing, function scope regardless of where they appear — let declarations attach to the block scope but are not initialized until they appear in the block So : console.log( a ); // undefined console.log( b ); // ReferenceError! var a; let b; So it seems that hoisting is not applied here. Question If so , how can I safely check if the variable has been declared ? NB - The option I see is try/catch and of course always put the let variables first at scope. but still my question remains it seems that hoisting is not

Custom “let” expression in Scala

岁酱吖の 提交于 2019-12-05 00:57:45
问题 I'd love to have let construct similar to the one in Haskell in Scala. I tried a few ways, but none seems to be good. Here's some code: object CustomLet extends App { val data = for (i <- 1 to 1024; j <- 1 to 512) yield (i % j) * i * (i + 1) - 1 def heavyCalc() = { println("heavyCalc called"); data.sum } def doSomethingWithRes(res: Int) = { println(s"${res * res}") 1 } def cond(value: Int): Boolean = value > 256 // not really usable, even though it's an expression (2x heavyCalc calls) def

Trouble differentiating Rspec's 'let' vs 'let!'

房东的猫 提交于 2019-12-04 07:36:32
I have read the rspec docs and have searched a number of other places but I am having a difficult time grasping the difference between Rspec's let and let! I've read that let isn't initialized until it's needed and that its value is only cached per example. I've also read that let! forces the variable into immediate existence, and forces invocation for each example. I guess since I'm new, I'm having a difficult time seeing how this relates to the following examples. Why does :m1 need to be set with let! to assert m1.content is present on the page, but :user can be set with let to assert that

Chrome console: difference between 'let' and 'var'?

穿精又带淫゛_ 提交于 2019-12-04 07:18:21
I've attached an animated gif to illustrate this weird behavior. Essentially, my question is does Chrome console treat var and let differently when used in the same scope? You'll notice that after declaring / assigning a variable, if you try to type that variable's name into the console, Chrome will autocomplete it for you, showing a dropdown list containing what your typing. When using let s, this is not the case. Is this a bug, feature, or is there something I'm missing about var and let in JavaScript? Note: I'm well aware that let lives & dies within the immediate scope. When you use var in

Scheme let statement

六眼飞鱼酱① 提交于 2019-12-04 05:16:48
In scheme which is a functional programming language, there is no assignment statement. But in a let statement (let ((x 2)) (+ x 3)) You are assigning 2 to x , so why doesn't this violate the principle that there is no assignment statements in functional programming? The statement "Scheme which is a functional programming language" is incorrect. In Scheme, a functional-programming style is encouraged, but not forced. In fact, you can use set! (an assignment statement!) for modifying the value of any variable: (define x 10) (set! x (+ x 3)) x => 13 Regarding the let statement of the question,