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
3 answers

How can I lazy evaluate fields on a javascript object?

I am wondering if it is possible to do something like the following: var obj = { counter: (function(){ if(!this.val){ this.val = 0; } this.val += 1; return this.val; …
RutledgePaulV
  • 2,568
  • 3
  • 24
  • 47
2
votes
2 answers

Is .NET's FileInfo.Length property lazy?

The following code generates a FileNotFoundException (using .NET 2.0): using System; using System.Collections.Generic; using System.Text; using System.IO; namespace LazyFileInfoTest { class Program { static void Main(string[] args) …
user290649
2
votes
3 answers

Lazy boolean evaluation in Python when using Map-Reduce

I will use my example: I want to create a list of primes using the sieve of Eratosthenes. For each number, I check if it is composite, and if not, I append it to the list. Using "standard" programming: primes = [2] start = time.time() for i in…
Mrpopo
  • 25
  • 5
2
votes
2 answers

Pattern matching against a type with only one constructor

If I pattern-match against an expression whose type has only one constructor, will that still force the runtime to evaluate the expression to WHNF? I did an experiment that seems to indicate it doesn't evaluate: Prelude> data Test = Test Int…
dspyz
  • 5,280
  • 2
  • 25
  • 63
2
votes
1 answer

gem Lazy High Charts - Pie Donut

I'm trying to create a pie donuts, but it does not work... http://www.highcharts.com/demo/pie-donut Controller @chart_teste5 = LazyHighCharts::HighChart.new('graph') do |f| f.chart({:defaultSeriesType=>"pie", :margin=> [50, 0, 0, 0]}) …
2
votes
2 answers

Is there any streaming regular-expression module for Python?

I'm looking for a way to run a regex over a (long) iterable of "characters" in Python. (Python doesn't actually have characters, so it's actually an iterable of one-length strings. But same difference.) The re module only allows searching over…
TLW
  • 1,373
  • 9
  • 22
2
votes
1 answer

Can I be sure of order of IO actions in this example?

At the moment, I have this code in and around main: import Control.Monad import Control.Applicative binSearch :: Ord a => [a] -> a -> Maybe Int main = do xs <- lines <$> readFile "Cars1.txt" x <- getLine <* putStr "Registration: " --…
mudri
  • 758
  • 3
  • 16
2
votes
1 answer

Efficiently parsing large JSON files in Haskell

I have a large JSON file (about 90MB) that contains an homogeneous array of objects. I am trying to write a Haskell program that reduces the values in the array. This seems like a good candidate for lazy evaluation - the program shouldn't have to…
immutablestate
  • 287
  • 1
  • 9
2
votes
4 answers

Invoke delegates without params but using local params c#

I find myself doing the following a lot, and i don't know if there is any side effects or not but consider the following in a WinForms C# app. (please excuse any errors as i am typing the code in, not copy pasting anything) int a = 1; int b =…
Daniel
  • 865
  • 1
  • 8
  • 12
2
votes
2 answers

Clojure. Drop-every?

Does the Clojure library have a "drop-every" type function? Something that takes a lazy list and returns a list with every nth item dropped? Can't quite work out how to make this. cheers Phil
interstar
  • 26,048
  • 36
  • 112
  • 180
2
votes
2 answers

Fancytree Lazyload: Make Ajax call each time it expands

I have a tree folder structure that I am displaying in a webpage using Fancytree and using the lazyLoad option to display the contents of the folder ondemand. This works fine for the first time, but if there are no items under a folder and when…
user980591
  • 31
  • 1
  • 3
2
votes
2 answers

Lazy evaluation in Python? Between modules?

I'm not sure if something like this is even possible in Python, but if it is it'd be really useful (at least to me in this instance). I have a test framework in which I want to keep the test configuration separate from the test commands. This is…
Paul D.
  • 1,785
  • 2
  • 19
  • 25
2
votes
1 answer

istream_iterator and lazy evaluation

Considering istream_iterator's lazy evaluation I was wondering if I can rely on the initialized, but never dereferenced or incremented, iterator for a condition. As an example: #include #include #include using…
user2952086
2
votes
1 answer

How to prevent sharing in GHC?

I've tried to come up with ways to break sharing of top level constants in haskell, but so far none of them worked: module Main where import Debug.Trace x1 :: Int x1 = trace "Eval1" $ 10 + 10 x2 :: () -> Int x2 = \() -> trace "Eval2" $ 10 +…
bennofs
  • 11,873
  • 1
  • 38
  • 62
2
votes
1 answer

OCaml, lazy list into lazy tree

I have two types: type 'a llist = LNil | LCons of 'a * (unit -> 'a llist);; type 'a lBT = LEmpty | LNode of 'a * (unit -> 'a lBT) * (unit -> 'a lBT);; I need to write function that gets lazy list and returns lazy BST. I…
ajgoralczyk
  • 35
  • 1
  • 10
1 2 3
99
100