On Fri, 10 Jul 2009 08:14:30 EDT erik quanstrom <quans...@quanstro.net>  wrote:
> > there has also been a lot of discussion in the past 1-2 months about
> > K, a successor to APL, in #plan9. you might ask there; i may have
> > missed a more recent development.
> 
> could someone please explain to the ignorant, what
> is interesting about apl?  the last surge of interest i
> recall in the language was in 1983.  ibm offered an
> rom for the mga (monochrome graphics adapter)
> that substituted the odd apl characters for the
> equally-odd pc character set's bucky-bit characters.

Ken Iverson's 1979 Turing Award lecture, "Notation as a Toool
of thought" is a good place to start.  Htmlized version at
    http://www.jsoftware.com/papers/tot.htm
Google for p444-iverson.pdf for the original.

If you watched the Game of Life in APL video I pointed to,
you saw how the presenter develops the program. This is very
much like how one builds up a shell pipeline (both are
loopless as there are a lot of similarities between streams
and arrays).

APL and its successor languages such as j/k/q are not just
for number crunching.  I mostly use k or q for scripting.
Here is a quick example of piecewise development in q.  A
year ago I wanted a simple inverted index program so this is
what I implemented.

I first created a sample table "dt" where each row contains a
document id and a term.

q)dt
d1 t1
d1 t2
d2 t1
d2 t3
d3 t1
d3 t2
d3 t3

Then dt[;0] is the doc-id column, dt[;1] is the term column.
The following gives me row indices that have the same terms.

q)group dt[;1]
t1| 0 2 4       /t1 appears in rows 0 2 and 4
t2| 1 5         /etc
t3| 3 6

What I really want is doc-ids with the same term.

q) dt[;0] @ group dt[;1]
t1| `d1`d2`d3
t2| `d1`d3
t3| `d2`d3

Given this associative table I can find out which documents
contain t2. I first name the table idx.

q) idx: dt[;0] @ group dt[;1]
q) idx[`t2]
d1 d3

Now I have the data in the form I want and can implement
fancier things on top. But how do I get the data in?  If I
have a file foo where each line contains a space separated
doc-id and term, I can initialize dt from it.

q)dt:("SS";" ")0:`:foo

Code to read a bunch of files and create lines of <doc-id
term> not shown.  This was fast enough for a few tens of MB
of data I was interested in.

See code.kx.com for syntax etc.  It has a wealth of
information on Q including tutorials.  You can download a
copy for your own use.

[Note that there is another Q language, an equational
language. UNlike this Q it is open source but not an array
language]

Reply via email to