Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utnut!cs.utexas.edu!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!newsserver.jvnc.net!siemens!princeton!elan!mg
From: mg@elan (Michael Golan)
Subject: Duel, Apl, and the shortest program to find prime numbers
Message-ID: <1993Mar19.155508.13034@Princeton.EDU>
Originator: news@nimaster
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: elan.princeton.edu
Organization: Princeton University
Date: Fri, 19 Mar 1993 15:55:08 GMT
Lines: 35

Hi!
I wonder how many characters is the shortest program to find the first
10 prime numbers over 1000, in APL ....

Background: I am the developer of Duel, a language for C debugging. 
I have never used APL seriously, though I'm aware of the semantics, 
some of which found their way into Duel. What is Duel? under gdb, 
given array x[100] of structs with field level, you could do:

(gdb) dl x[..100].level >? 0
x[42].level = 5
x[67].level = 19

That is, find x[i].level that are positive (the nice symbolic output is
automatic). care for more details? anon ftp to: ftp.cs.princeton.edu:/duel.

Anyway, I needed some prime numbers over 1000, and I ended up using Duel!
This raises the question of whether Duel provides anything interesting to 
people who use APL one-liners, or plain old Unix 'bc'.

To get the first 10 prime numbers over 1000, in Duel:
(all the spaces are redundant. x=>y creates an implied loop over x, returning
 y, where _ is the index of the loop)

(1000.. => if(&&/( 2,3.._-1 => __%_)) _ )[[..10]]

How much work it takes in APL? Duel uses Icon-like generators, so the above
is iterative, not lists/arrays manipulations. The above code does not
assume, e.g. that there must be 10 primes between 1000 and 2000.

Comments appreciated!
 Michael Golan
 mg@cs.princeton.edu


