let

Swift 1.2 assigning let after initialization

北慕城南 提交于 2019-12-11 02:19:00
问题 I'm trying to assign a value to a let in Swift 1.2 and its causing a compile error. On Apple's blog it says that this is now allowed The new rule is that a let constant must be initialized before use (like a var), and that it may only be initialized, not reassigned or mutated after initialization. So in my code i made a let a property in my class class SampleClass: NSObject { let idOfSomething:String public func createSomething(idString:String)-> Void { self.idOfSomething = idString } } After

let statement in loop doesn't work as expected in IE

一世执手 提交于 2019-12-10 22:00:05
问题 I am trying some example in ECMAScript 6. That is working differently compared to other browsers. This returns true in Firefox, but it returns false in IE. Why is this working different in Internet Explorer? let callbacks = [] for (let i = 0; i <= 2; i++) { callbacks[i] = function () { console.log(i); return i * 2 } } console.log(callbacks[0]() === 0); console.log(callbacks[1]() === 2); console.log(callbacks[2]() === 4); 回答1: According to caniuse.com IE11 kind of supports let : let variables

Could this do-monad be replaced by a let block?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 17:56:33
问题 The author here provides the following example usage of a do-monad to combine test generators: (require '[clojure.test.check.generators :as gen]) (require '[clojure.algo.monads :as m]) (m/defmonad gen-m [m-bind gen/bind m-result gen/return]) (def vector-and-elem (m/domonad gen-m [n (gen/choose 1 10) v (gen/vector gen/int n) e (gen/element v)] [v, e])) (gen/sample vector-and-elem) ([[0 -1 1 0 -1 0 -1 1] 0] [[1 1 3 3 3 -1 0 -2 2] 3] [[8 4] 8]... There commentator here asserts that this is a

eval a list into a let on clojure

笑着哭i 提交于 2019-12-10 15:46:26
问题 My problem is the next, i try to evaluate a list with some vars using a let to asign values to this vars if i do (def a (list * 'x 'y)) and (let [x 3 y 3] (eval a)) I have a CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_PATH:6) but if I run (def x 4) (def y 4) and (eval a) i have a 16, anyway if I run again (let [x 3 y 3] (eval a)) again I have 16, exist a method to binding the x and y correctly and eval the list? ty! 回答1: Well

Why do I have to wrap an Async<T> into another async workflow and let! it?

拜拜、爱过 提交于 2019-12-10 13:58:35
问题 I'm trying to understand async workflows in F# but I found one part that I really don't understand. The following code works fine: let asynWorkflow = async{ let! result = Stream.TryOpenAsync(partition) |> Async.AwaitTask return result } let stream = Async.RunSynchronously asynWorkflow |> fun openResult -> if openResult.Found then openResult.Stream else Stream(partition) I define a async workflow where TryOpenAsync returns a Task<StreamOpenResult> type. I convert it to Async<StreamOpenResult>

Advantages of define over let

让人想犯罪 __ 提交于 2019-12-10 13:15:13
问题 During a conversation with Matt Flatt, one of the primary authors of Racket, I was told (in passing) that the let form is not recommended by the community and is largely being replaced by define . What are the advantages of define over let that would prompt the Racket community to elect to use it in place of let ? For reference, define and let from the Racket documentation are linked here. 回答1: "To reduce rightward drift" See the section 4.2 on definitions: http://www.ccs.neu.edu/home

How to nest let statements in Haskell?

♀尐吖头ヾ 提交于 2019-12-10 12:37:24
问题 I'm trying to nest a couple let statements, but I'm getting syntax errors that don't make sense to me. I'm really new to Haskell programming so I'm sure it's something I just don't understand (probably having to do with the spacing). I understand that let and in must be in the same column. Why is it that: aaa = let y = 1+2 z = 4+6 in y+z Works perfectly fine, whereas aaa = let y = 1+2 z = 4+6 in let f = 3 e = 3 in e+f gives me the error: "Syntax error in expression (unexpected `=')" 回答1: In

Block scope, function scope and local scope in Javascript

喜你入骨 提交于 2019-12-10 03:34:38
问题 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) 回答1: 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

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

老子叫甜甜 提交于 2019-12-06 21:46:10
问题 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

Clojure: let scope and function return value

回眸只為那壹抹淺笑 提交于 2019-12-06 18:06:26
问题 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 sel-opt-tmp will return a nil value instead than a list. (defn sel-opt-tmp [] (let [cols "test"])) (prn (sel-opt-tmp)) *The above code returns a nil value. I understand that "let" only binds a value in the scope of a function, what I do not know is if