Clojure: rest vs. next

As the page you linked described, next is stricter than (the new behaviour of) rest because it needs to evaluate the structure of the lazy cons to know whether to return nil or a seq. rest on the other hand always returns a seq, so nothing needs to be evaluated until you actually use the … Read more

hibernate: LazyInitializationException: could not initialize proxy

The problem is that you are trying to access a collection in an object that is detached. You need to re-attach the object before accessing the collection to the current session. You can do that through session.update(object); Using lazy=false is not a good solution because you are throwing away the Lazy Initialization feature of hibernate. … Read more

Lazy evaluation in C++

I’m wondering if it is possible to implement lazy evaluation in C++ in a reasonable manner. If yes, how would you do it? Yes, this is possible and quite often done, e.g. for matrix calculations. The main mechanism to facilitate this is operator overloading. Consider the case of matrix addition. The signature of the function … Read more

withFilter instead of filter

From the Scala docs: Note: the difference between c filter p and c withFilter p is that the former creates a new collection, whereas the latter only restricts the domain of subsequent map, flatMap, foreach, and withFilter operations. So filter will take the original collection and produce a new collection, but withFilter will non-strictly (i.e. … Read more

What’s so bad about Lazy I/O?

Lazy IO has the problem that releasing whatever resource you have acquired is somewhat unpredictable, as it depends on how your program consumes the data — its “demand pattern”. Once your program drops the last reference to the resource, the GC will eventually run and release that resource. Lazy streams are a very convenient style … Read more

Angular lazy one-time binding for expressions

Yes. You can prefix every expressions with ::, even the ones in ngIf or ngClass: <div ng-if=”::(user.isSomething && user.isSomethingElse)”></div> <div ng-class=”::{classNameFoo: user.isSomething}”></div> Actually, the code simply checks that the two first characters in the expression are : in order to activate the one-time binding (and then removes them, thus the parenthesis aren’t even needed). Everything … Read more

Does Haskell have tail-recursive optimization?

Haskell uses lazy-evaluation to implement recursion, so treats anything as a promise to provide a value when needed (this is called a thunk). Thunks get reduced only as much as necessary to proceed, no more. This resembles the way you simplify an expression mathematically, so it’s helpful to think of it that way. The fact … Read more