Qi (programming language)
Qi is a functional programming language developed by Dr Mark Tarver and introduced in its current form in April 2005 under the GNU GPL license. Although Qi is written in Lisp, it includes most of the features common to modern functional programming languages such as pattern-matching, currying, partial applications and (optional) static type checking. The combination of all these features within the Lisp environment makes Qi in many senses a rationalization and modernization of Lisp. Qi won its creator a Promising Invention Award from the State University of New York in 2003.
Notable Features
Though Qi shares the afore-mentioned features with modern functional programming languages like Standard ML and Haskell, Qi includes features which are quite specific to the language. Qi's most significant divergence from ML and Haskell is the use of sequent calculus notation to define types. Qi incorporates an efficient compiler for compiling sequent calculus notation into an extended Prolog that incorporates embedded function calls. Since Prolog is itself a programming language, the type specification language of Qi is Turing-equivalent, which in practice means that type checking in Qi is not guaranteed to terminate.
This fact initially generated some controversy, but the author defended this feature by arguing that non-termination was an inevitable by-product of increased expressiveness and that a preference for a less expressive terminating type system represented a value judgment. In the absence of user-defined types, the Qi type checker will in fact terminate in all cases.
Development
As of October 2007, Qi has been updated several times since the first release (6.1) in April 2005 and the current release, 9.1, released September 2007, runs under both Windows and Linux on the CLisp, CMU Common Lisp, Allegro Common Lisp and SBCL platforms. 9.0 incorporated an optional factorising code compiler (Turbo-E) for optimising pattern-matching. In a comparative shoot-out against several Lisp programs and OCaml, Qi 9.0 performed at the speed of the fastest and most heavily hand-optimised Lisp version. A release (Qi/Tk) incorporating a type secure version of Tcl/Tk embedded into Qi is scheduled to Appear later in 2007.
Examples
The traditional Hello world program in Qi:
(output "Hello, world~%")
A factorial function using pattern matching:
(define factorial
0 -> 1
N -> (* N (factorial (- N 1))))
This is a basic example of Qi-Prolog:
(defprolog
"dog(snoopy).
man(socrates).
man(plato).
mortal(X) :- man(X).")
And this is how to ask questions to the Prolog database:
(ask [ man plato ] )
(ask [ man snoopy ] )
(ask [ dog X ] )
(ask [ man M ] )
External links
- Lambda Associates is the home for Qi.
- Functional Programming in Qi is the standard text.
- Qi includes an embedded Prolog and TDPL (top-down parsing language) compiler-compiler described on the home site. The Abstract Unification Machine is the virtual machine that powers Qi's extended Prolog and its interpretation into Lisp.
- Online code studies in Qi are available on the main site.
- Qi has its own news group.
- Qi sources are also hosted on the Google Code Project Hosting.