Pure (programming language): Difference between revisions

Content deleted Content added
Add links to the manual and quick reference guide.
Expand the description of the sieve of Eratosthenes example.
Line 55:
end;
 
While Pure uses [[eager evaluation]] by default, it also supports [[Lazy evaluation|lazy]] data structures such as streams (lazy [[List (computing)|lists]]). For instance, here is a version of the [[sieve of Eratosthenes]] which computes the stream of all [[prime numbers]]:
 
primes = sieve (2..inf) with
sieve (p:qs) = p : sieve [q | q = qs; q mod p] &;
end;
 
Note the use of the <code>&</code> operator which turns the tail of the sieve into a [[thunk]] to delay its computation. The thunk is evaluated implicitly and then [[Memoization|memoized]] (using [[call by need]] evaluation) when the corresponding part of the list is accessed, e.g.:
 
primes!!(0..99); // yields the first 100 primes
 
Pure has efficient support for vectors and matrices (similar to that provided by [[MATLAB]] and [[GNU Octave]]), including vector and matrix comprehensions. E.g., a [[Gaussian elimination]] algorithm with [[partial pivoting]] can be implemented as follows in Pure: