What is a life? Two billion heartbeats. Perhaps four thousand books. And how many keystrokes?
Q is an array-programming language optimised for timeseries. It is implemented as a domain-specific PL embedded in k4, a descendant of APL and Lisp. Q is fast, functional, and brutally terse. You will love it.
Salient features:
sum[cos[2+first[list]]]
write sum cos 2+first list
.(true;false;true)
but as 101b
; the first natural numbers are not (1,2,3)
but 1 2 3
. You will love the way your q code looks.Here’s q code to draw the Mandelbrot Set in ASCII, adapted from Michal Wallace.
s:{(.[-]x*x),2*prd x} / complex square (x is R,Im pair)
m:{floor sqrt sum x*x} / magnitude (distance from origin)
d: 120 60 / dimensions of the picture
t: -88 -30 / camera translation
f: reciprocal 40 20 / scale factor
c: (,/:\:) . f * t + til each d / complex plane near mandelbrot set
z: d # enlist 0 0 / 3d array of zeroes in same shape
mb: c+ (s'')@ / Mandelbrot: s(z) + c
r: 1 _ 8 mb\z / collect 8 times
o: " 12345678"@ sum 2<m'''[r] / "color" by how soon point "escapes"
-1 "\n"sv flip o; / transpose and print the output
Here’s the result. (Compare solutions in other languages at Rosetta Code.)
Save q tables to file and you get kdb+, for two decades the world’s fastest column-store timeseries database. Q includes SQL-like queries built from functional equivalents of greater power and generality.
Q is implemented in C, runs close to the metal, and is bewilderingly fast. For most of its life it has been restricted mostly to financial institutions willing to pay a premium for extreme speed.
I’ve been blessed with access to a q licence and because of its elegance and economy it has become my go-to language for hacking and solving problems.
Now q is becoming more widely accessible through cloud-based services, and the kdb+ Personal Edition is available for free download. You might want to try it yourself.