lazy-evaluation

Lazy Evaluation not so Lazy?

旧时模样 提交于 2019-12-11 03:24:25
问题 I've always heard C# uses lazy evaluation. So for certain code like, if (true || DoExpensiveOperation() will return true without executing DoExpensiveOperation() . On an interview test I saw the following questions, static bool WriteIfTrue(bool argument) { if (argument) { Console.WriteLine("argument is true!"); } return argument; } static void Main() { // 1 0 0 1 WriteIfTrue((WriteIfTrue(false) & WriteIfTrue(true)) || WriteIfTrue(true)); // 1 1 0 1 WriteIfTrue((WriteIfTrue(true) ||

Using Spring @Lazy and @PostConstruct annotations

左心房为你撑大大i 提交于 2019-12-11 03:09:02
问题 I have following classes: @Repository class A { public void method1() { ... } } @Component class B implements C { @Autowired @Lazy private A a; public void method2() { a.method1(); } } @Component class D { @Autowired private List<C> c; @PostConstruct public void method3() { // iterate on list c and call method2() } } Let's suppose Spring initializes the beans as following: 1. First bean B is created. When bean B is being created, field a will not be initialized because of the @Lazy annotation

Lazy loading using nodejs and mongoDB as backend data

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:36:56
问题 Our collection has around 100 million documents. We created a simple application using nodejs and expressjs with a limit clause in the mongo query . It is sufficient for the users as of now. In the mean time we are trying to implement lazy loading so that the initial page load returns few documents and when the user scrolls we would like to load further documents. Struggling where to start and how to ahead to implement it. Appreciate your suggestions. My index.js file would look like this

How can I have PHP avoid lazy evaluation?

眉间皱痕 提交于 2019-12-11 02:32:58
问题 I have an interesting question about the way PHP evaluates boolean expressions. When you have, for example, $expression = $expression1 and $expression2; or if ($expression1 and $expression2) PHP first checks if $expression1 evaluates to true . If this is not the case, then $expression2 is simply skipped to avoid unnecessary calculations. In a script I am writing, I have: if ($validator->valid("title") and $validator->valid("text")) I need to have the second statement ( $validator->valid("text

Any merit to a lazy-ish juxt function?

余生颓废 提交于 2019-12-11 01:42:13
问题 In answering a question about a function that maps over multiple functions with the same arguments (A: juxt), I came up with a function that basically took the same form as juxt, but used map: (defn could-be-lazy-juxt [& funs] (fn [& args] (map apply funs (repeat args)))) => ((juxt inc dec str) 1) [2 0 "1"] => ((could-be-lazy-juxt inc dec str) 1) (2 0 "1") => ((juxt * / -) 6 2) [12 3 4] => ((could-be-lazy-juxt * / -) 6 2) (12 3 4) I have little clue about the laziness or performance of it,

Haskell: Alternative, non-circular definition of Redex?

江枫思渺然 提交于 2019-12-10 22:35:59
问题 I got quite confused about what is and is not a redex in Haskell, so I spent some time on it, but I would like feedback whether I got it right. I found this definition of a redex, and it is circular; Etymology : From "reducible expression" Definition: Redex (plural redexes): (mathematics) Something to be reduced according to the rules of a formal system. http://en.wiktionary.org/wiki/redex The above definition presumes one knows how to reduce. So to me this is like saying "Bluish is the

How do I make a Scalaz ZIO lazy?

 ̄綄美尐妖づ 提交于 2019-12-10 19:56:19
问题 I have a heavy side-effecting function (think database call) that I want to use as a lazy value, so that it gets called only on first use (and not at all if never used). How do I do this with ZIO? If my program looks like this, the function gets called only once (but even the result is not used at all): import scalaz.zio.IO import scalaz.zio.console._ object Main extends scalaz.zio.App { def longRunningDbAction: IO[Nothing, Integer] = for { _ <- putStrLn("Calling the database now") } yield 42

Weak head normal form and order of evaluation

旧巷老猫 提交于 2019-12-10 19:52:15
问题 I've read lots on weak head normal form and seq. But I'm still have trouble imagining the logic behind Haskell's order of evaluation A common example demonstrating when and how to use but I still don't understand how the common example foldl (+) 0 [1..5000000] can result in a stack overflow. While another fold definition using seq doesn't foldl' _ a [] = a foldl' f a (x:xs) = let a' = f a x in a' `seq` foldl' f a' xs foldl' (+) 0 [0..5000000] From explanations of seq that I've read, authors

How to write an NES function that also takes character input?

陌路散爱 提交于 2019-12-10 18:46:02
问题 I´m working on a R package that takes strings as function arguments. Now I want to use non-standard evaluation to allow for non-string input. Also, to keep the backwards compatibility, I´d like to keep the possibility for the functions to take strings. Hadley gives an example with the subset function and suggests that every NES function should be accompanied by a standard evaluation function. library(lazyeval) # standard evaluation subset2_ <- function(df, condition) { r <- lazy_eval

Stack space overflow with the ST monad

假装没事ソ 提交于 2019-12-10 18:05:00
问题 The following short Haskell program is intended to count a list of items from a file. The version using foldl' works fine, but the version using the ST Monad gives a stack space overflow message. Clearly there's a space leak of some sort here, but I haven't been able to solve it. The really interesting part is that the ST monad is supposed to be doing in-place updates and shouldn't be letting resources grow like this, although that may only pertain to main memory and not stack space. Could