| Path: | README |
| Last Update: | Sat Feb 18 18:42:04 EST 2006 |
lazy.rb provides lazy evaluation and futures in Ruby.
For lazy evaluation, the facilities are similar to those provided by R5 Scheme. There are two functions: Kernel.promise (similar to Scheme’s delay) which takes a block for later evaluation, and Kernel.demand (similar to Scheme’s force), which forces its evaluation (if necessary) and returns its cached result.
Unlike some Scheme implementations, it is safe to pass ordinary values to force. Promises are also transparent, meaning that in most cases an evaluated promise is not distinguishable from the actual result object it wraps.
To avoid locking overhead for single-threaded applications, promises will not be threadsafe unless you require ‘lazy/threadsafe’.
Additionally, the library provides futures, where a computation is run optimistically in a background thread. Futures can be constructed using Kernel.future. Based on promises, they are also transparent. An attempt to demand the result of a future will block until the computation completes.
Since futures require threads, requiring ‘lazy/future’ will automatically require ‘lazy/threadsafe’ for you.
lazy.rb is made available under the same license as Ruby.