cmuinfix
20180228
Mathematical infix notation for Common Lisp.
Upstream URL
Author
Maintainer
License
CMUINFIX
A library for writing infix mathematical notation in Common Lisp.
Origin
This library was originally written by Mark Kantrowitz in 1993 with updates the following few years. The code in this repository was derived from the original infix.cl
library provided by the CMU AI Repository. For posterity, a copy of this original file—otherwise unused by this library—can be found in attic/infix.cl
.
With minimal changes to the core functionality, the library was modernized by Robert Smith to be inline with contemporary Common Lisp usage.
Example Use
This package uses namedreadtables
to manage the readtables. If you've loaded CMUINFIX
successfully, then you'll have this package loaded as well.
To use CMUINFIX
, simply use the readtable named cmuinfix:syntax
:
(namedreadtables:inreadtable cmuinfix:syntax)
Once you have this, you can use the #I
syntax for infix syntax. Here are some examples.
Example: Pythagorean Theorem
(defun hypot (a b) "Compute the length of the hypotenuse of a right triangle with sides A and B." #I( sqrt(a^^2 + b^^2) ))
Example: PowerofTwo Check
(defun poweroftwop (n) "Check if N is a power of 2." #I( n != 0 and (n & (n  1)) == 0 ))
Example: Euclidean Algorithm
(defun euclid (a b) "Compute the GCD of A and B using Euclid's algorithm." (let (temp) (loop :until #I( b == 0 ) :do #I( temp := b, b := a % b, a := temp )) a))
Example: Matrix Multiplication
(defun matmul (A B) "Compute C = A * B for matrices A and B." (let* ((m (arraydimension A 0)) (n (arraydimension A 1)) (q (arraydimension B 1)) (C (makearray (list m q) :initialelement 0))) (loop :for i :below m :do (loop :for k :below q :do (loop :for j :below n :do #I( C[i, k] += A[i, j] * B[j, k] )))) C)) ;; Example: (let ((A (makearray '(2 2) :initialcontents '((0 1) (1 0)))) (B (makearray '(2 1) :initialcontents '((2) (3))))) #I( matmul(A, B) ))
A full description of the supported operators is in the package documentation for CMUINFIX
:
(format t "~A" (documentation (findpackage :cmuinfix) t))
Modernization Updates
The library has been updated in the following ways:

The package of this library has been renamed
CMUINFIX
so as to not conflict with existing Quicklisp libraries. 
A system of the same name has been made so it is loadable by ASDF.

The tests have been lifted and put into a separate system called
CMUINFIXTESTS
. You can run them by doing(asdf:testsystem :cmuinfix)

The library was modified to use
NAMEDREADTABLES
to not eagerly pollute your readtable. 
Some outofdate comments have been deleted.
Contributing
After receiving permission from Mark Kantrowitz, Rigetti Computing has taken stewardship of the library. Questions and issues should be filed on GitHub here, and pull requests are welcome. The licensing terms are described in LICENSE.txt
.