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

How to make my Haskell code use Laziness and Garbage collector

I wrote a Haskell code which has to solve the following problem : we have n files : f1, f2, f3 .... fn and I cut those files such a way that each slice has 100 lines f1_1, f1_2, f1_3 .... f1_m f2_1, f2_2, .... f2_n ... fn_1, fn_2, ....…
Fopa Léon Constantin
  • 11,863
  • 8
  • 48
  • 82
2
votes
1 answer

Haskell CIS194 Spring 13 Homework 6 Exercise 5

http://www.seas.upenn.edu/~cis194/spring13/hw/06-laziness.pdf The question is about representing the ruler function 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, . . . where the nth element in the stream (assuming the first element …
User9123
  • 33
  • 3
2
votes
3 answers

How do you implement a lazy loading ListView in a simple way for UWP?

I have read samples on the internet and some are very hard to learn. I want to learn how to understand when the ListView is scrolling down and if more data is still available, how I can get the data from the internet while showing a ProgressRing on…
2
votes
1 answer

Project Euler prob 10 using haskell

Okay, so I made a small modification that seems to have made a whole lot of difference to haskell. Here is how it goes: I implemented the Sieve of Eratosthenes for Prob 10 from project euler. Here's how it goes: primesBelowN :: Integer ->…
deejay
  • 25
  • 5
2
votes
2 answers

Regular expression library for .Net that supports lazy evaluation

I'm looking for a regular expression library in .Net that supports lazy evaluation. Note: I'm specifically looking for lazy evaluation (i.e., the library, instead of immediately returning all matches in a document, only consumes as much of the…
Dathan
  • 7,266
  • 3
  • 27
  • 46
2
votes
0 answers

Scala by name versus function parameters

This is a named parameter: def foo(bar: => Boolean): Boolean = bar And this is a function parameter: def foo(bar: () => Boolean): Boolean = bar() How do the two declarations differ? Both will be evaluated lazily and each time the parameter is…
Saish
  • 1,518
  • 1
  • 12
  • 21
2
votes
1 answer

Why lazy variables / computed properties, not just methods

Why does Swift have the concepts of "lazy variables" and "computed properties", when it seems that simple methods or functions would be appropriate for the purpose? In the time-consuming case of computing Pi, shouldn't this have been a method…
forthrin
  • 2,709
  • 3
  • 28
  • 50
2
votes
2 answers

If global properties are always computed lazily, and local properties are never, what does the lazy modifier modify?

A note on page 248 in The Swift Programming Language (Swift 2.1) explains the following: Global constants and variables are always computed lazily, in a similar manner to Lazy Stored Properties. Unlike lazy stored properties, global constants and…
grossmae
  • 331
  • 5
  • 16
2
votes
1 answer

seq to force evaluation

To run in constant space, mean2 uses sumlen2 which seqs summation and count. But again my belief and textbook, mean2 still runs with space leak. What's the mistake? Any helps will be appreciated deeply. -- Thinking Functionally with Haskell by R.…
Chul-Woong Yang
  • 1,223
  • 10
  • 17
2
votes
3 answers

Iterate generator in tuples in python

Suppose I have a list xs = [0,1,2,3] [some_function(current, next) for current, next in zip(xs, xs[1:])] I want to iterate over pairs (current, next) of this list. To clarify zip creates list [(0,1), (1,2), (2,3)] The problem is that if xs is a…
user1685095
  • 5,787
  • 9
  • 51
  • 100
2
votes
1 answer

haskell - is it my partitions lazy?

For example partitions [1,2,3] = [([],[1,2,3]) ,([1],[2,3]) ,([1,2],[3]) ,([1,2,3],[])] partitions :: [a] -> [([a], [a])] partitions (x:xs) = ([], x:xs):[(x:ys, rs) | (ys, rs) <- partitions xs] I wonder is it lazy solution. For example…
user6023611
2
votes
1 answer

Lazyeval in R -- How can I build a subset function?

I'm trying to build a subset function in R that will accept dataframes as well as column names and running into issues using the lazyeval approach outlined here. Here's my code: iris_fun <- function(df, selection_var, selection_input){ temp <-…
c. garrett
  • 69
  • 2
  • 4
2
votes
1 answer

Irrefutable/lazy pattern exercise in Haskell wikibook

Half way down here... https://en.wikibooks.org/wiki/Haskell/Laziness ...is an exercise asking about the effects of changes to an alternative implementation of the head function that uses irrefutable patterns. It provides a definition of head' as…
2
votes
1 answer

Demonstrating Lazy evaluation in Haskell?

This is a question from one of my homework assignments that I haven't been able to answer. It's to do with reasoning about Haskell code by demonstrating how the Haskell compiler (interpreter?) executes programs. I'm given a few different…
2
votes
4 answers

R : How evaluate formals (arguments) of function?

I really looked all over the place and haven't found an answer to my question : The Generalized Problem : How do you evaluate arguments (formals()) of a R function, without launching it ? How do you evaluate a whole environment in R, despite the…
Jean Lescut
  • 1,387
  • 1
  • 12
  • 17