Tags » Lazy Evaluation

Scala: Lazy vs Non-Lazy evaluations

Function is a first class citizen in Scala, therefore lazy evaluation feels very intuitive and handy in many situations. However recently I encountered a situation where lazy evaluation could be catastrophic if we’re not careful. 876 more words

Scala

How lazy is compiled in Scala

Scalaのlazyというkeywordはどのように実装されているのかを見てみます。確認したプログラムは以下のシンプルなもので、lzというフィルドはlazy valによって宣言されています。

class Foo {
  lazy val lz = 5
}

それでこのプルグラムをコンパイルして、更にJDツールでデコンパイルすると、以下のコードとなります。

public class Foo
{
  private int lz;
  private volatile boolean bitmap$0;

  private int lz$lzycompute()
  {
    synchronized (this) {
      if (!this.bitmap$0) { this.lz = 5; this.bitmap$0 = true;}
      return this.lz;
    }
  }
  public int lz() { 
      return this.bitmap$0 ? 13 more words

Python Generators (Part 2)

So what, then, are the benefits of using generators over regular list-returning functions? The answer is lazy evaluation, and below I’ll give you a few examples of how laziness can be much better than “thoroughness”… 1,158 more words

Python

Randomly Lazy

In the previous article on extending lazy, we extended the lazy views with first_n, which returned a sequence of the first n elements of a sequence. 1,066 more words

Swift

Lambda calculus and the fixed point combinator in chemlambda (VII)

This is the 7th  (continuing from part I  and part II  and part III and part IV and part V and part VI)  in a series of expository posts where we put together in one place the pieces from various places about: 1,118 more words

Chemlambda

Working at being lazy

As teased in the previous article, suppose you want a new kind of lazy evaluation. You want to be able to generate a lazy sequence that represents the first n values of a container. 1,016 more words

Swift