How this APL prog, and most data processing, works

Initialise

∇ FN a ⍝ A  programme called FN with one parameter called “a”

N← ⍳ a⍝ the numbers from 1 to N in a vector

N← 1↓ N⍝ 1 is a special case, drop it before sieve starts
P←2⍝ 2 is the first prime, we assume, put it in P, the vector of primes
“starting with N is ” N ” and P is ” P
“entering loop”

process

topend:scan ← ((⌈(N÷N[1]))≠⌊(N÷N[1]))⍝ this is a sieveing test for prime numbers
N← scan/N⍝here we apply the test

if (we are at the end of processing) then go to the end

→(0=⍴N)/0⍝ if N is now fully sieved out of primes then go to the end of the programme

deliver interim output

P← P,N[1]⍝ this is really processing but if it is done before the 0=⍴N test then we exit with an error at the end of the processing loop

‘N is ‘ N
‘P is ‘ P

‘scan is ‘ scan

go back to process

→topend

the end

Tagged , , ,

Leave a comment