lazy-evaluation

Improving clojure lazy-seq usage for iterative text parsing

I'm writing a Clojure implementation of this coding challenge, attempting to find the average length of sequence records in Fasta format: >1 GATCGA GTC >2 GCA >3 AAAAA For more background see this related StackOverflow post about an Erlang solution. My beginner Clojure attempt uses lazy-seq to attempt to read in the file one record a...

Stream of readLines

I'm attempting to create an infinite stream of strings from readLine calls: import java.io.{BufferedReader, InputStreamReader} val in = new BufferedReader(new InputStreamReader(System in)) val input: Stream[String] = Stream.cons(in readLine, input) But it appears that the readLine call isn't being called lazily. Immediately after ente...

Partitioning in clojure with a lazy collection of strings

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...

Lazy Evaluation for iterating through NumPy arrays

I have a Python program that processes fairly large NumPy arrays (in the hundreds of megabytes), which are stored on disk in pickle files (one ~100MB array per file). When I want to run a query on the data I load the entire array, via pickle, and then perform the query (so that from the perspective of the Python program the entire array...

How can I try Perl 6 without installing it?

I would like to try out Perl 6, but I am not sure that downloading and configuring it is worth the effort. What can I do? ...

Sharing data between processes in Python

I have a complex data structure (user-defined type) on which a large number of independent calculations are performed. The data structure is basically immutable. I say basically, because though the interface looks immutable, internally some lazy-evaluation is going on. Some of the lazily calculated attributes are stored in dictionaries (...

Python lazy dictionary evaluation

Python evangelists will say the reason Python doesn't have a switch statement is because it has dictionaries. So... how can I use a dictionary to solve this problem here? The problem is that all values are being evaluated some and raising exceptions depending on the input. This is just a dumb example of a class that stores a number or ...

clojure deferred function execution

Ok Here is what i am trying to do (defn addresses [person-id] ;addresses-retrival ) (defn person [id] (merge {:addresses (addresses id)} {:name "john"})) In the above person function i want addresses to be retrieved only on demand , like only when i do (:addresses (person 10)) and not when (person 10) I am not sure if i ...

lazy function definitions in scala

I've been learning scala and I gotta say that it's a really cool language. I especially like its pattern matching capabilities and function literals but I come from a javascript, ruby background and one of my favorite patterns in those languages is the lazy function and method definition pattern. An example in javascript is var foo = fu...

Lazy List of Prime Numbers

How would one implement a list of prime numbers in Haskell so that they could be retrieved lazily? I am new to Haskell, and would like to learn about practical uses of the lazy evaluation functionality. ...

If I have an expression, which is partitially evaluable, is it a good idea to avoid tail-recursion?

Consider an haskell-expression like the following: (Trivial example, don't tell me what the obvious way is! ;) toBits :: Integral a => a -> [Bool] toBits 0 = [] toBits n = x : toBits m where (m,y) = n `divMod` 2 x = y /= 0 Because this function is not tail-recursive, one could also write: toBits :: Integral a => a -> [Bool] toB...

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 document as necessary to determine the next match per request), NOT support for lazy quantifie...

Calculating an array of values in C# (Formula convert from Excel)

Hi all, I'm currently building a semi-complicated calculator which is basically a conversion from an Excel spreadsheet I've been provided. I've nailed most of it but there's a part in the Excel spreadsheet where multiple calculations occur between 6 rows and 7 columns, but the issue is that the calculations happen in no particular orde...

How can iterative deepening search implemented efficient in haskell?

I have an optimization problem I want to solve. You have some kind of data-structure: data Foo = { fooA :: Int , fooB :: Int , fooC :: Int , fooD :: Int , fooE :: Int } and a rating function: rateFoo :: myFoo -> Int I have to optimize the result of rateFoo by changing the values in the struct. In this specific case, I dec...

Why isn't promise a data type in Scheme?

The object returned by delay in Scheme is "a promise", but promises are not considered to be a type (so there is no promise? procedure, and it's not listed as a type in R5RS or R6RS). Is there a strong reson why this is so? It would seem quite natural to me to do something like (if (promise? x) (force x) x), for example. (And I see that...

How can I lazily load a Perl variable?

I have a variable that I need to pass to a subroutine. It is very possible that the subroutine will not need this variable, and providing the value for the variable is expensive. Is it possible to create a "lazy-loading" object that will only be evaluated if it is actually being used? I cannot change the subroutine itself, so it must sti...

Understanding and using the Boost Phoenix Library with a focus on lazy evaluation

I just found out about the Boost Phoenix library (hidden in the Spirit project) and as a fan of the functional-programming style (but still an amateur; some small experience with haskell and scheme) i wanted to play around with this library to learn about reasonable applications of this library. Besides the increasement of expressivenes...

Why does laziness go well with referential transparency?

Hello. I was reading a Haskell tutorial (Learn You a Haskell) in which the author said that laziness goes well with referential transparency. After more reading and some searching, I still don't understand why. Note that I do understand what's great about referential transparency and laziness, but it's them together that's troubling me....

Lazy evaluation of linq expressions

Hi, Im trying to build a expression evaluator with Linq expressions. Im trying to make It so that all function arguments are lazy evaluated but can't quite get there. I'm writing in psuedo here but the real thing is linq expressions. Example expression: Func1(Func2(10) + 1, Func3(10)) Update Expression.Call(Func1, Expression.A...

Use of lazy val for caching string representation

I encountered the following code in JAXMag's Scala special issue: package com.weiglewilczek.gameoflife case class Cell(x: Int, y: Int) { override def toString = position private lazy val position = "(%s, %s)".format(x, y) } Does the use of lazy val in the above code provide considerably more performance than the following code? ...