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

Post Processing to Lazy-Sequences (Clojure)

Say I'have a lazy sequence called numbers that's giving me an infinite sequence of numbers: 0, 1, 2, 3, 4, 5, 6... (def numbers (iterate inc 0)) I limit the infinity by passing it to the function take. e.g.: (take 3 numbers) ; > (0 1 2) I'm asking…
2
votes
2 answers

Django NoReverseMatch at /school/new-school/

What is wrong with my approach? When I post new data, I want it to return back to the page with the input fileds empty. But it gives me this error NoReverseMatch at /school/new-school/ Reverse for 'new-school' with arguments '()' and keyword…
2
votes
1 answer

Swift lazy stored property versus regular stored property when using closure

In Swift, we can set a stored property to use closure: class Test { var prop: String = { return "test" }() } vs or make lazy stored property use closure: class Test { lazy var prop: String = { return "test" }() } In both cases, the…
Boon
  • 40,656
  • 60
  • 209
  • 315
2
votes
2 answers

Realizing a Clojure lazy sequence (string) in the REPL

I'm trying to realize a lazy sequence (which should generate a single string) in the REPL, with no luck. The original code works fine: (def word_list ["alpha" "beta" "gamma" "beta" "alpha" "alpha" "beta" "beta" "beta"]) (def word_string (reduce str…
John C
  • 6,285
  • 12
  • 45
  • 69
2
votes
1 answer

Lazy sequence doesn't work in stack-consuming recursive calls

I found a simple(but inefficient) solution to a problem which basically can be written like this in Clojure: (defn make-someof [data] (fn sumf ([x n ds] (if (= n 1) (if (some #{x} ds) 1 0) (reduce + (for [m (filter #(< % n)…
Saeid Akbari
  • 115
  • 8
2
votes
1 answer

R lazy evaluation of two variables in data.frame

Given a data frame df <- data.frame(a = sample(c(1,0), 30, replace = TRUE), b = sample(c(2,3), 30, replace = TRUE), c = sample(c(4,5), 30, replace = TRUE)) and an expression captured by the lazy() argument in the lazyeval…
Marti
  • 53
  • 4
2
votes
1 answer

shuffle and take first vs sampling in haskell

In Ruby Programming language myList.shuffle.first is slower than myList.sample since it completely shuffle the list and pick the first element. If something similar (shuffle and take first) is done in Haskell, will that be as fast as the later…
Kavin Eswaramoorthy
  • 1,595
  • 11
  • 19
2
votes
1 answer

R dplyr filter for non-standard evaluation (NSE) ".dots is missing, with no default"

I am hoping someone can help determine why I receive an error message when using lazy evaluation as part of a dplyr filter_ verb. The end goal is to pass arguments by reference using a function but I have narrowed the problem down outside of a…
Englehas
  • 308
  • 4
  • 9
2
votes
2 answers

Performance comparison of strict collection vs view

Im doing a performance comparison between executing multiple subsequent transformations on collections in Scala that are strict (eagerly performed evaluation), and non-strict (lazily performed evaluation). def time[R](block: => R): R = { val t0…
qed
  • 22,298
  • 21
  • 125
  • 196
2
votes
2 answers

How can I force load a proxy object in NHibernate?

I am working with NHibernate right now, and am coming across a problem trying to improve the data bandwidth efficiency of what im working on. The context is I am making a data event editor, which has a listview populated with events. These events…
Cameron Stubber
  • 301
  • 3
  • 14
2
votes
1 answer

Scala 2.8 and Map views

In 2.7 I could do the following: val lazyM: Map[_, _] = map.projection.mapElements(v => expCalc(v)) //MAP VIEW I can't find a way of doing this in 2.8 and actually ending up with a map: val m: Map[_, _] = map.view.map(kv => kv._1 ->…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
2
votes
1 answer

What is wrong with this recursive Promise function with jQuery Deferred

I am working on my scripts for ReST API processes. Now I need a function which keeps retrying to request to the API as many as possible in few seconds. So I wrote some Promise abstractions and I made something like below: $(function () { var $el =…
Japboy
  • 2,699
  • 5
  • 27
  • 28
2
votes
1 answer

Questions regarding Haskell solution of Project Euler 14

This is the Question 14. import Data.Array import Data.List import Data.Ord (comparing) syrs n = a where -- For those who don't want to lookup array in the reference -- the following line creates an array indexed from 1 to n --…
pspencil
  • 295
  • 1
  • 10
2
votes
1 answer

How to make an IEnumerable of values of tree nodes?

Consider the following class: class TreeNode { int value; public TreeNode l, r; public TreeNode(int value) { this.value = value; } public IEnumerable sub_values() { if (l != null) foreach…
user2136963
  • 2,526
  • 3
  • 22
  • 41
2
votes
3 answers

Evaluation (or none at all) of `_` Function Argument?

Given the data type, Foo: Prelude> data Foo a = Foo a It does not implement Show, so it can't be printed. Prelude> Foo 5 :13:1: No instance for (Show (Foo a0)) arising from a use of ‘print’ However, given a function that always…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384