let

F#: Destructuring bind with a discriminated union

你离开我真会死。 提交于 2019-12-12 10:36:51
问题 open System let x = (1, 2) let (p, q) = x printfn "A %A" x printfn "B %A %A" p q let y = Some(1, 2) try let None = y () with | ex -> printfn "C %A" ex let Some(r, s) = y printfn "D %A" y // printfn "E %A %A" r s http://ideone.com/cS9bK0 When I uncomment the last line, the compiler rejects the code complaining /home/rRiy1O/prog.fs(16,19): error FS0039: The value or constructor 'r' is not defined /home/rRiy1O/prog.fs(16,21): error FS0039: The value or constructor 's' is not defined Is it not

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

人盡茶涼 提交于 2019-12-12 05:59:08
问题 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 title =' expression does no unbox it anymore? What should I do to unbox in the if? // Go thru all publication where the tag has been found for item in items { if let item = item as? [String: String?], let title = item["label"] { i += 1 if let

Scheme rewrite let* as nested unary lets

China☆狼群 提交于 2019-12-12 05:29:01
问题 I have written a function match-rewriter that is essentially match-lambda except that it returns its argument if no match is found: (define-syntax match-rewriter (syntax-rules () ((_ (patt body) ...) (λ (x) (match x (patt body) ... (_ x)))))) Now I would like to use match-rewriter to take strings representing source code for let* and rewrite it as nested unary lets : (define let*→nested-unary-lets (match-rewriter (`(let*((,<var> ,<val>) ...) ,<expr1> ,<expr2> ...) I am really stumped over how

Let variables and block scope

梦想的初衷 提交于 2019-12-12 04:57:26
问题 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 variable name 'student'? (function (){ let student = {name: 'James'}; function createStudent(name){ if(true){ let student = {name: name}; } return student; } console.log(createStudent('Ken')); console.log(student); })(); 回答1: let is block scoped so this

javascript let not working in various browsers

旧城冷巷雨未停 提交于 2019-12-11 20:08:31
问题 let doesnt't work in some browsers. Not in their interpeters/ web consoles either. Why? (originally I thought there was an inconsistency b/t the browser interpeter and the jsFiddle, but it turns out not to be true, just bad tests on my part.) 回答1: It is a non-standard keyword introduced in JS 1.7, not necessarily implemented in different browsers. https://developer.mozilla.org/en/JavaScript/Reference/Statements/let 回答2: In order to use some of the new features of JavaScript 1.7, you need to

Local state of a variable

帅比萌擦擦* 提交于 2019-12-11 08:28:08
问题 I am trying to fully understand Objects and local states of their variables This code seems to produce different results for the same procedure called multiple times, meaning the local variable changes: (define new-withdraw (let ((balance 100)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")))) For this other code, it produces the same result, which means it creates a new local variable for every procedure call: (define (make

Where are global let variables stored? [duplicate]

一曲冷凌霜 提交于 2019-12-11 07:35:48
问题 This question already has answers here : Do let statements create properties on the global object? (5 answers) Closed 2 years ago . I have created a navigator variable in global scope and assign it a string using let keyword. // in a browser let navigator = "Hello!"; console.log(navigator ); // "Hello!" console.log(window.navigator === navigator ); // false Here let navigator value shadows the window.navigator . But I am very curious to know where exactly the let navigator gets stored in? 回答1

LINQ to Populate a range

这一生的挚爱 提交于 2019-12-11 06:49:40
问题 I can't figure out how to do the second part of this (the for/foreach) with a LINQ expressions and haven't found any similar examples with LINQ. rangeDays will be between about 5 and 200, and q1 is a list of MyClasses where RowID is about from 10000 to 25000, without gaps. public class MyClass { public int RowID; public object otherData; } PopulateRange(int rangeDays, List<MyClass> q1){ var q2 = (from a in q1 let Rows = new int[rangeDays] select new {a.RowID, Rows }).ToList(); foreach(var a

Custom Method in LINQ Query

亡梦爱人 提交于 2019-12-11 06:46:36
问题 I sum myself to the hapless lot that fumbles with custom methods in LINQ to EF queries. I've skimmed the web trying to detect a pattern to what makes a custom method LINQ-friendly, and while every source says that the method must be translatable into a T-SQL query , the applications seem very diverse. So, I'll post my code here and hopefully a generous SO denizen can tell me what I'm doing wrong and why. The Code public IEnumerable<WordIndexModel> GetWordIndex(int transid) { return (from

why is base only possible in private members?

匆匆过客 提交于 2019-12-11 04:08:44
问题 I have some understanding of the difference between private members and let bindings. It may help me clarify my doubts understanding why something like this is not possible type B () = inherit A () let doSomething () = base.CallToA () Is it to prevent partially constructed objects or some leaks during construction? 回答1: The base keyword is only really needed to call a base-class implementation of a virtual method. That is the only case where you need base because you cannot invoke the method