Questions tagged [lazy-evaluation]

Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses of its, so that no expression need be evaluated more than once.

Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses thereof, so that no expression need be evaluated more than once.

2555 questions
2
votes
1 answer

Using Nessos.Stream to reduce the time to get and write query output to a `.CSV`

In the past, I have written queries that just get the entirety of the query, store the results in memory, then feed the whote sequence to a .CSV type provider. A query example: let results = query { for row in db.ThisRow do …
Steven
  • 3,238
  • 21
  • 50
2
votes
1 answer

map not quite lazy?

map doesn't seem quite as lazy as I would like, in this example map calls the function one time as I would expect: (first (map #(do (println "x: " %) %) '(0 1))) but in these two examples it calls the function two times: (first (map #(do (println…
Hob Nilre
  • 23
  • 3
2
votes
1 answer

Benchmarking and lazy evaluation

What is wrong here, is Lazy Evaluation too? teste.hs module Main where import Control.Parallel(par,pseq) import Text.Printf import Control.Exception import System.CPUTime import Data.List import IO import Data.Char import…
Gmp
  • 179
  • 10
2
votes
2 answers

Lazy evaluation steps : filtering a list

I have some questions regarding lazy evaluation in Scala. This is the sample code: val people=List(("Mark", 32), ("Bob", 22), ("Jane", 8), ("Jill", 21), ("nick", 50), ("Nancy", 42), ("Mike", 19), ("Sara", 12), ("Paula", 42), …
FaY
  • 103
  • 6
2
votes
2 answers

Could a bored AWK master kindly convert this Python program?

I love Python but do not really care for AWK. For purposes of comparison (and to see how a Python-to-AWK master would do this), could someone rewrite the following Python program in AWK? Considering how short it is, some would think that the rewrite…
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
2
votes
1 answer

reduce and map on accumulator produces stack overflow

Why do I need to replace map with mapvin this piece of code to prevent a stack overflow: #!/bin/bash lein-exec (println (reduce (fn [acc _] …
user3639782
  • 487
  • 3
  • 10
2
votes
2 answers

Global CAFs in `where` blocks - Haskell

I'm going to implement a function which takes in an Integer and outputs a lazy, infinite list of coprime Integers. coprime 2 = [1,3..] coprime 3 = [1,2,4,5,7,8,....] I expect that these lists will be accessed multiple times, so I want their values…
Myridium
  • 789
  • 10
  • 20
2
votes
4 answers

Java grouping in stream

Java 8 streams allow us to collect elements while grouping by an arbitrary constraint. For example: Map> grouped = stream .collect(groupingBy(myThing -> myThing.type())); However this has the drawback that the stream must be…
kag0
  • 5,624
  • 7
  • 34
  • 67
2
votes
2 answers

Thread-safe lazy get and release

I'm running into kindof an annoying problem and would need some advice... Let's say I have a bunch of small MyObject's, that can construct bigger MyExtendedObject's. MyExtendedObject's are big and CPU consuming so construction is lazy, and I try do…
Julio
  • 360
  • 1
  • 3
  • 7
2
votes
1 answer

Clojure Core Cache Stackoverflow

Here's a namesake question for this site. Why does this piece of code throw a StackOverflow exception in Clojure? (require [clojure.core.cache :as cache]) (def C (atom (cache/fifo-cache-factory {} :threshold 1E7))) (doseq [i (range 1 1E6)] …
Ravi
  • 661
  • 6
  • 17
2
votes
2 answers

Understanding `evaluate` Functiion

The Haskell docs explain the evaluate function: Forces its argument to be evaluated to weak head normal form when the resultant IO action is executed. Prelude Control.Exception> let xs = [1..100] :: [Int] …
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
4 answers

Is using a constant value as a "nil" (absence of value) a good practice in this case?

I'm learning Swift and I'm facing a problem in one of my model classes. What I'm trying to do is having a lazy-loaded property that can be "invalidated" when the data it is based on changes. (something like this:…
Lorenzo Rossi
  • 613
  • 1
  • 8
  • 18
2
votes
1 answer

JPA: how to tell CriteriaQuery to include lazy properties in returned entities?

JPA: how to tell CriteriaQuery to fetch lazy properties? For example, Student entity has description property that is declared lazy. public class Student { @Basic(fetch=FetchType.LAZY) public String getDescription() { ... …
Dave
  • 759
  • 2
  • 9
  • 31
2
votes
2 answers

"Cannot convert lambda expression to type 'bool' because it is not a delegate type" with Lazy

There are a lot of questions out there that have this error, but that's because it seems like a common error that occurs with lambdas in many scenarios; however, I can't pin down the reason for my issue. I'm using Lazy and this works fine: ///…
rory.ap
  • 34,009
  • 10
  • 83
  • 174
2
votes
2 answers

Idiomatic and lazy eventually truthy in a list in Clojure

I'd like to have a function/macro for checking a list to have truthy value eventually, and I hope the evaluation would be lazy. Here is my illustrative implementation without lazy evaluation: (defn eventual [cols] (or (first cols) (if-let [rs…
Yu Shen
  • 2,770
  • 3
  • 33
  • 48