lazy-evaluation

Partitioning in clojure with a lazy collection of strings

与世无争的帅哥 提交于 2019-12-13 13:14:06
问题 Starting with a collection of strings like: (def str-coll ["abcd" "efgh" "jklm"]) The goal is to extract off a specific number of characters from the head of the string collection, generating a partitioned grouping of strings. This is the desired behavior: (use '[clojure.contrib.str-utils2 :only (join)]) (partition-all 3 (join "" str-coll)) ((\a \b \c) (\d \e \f) (\g \h \j) (\k \l \m)) However, using join forces evaluation of the entire collection, which causes memory issues when dealing with

Merge N sorted arrays in ruby lazily

浪尽此生 提交于 2019-12-13 13:11:11
问题 How does one merge N sorted arrays (or other list-like data structures) lazily in Ruby? For example, in Python you would use heapq.merge. There must be something like this built into Ruby, right? 回答1: Here's a (slightly golfed) solution that should work on arrays of any 'list-like' collections that support #first , #shift , and #empty? . Note that it is destructive - each call to lazymerge removes one item from one collection. def minheap a,i r=(l=2*(m=i)+1)+1 #get l,r index m = l if l< a

Variable x equals a or b

折月煮酒 提交于 2019-12-13 11:28:09
问题 Is this: if(x == a || b){//do something} same as: if(x == a || x == b){//do something} ? I think it is not, because in the first case we evaluate if x equals a and if b is true or false. In the second case, we evaluate if x equals a and if x equals b. And I understand that in the lazy evaluation if x equals a than we are not evaluating further. But somebody thinks that in the first case we ask if x equals a or b, so I wanna make sure. 回答1: No . In C++, this: x == a || b // Same as (x == a) ||

How to do lazy evaluation of an array being processed by a for loop

眉间皱痕 提交于 2019-12-13 04:30:57
问题 window.onload = function () { x = ''; myArray = [ {a:'a', b:'b'}, {a:'c', b:'d'}, {a:x, b:''} ]; for (i = 0; i < myArray.length; i += 1) { x = myArray[i].a + myArray[i].b; } alert(x); // alerts ''; } Hi, the above is an example of what I'm trying to do. Basically, I would like for x to be evaluated after the 2nd array element computes it. I think this is called lazy evaluation, but not sure... I'm somewhat new. How can I process my array in the loop and x be evaluated each time such that when

SFML 2.1 & “lazy symbol binding failed”

人走茶凉 提交于 2019-12-13 04:30:26
问题 I've compiled my SFML program with g++ and that seems to be working fine now (had issues with it previously), however when I try to run the resulting output, I get the following error message: dyld: lazy symbol binding failed: Symbol not found: __ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE Referenced from: /Users/fabricecastel/Work/Game_Projects/SFML_tutorials/./a.out Expected in: /usr/local/lib/libsfml-graphics.2.dylib dyld: Symbol not found: _

Comparison of lazy and strict evaluations in Haskell

邮差的信 提交于 2019-12-12 19:16:51
问题 I implemented the Winograd algorithm on Haskell and tried to speed up the algorithm due to strict calculations. In this I succeeded, but I completely did not understand why, adding strictness, it starts to work faster. Since my code for this algorithm is large enough, I wrote two small functions that demonstrate this problem. module Main where import qualified Data.Vector as V import qualified Data.Matrix as M import Control.DeepSeq import Control.Exception import System.Clock import Data

In Apache Spark, how to make an RDD/DataFrame operation lazy?

感情迁移 提交于 2019-12-12 18:36:10
问题 Assuming that I would like to write a function foo that transforms a DataFrame: object Foo { def foo(source: DataFrame): DataFrame = { ...complex iterative algorithm with a stopping condition... } } since the implementation of foo has many "Actions" (collect, reduce etc.), calling foo will immediately triggers the expensive execution. This is not a big problem, however since foo only converts a DataFrame to another, by convention it should be better to allow lazy execution: the implementation

How to make an IEnumerable of values of tree nodes?

匆匆过客 提交于 2019-12-12 18:00:48
问题 Consider the following class: class TreeNode { int value; public TreeNode l, r; public TreeNode(int value) { this.value = value; } public IEnumerable<int> sub_values() { if (l != null) foreach (int i in l.sub_values()) yield return i; if (r != null) foreach (int i in r.sub_values()) yield return i; yield return value; } } Each value is passed O(h) times, where h is the height of the tree. First, in yield return value; statement, then in yield return i; of each parent node. So, sub_values

How to lazy-evaluate a wpf:DataGrid, retrieving data only as needed

末鹿安然 提交于 2019-12-12 14:41:24
问题 I have a WPF datagrid, bound to a list populated by linq-to-sql from a database. The binding is two-Way, allowing the user to change the values in each row <wpf:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding MyList}" SelectedItem="{Binding SelectedItem}" > When displaying about 20000 rows, the program crashes with an out-of-memory exception during initialisation of the list. Performance becomes unbearably slow even with less rows. I know that on initialization the datagrid

Icefaces ace:dataTable lazy loading

…衆ロ難τιáo~ 提交于 2019-12-12 14:15:50
问题 Is there anybody who have a little example of a lazy loading with ace:dataTable?.. I can't understand how to implement the load method of the class LazyDataModel.. and how to fetch data from a Database through this method.. thanks! 回答1: ace:dataTable has already a "built in" lazy loading mechanism in ICEFaces (at least for release 3.x and up). No need to extend an AbstractList for this anymore. All you need to do is add the lazy="true" to your tag, and make sure the " value " attribute points