lazy-evaluation

why using plain val in non-final classes

ε祈祈猫儿з 提交于 2019-12-01 06:28:08
问题 If class is not a final one, it may be extended. There are two possibilities for values: it may be overridden and should be lazy for it, it may not be overridden and should be final. If val is final - you may assume that all computations over it would work through class hierarchy. If val may be overriden you should declare it lazy for not becoming broken after extending. You may leave val plain and this gives no guaranties it would be extended in right way. What use cases imply using plain

Execute raw SQL query in ASP.NET MVC, database first mode

馋奶兔 提交于 2019-12-01 05:52:16
The model of my project is database first, and uses remote access to database on another server. I need to use raw SQL query because my query is very complex and I feel more comfortable in SQl not LINQ. This is how I do: string query = "select * from Inquiry_TBL where ..."; using (educationEntities db = new educationEntities()) { var list = db.Database.SqlQuery<Inquiry_TBL>(query); ViewData["total"] = list.Count(); } The problem is sometimes I get the query result within a second, sometimes it just keep loading for a long time and gives me an error that 'Calling 'Read' when the data reader is

Hibernate mapping setting lazy = 'false'

老子叫甜甜 提交于 2019-12-01 05:34:18
问题 In hibernate mapping, I have set the property lazy="false" , and this fetches all the child records of the parent. This is being used throughout the application. This creates a performance issue at a particular module of my application, wherein I would like to fetch only the parent record. I cant change the lazy property to true since it's being used at many other places. Is there a way to fix this? Do let me know if any more info is required. 回答1: These is no such feature in hibernate as it

Haskell style/efficiency

坚强是说给别人听的谎言 提交于 2019-12-01 05:18:51
So I was working on a way to lazily generate primes, and I came up with these three definitions, which all work in an equivalent way - just checking whether each new integer has a factor among all the preceding primes: primes1 :: [Integer] primes1 = mkPrimes id [2..] where mkPrimes f (x:xs) = if f (const True) x then let g h y = y `mod` x > 0 && h y in x : mkPrimes (f . g) xs else mkPrimes f xs primes2 :: [Integer] primes2 = mkPrimes id (const True) [2..] where mkPrimes f f_ (x:xs) = if f_ x then let g h y = y `mod` x > 0 && h y in x : mkPrimes (f . g) ( f $ g $ const True) xs else mkPrimes f

Avoid or delay evaluation of things which may not be used

≯℡__Kan透↙ 提交于 2019-12-01 04:24:34
How can lazy evaluation be achieved in Python? A couple of simple examples: >>> def foo(x): ... print(x) ... return x ... >>> random.choice((foo('spam'), foo('eggs'))) spam eggs 'eggs' Above, we didn't really need to evaluate all the items of this tuple, in order to choose one. And below, the default foo() didn't really need to be computed unless the lookup key was actually missing from the dict: >>> d = {1: "one"} >>> d.get(2, foo("default")) default 'default' >>> d.get(1, foo("default")) default 'one' I'm looking for a Pythonic way to refactor examples like the above to evaluate lazily. The

Does Prolog use Eager Evaluation?

a 夏天 提交于 2019-12-01 04:02:01
Because Prolog uses chronological backtracking(from the Prolog Wikipedia page) even after an answer is found(in this example where there can only be one solution), would this justify Prolog as using eager evaluation? mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y). parent_child(X, Y) :- father_child(X, Y). parent_child(X, Y) :- mother_child(X, Y). With the following output: ?- sibling(sally, erica). true ; false. To summarize the discussion with @WillNess below, yes, Prolog is

make a lazy var in scala

白昼怎懂夜的黑 提交于 2019-12-01 03:12:48
Scala does not permit to create laze vars, only lazy vals. It make sense. But I've bumped on use case, where I'd like to have similar capability. I need a lazy variable holder. It may be assigned a value that should be calculated by time-consuming algorithm. But it may be later reassigned to another value and I'd like not to call first value calculation at all. Example assuming there is some magic var definition lazy var value : Int = _ val calc1 : () => Int = ... // some calculation val calc2 : () => Int = ... // other calculation value = calc1 value = calc2 val result : Int = value + 1 This

Haskell style/efficiency

放肆的年华 提交于 2019-12-01 02:37:38
问题 So I was working on a way to lazily generate primes, and I came up with these three definitions, which all work in an equivalent way - just checking whether each new integer has a factor among all the preceding primes: primes1 :: [Integer] primes1 = mkPrimes id [2..] where mkPrimes f (x:xs) = if f (const True) x then let g h y = y `mod` x > 0 && h y in x : mkPrimes (f . g) xs else mkPrimes f xs primes2 :: [Integer] primes2 = mkPrimes id (const True) [2..] where mkPrimes f f_ (x:xs) = if f_ x

Execute raw SQL query in ASP.NET MVC, database first mode

空扰寡人 提交于 2019-12-01 02:11:21
问题 The model of my project is database first, and uses remote access to database on another server. I need to use raw SQL query because my query is very complex and I feel more comfortable in SQl not LINQ. This is how I do: string query = "select * from Inquiry_TBL where ..."; using (educationEntities db = new educationEntities()) { var list = db.Database.SqlQuery<Inquiry_TBL>(query); ViewData["total"] = list.Count(); } The problem is sometimes I get the query result within a second, sometimes