Primes

LA home
Computing
FP
 PFL
  Examples
  Syntax
  Interpreter
   Primes

Sieve of Eratosthenese by parallel (||) processes.

let rec
 from = lambda n. fromchan!n -> from (n+1),

 fromchan = chan,

 sieve = lambda inch.
   inch?p -> output!p {must be prime} ->
   let rec
     filter = inch?x ->
       if (x/p)*p<>x then {not p|x} connect!x -> filter
                     else filter,

     connect = chan

   in (filter || sieve connect)


in  from 2 || sieve fromchan

{\fB Parallel Sieve of Eratosthenese. \fP}
example c1993.

A process is set up for each new prime -- to remove duplicates of that prime.


& [precomputed]
www #ad:

pfl...
|   choice
|| parallel
-> sequence
? input act
! output act
chan new channel

↑ © L. Allison, www.allisons.org/ll/   (or as otherwise indicated).
Created with "vi (Linux)",  charset=iso-8859-1,   fetched Sunday, 05-May-2024 16:48:35 UTC.

Free: Linux, Ubuntu operating-sys, OpenOffice office-suite, The GIMP ~photoshop, Firefox web-browser, FlashBlock flash on/off.