lazy-evaluation

Equational reasoning with tying the knot

◇◆丶佛笑我妖孽 提交于 2019-12-08 17:28:16
问题 I'm trying to wrap my head around Cont and callCC, by reducing this function: s0 = (flip runContT) return $ do (k, n) <- callCC $ \k -> let f x = k (f, x) in return (f, 0) lift $ print n if n < 3 then k (n+1) >> return () else return () I've managed to reach this point: s21 = runContT (let f x = ContT $ \_ -> cc (f, x) in ContT ($(f,0))) cc where cc = (\(k,n) -> let iff = if n < 3 then k (n+1) else ContT ($()) in print n >> runContT iff (\_ -> return ())) And at this point i have no idea what

Is Sql Server's ISNULL() function lazy/short-circuited?

独自空忆成欢 提交于 2019-12-08 17:03:54
问题 TIs ISNULL() a lazy function? That is, if i code something like the following: SELECT ISNULL(MYFIELD, getMyFunction()) FROM MYTABLE will it always evaluate getMyFunction() or will it only evaluate it in the case where MYFIELD is actually null? 回答1: It's whichever it thinks will work best. Now it's functionally lazy, which is the important thing. E.g. if col1 is a varchar which will always contain a number when col2 is null, then isnull(col2, cast(col1 as int)) Will work. However, it's not

Segfault reading lazy bytestring past 2^18 bytes

这一生的挚爱 提交于 2019-12-08 16:37:19
问题 Consider the following code: http://hpaste.org/90394 I am memory mapping a large 460mb file to a lazy ByteString. The length of the ByteString reports 471053056 . When nxNodeFromID file 110000 is changed to a lower node ID, ie: 10000 , it works perfectly. However; as soon as I try and serialize anything past exactly 2^18 bytes ( 262144 ) of the ByteString I get Segmentation fault/access violation in generated code and termination. I'm running Windows and using GHC 7.4.2. Please advise whether

How to get distinct items from a Scala Iterable, maintaining laziness

感情迁移 提交于 2019-12-08 16:27:17
问题 I have a java.lang.Iterable which computes its values lazily. I am accessing it from Scala. Is there a core API way of returning only distinct values? For instance, imaging there was a filter method that also provided all results returned thus far: val myLazyDistinctIterable = iterable.filter((previousReturnedItems, newItem) => previousReturnedItems.contains(newItem)) I guess this is not a very general case because it involves storing previously returned items, and that might be why it isn't

When are F# function calls evaluated; lazily or immediately?

佐手、 提交于 2019-12-08 14:44:00
问题 Curried functions in F#. I get the bit where passing in a subset of parameters yields a function with presets. I just wondered if passing all of the parameters is any different. For example: let addTwo x y = x + y let incr a = addTwo 1 let added = addTwo 2 2 incr is a function taking one argument. Is added an int or a function? I can imagine an implementation where "added" is evaluated lazily only on use (like Schroedinger's Cat on opening the box). Is there any guarantee of when the addition

How to create a memory efficient Ruby Pipe class with lazy evaluation?

天涯浪子 提交于 2019-12-08 08:35:03
问题 I would like to create a Pipe class to emulate Unix commands in Ruby in a two step fashion. First step is to compile a pipeline by adding a number of commands, and the second step is to run that pipeline. Here is a mockup: #!/usr/bin/env ruby p = Pipe.new p.add(:cat, input: "table.txt") p.add(:cut, field: 2) p.add(:grep, pattern: "foo") p.add(:puts, output: "result.txt") p.run The question is how to code this using lazy evaluation , so that the pipe is processed record by record when run() is

Django deferring save() of graph of model objects / transactionally create models

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 07:10:52
问题 I'm creating a bunch of model objects that refer to each other, like so: link = DirectorsIndividual(company = co, individual = individual, director = officer) Where co , individual , and officer are unsaved model objects. Because they're unsaved, they don't yet have ids, so saving link will cause an error. I want to either create and save all of my objects, or none of them. Is there a standard pattern for doing this? I'm doing this because I care about "transactionality"; minimising database

Lazy Load on MULTIPLE horizontal containers

白昼怎懂夜的黑 提交于 2019-12-08 03:13:41
问题 I'm using Lazy Load jQuery plugin: http://www.appelsiini.net/projects/lazyload My question is: is it possible to have multiple scrolling containers each with a lazyload images inside, like this: $("#container1 img.lazy").lazyload({ container: $("#container1")}); $("#container2 img.lazy").lazyload({ container: $("#container2")}); When I do this it seems to only keep track of the most recently called. I tried to call the function two times (one for each container) but it didn't work, I also

dplyr standard evaluation: summarise_ with variable name for summed variable

天涯浪子 提交于 2019-12-07 14:41:12
问题 I went through a lot of questions that are similar to mine but only addressed one part of my problem. I am using dplyr with standard evaluation to accommodate variable names. This works fine for filter_ and group_by_ in a pipe. However, for summarize I cannot have a variable name for the metric I'm summing. An example will make it clear. library(dplyr) library(lazyeval) # create data a <- data.frame( x = c(2010, 2010, 2011, 2011, 2011), y_zm = c(rep(10, 5)), y_r2 = c(rep(20, 5))) # define

Laziness in C++11

拥有回忆 提交于 2019-12-07 13:03:05
问题 Do you know how to perform a lazy evaluation of string, like in this D snippet: void log(lazy string msg) { static if (fooBarCondition) writefln(…) /* something with msg */ } Actually, the problem might not need laziness at all since the static if. Maybe it’s possible to discard char const* strings when not used? Like, in C++: void log(char const *msg) { #ifdef DEBUG cout << … << endl; /* something with msg */ #else /* nothing at all */ #endif } Any idea? Thank you. 回答1: #ifdef DEBUG #define