lazy-evaluation

C# How to split (A:B=C)* using regex?

This is supposedly a very easy question, but I just can't seem to find the right solution. There is a string in the format: A:B=C;D:E=F;G:E=H;... whereas A, B and C are alphanumeric (and may be lower as well as upper case). A and B are of length 1+, C may be empty. I figured I'd have to use something along the lines of ((?<A>.+):(?<...

Parsing: Lazy initialization and mutually recursive monads in F#

I've been writing a little monadic parser-combinator library in F# (somewhat similar to FParsec) and now tried to implement a small parser for a programming language. I first implemented the code in Haskell (with Parsec) which ran perfectly well. The parsers for infix expressions are designed mutually recursive. parseInfixOp :: Parser ...

PHP equivalent to Python's yield operator

In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP? For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this example is contrived, as it is ...

recursive (doall) in clojure

I have some structures with nested lazy sequences which read from files. When I'm testing I would like to be able to wrap them in a recursive version of doall to make sure all the data is pulled from the files before the files get closed. ...

Python lazy attributes that don't eval on hasattr()

Is it possible to make a decorator that makes attributes lazy that do not eval when you try to access it with hasattr()? I worked out how to make it lazy, but hasattr() makes it evaluate prematurely. E.g., class lazyattribute: # Magic. class A: @lazyattribute def bar(self): print("Computing") return 5 >>> a = A...

how to solve "stack space overflow" in haskell

Hi! Running the following program will print "space overflow: current size 8388608 bytes." I have read this and this, but still don't know how to resolve my problem. I am using foldr, shouldn't it be guaranteed to be "tail recursive"? I feel great about Haskell so far until I know I should prevent "space overflow" when using the powe...

(emulated) Macros in Haskell?

Hi. A person on Reddit has brought this code to my attention: main = do let ns = [print 1, print 2, print 3] sequence_ ns sequence_ $ reverse ns sequence_ $ tail ns ++ [head ns] head ns What's going on here is we have an array of operations that we can do stuff with, like reverse or get its tail or head. Awesome. What I w...

How is debugging achieved in a lazy functional programming language?

I'd like to know how debugging is achieved in a lazy functional language. Can you use breakpoints, print statements and traditional techniques? Is this even a good idea? It is my understanding that pure functional programming does not allow side-effects, with the exception of monads. Order of execution is also not guaranteed. Would you h...

When is lazy evaluation not useful?

Delay execution is almost always a boon. But then there are cases when it’s a problem and you resort to “fetch” (in Nhibernate) to eager fetch it. Do you know practical situations when lazy evaluation can bite you back…? ...

XML serialisation won't write out lazy-evaluated property

Following on from a previous question, I am having trouble combining the Lazy<T> generic that was suggested with my XML Serialization. Here is the functionality I am using for Lazy<T>: public struct Lazy<T> where T : class, new() { private T _Value; public bool HasValue { get { return (_Value !=...

Playing with infinity - Lazy arithmetics

Many modern programming languages allow us to handle potentially infinite lists and to perform certain operations on them. Example [Python]: EvenSquareNumbers = ( x * x for x in naturals() if x mod 2 == 0 ) Such lists can exist because only elements that are actually required are computed. (Lazy evaluation) I just wondered out of in...

Partitioning an Iterator in scala 2.7.5

It looks as though there is no partition method on an Iterator in scala 2.7.5 (there is in 2.8). I'd like to have a partition without losing the laziness of the Iterator, so the following is not an option: itr.toList.partition( someTest(_) ) Can anyone recommend a way of doing this without implementing my own partition method? For exa...

Haskell. Strict application $!

I execute the next code: (take 10) $! [1,2..] What is it ? I thought, ghc will yield a termination, beacause i say "evaluate [1,2..] force". But I got the result "[1,2,3,4,5,6,7,8,9,10]". ...

Transform this Clojure call into a lazy sequence

I'm working with a messaging toolkit (it happens to be Spread but I don't know that the details matter). Receiving messages from this toolkit requires some boilerplate: Create a connection to the daemon. Join a group. Receive one or more messages. Leave the group. Disconnect from the daemon. Following some idioms that I've seen used ...

How to covert a lazy sequence to a non-lazy in Clojure

I tried the following in Clojure, expecting to have the class of a non-lazy sequence returned: (.getClass (doall (take 3 (repeatedly rand)))) However, this still returns clojure.lang.LazySeq. My guess is that doall does evaluate the entire sequence, but returns the original sequence as it's still useful for memoization. So what is t...

Python: Lazy String Decoding

I'm writing a parser, and there is LOTS of text to decode but most of my users will only care about a few fields from all the data. So I only want to do the decoding when a user actually uses some of the data. Is this a good way to do it? class LazyString(str): def __init__(self, v) : self.value = v def __str__(self) : ...

How to begin approach of creating a small lazily-evaluated language.

I'm trying to build a small language with similar syntax and grammatical structure to Java, with List Comprehension and Lambda Functions and such (already made). What I'm trying to do now is instead of having it do eager evaluation, I want to make this language lazily-evaluate expressions. I'm not entirely sure how to go about it, becau...

Lazy stream for C# / .NET

Does anyone know of a lazy stream implementation in .net? IOW, I want a to create a method like this: public Stream MyMethod() { return new LazyStream(...whatever parameters..., delegate() { ... some callback code. }); } and when my other code calls MyMethod() to return retrieve the stream, it will not actually perform...

Is it possible to match with decomposed sequences in F#?

I seem to remember an older version of F# allowing structural decomposition when matching sequences just like lists. Is there a way to use the list syntax while keeping the sequence lazy? I'm hoping to avoid a lot of calls to Seq.head and Seq.skip 1. I'm hoping for something like: let decomposable (xs:seq<'a>) = match xs with |...

JQuery plugin for lazy-loading/lazy-evaluation?

Is there such jQuery plugin? More specific: I want to use some elegant and easy way to postpone some code execution until it's really needed (some event happens). And when this event happens, the postponed code should get executed only once. Some kind of lazy initialization. For example, apply some animation to an element not when docu...