Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cmu-infix Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 13:07:45 2020 GMT+0.
• Introduction | What cmu-infix is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
A library for writing infix mathematical notation in Common Lisp.
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 in-line with contemporary Common Lisp usage.
This package uses named-readtables
to manage the readtables. If you've loaded CMU-INFIX
successfully, then you'll have this package loaded as well.
To use CMU-INFIX
, simply use the readtable named cmu-infix:syntax
:
(named-readtables:in-readtable cmu-infix: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: Power-of-Two Check
(defun power-of-two-p (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 (array-dimension A 0))
(n (array-dimension A 1))
(q (array-dimension B 1))
(C (make-array (list m q) :initial-element 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 (make-array '(2 2) :initial-contents '((0 1) (1 0))))
(B (make-array '(2 1) :initial-contents '((2) (3)))))
#I( matmul(A, B) ))
A full description of the supported operators is in the package documentation for CMU-INFIX
:
(format t "~A" (documentation (find-package :cmu-infix) t))
The library has been updated in the following ways:
The package of this library has been renamed CMU-INFIX
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 CMU-INFIX-TESTS
. You can run them by doing
(asdf:test-system :cmu-infix)
The library was modified to use NAMED-READTABLES
to not eagerly pollute your readtable.
Some out-of-date comments have been deleted.
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
](LICENSE.t
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The cmu-infix system |
Robert Smith <robert@rigetti.com>
Mark Kantrowitz
Custom (See LICENSE.txt)
Mathematical infix notation for Common Lisp.
named-readtables
cmu-infix.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The cmu-infix.asd file | ||
• The cmu-infix/package.lisp file | ||
• The cmu-infix/cmu-infix.lisp file |
Next: The cmu-infix/package․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
/home/quickref/quicklisp/dists/quicklisp/software/cmu-infix-20180228-git/cmu-infix.asd
cmu-infix (system)
Next: The cmu-infix/cmu-infix․lisp file, Previous: The cmu-infix․asd file, Up: Lisp files [Contents][Index]
Previous: The cmu-infix/package․lisp file, Up: Lisp files [Contents][Index]
package.lisp (file)
cmu-infix (system)
cmu-infix.lisp
string->prefix (function)
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The cmu-infix package |
Package holding the readtable designator for mathematical infix notation.
The following two tables enumerate the supported operators along with
their precedence.
Operators:
NOTE: == is equality, = is assignment (C-style).
\ quoting character: x\-y –> x-y
! lisp escape !(foo bar) –> (foo bar)
; comment
x = y assignment (setf x y)
x += y increment (incf x y)
x -= y decrement (decf x y)
x *= y multiply and store (setf x (* x y))
x /= y divide and store (setf x (/ x y))
x|y bitwise logical inclusive or (logior x y)
x^y bitwise logical exclusive or (logxor x y)
x&y bitwise logical and (logand x y)
x<<y left shift (ash x y)
x>>y right shift (ash x (- y))
~x ones complement (unary) (lognot x)
x and y conjunction (and x y)
x && y conjunction (and x y)
x or y disjunction (or x y)
x || y disjunction (or x y)
not x negation (not x)
x^^y exponentiation (expt x y)
x,y sequence (progn x y)
(x,y) sequence (progn x y)
also parenthesis (x+y)/z –> (/ (+ x y) z)
f(x,y) functions (f x y)
a[i,j] array reference (aref a i j)
x+y x*y arithmetic (+ x y) (* x y)
x-y x/y arithmetic (- x y) (/ x y)
-y value negation (- y)
x % y remainder (mod x y)
x<y x>y inequalities (< x y) (> x y)
x <= y x >= y inequalities (<= x y) (>= x y)
x == y equality (= x y)
x != y equality (not (= x y))
if p then q conditional (when p q)
if p then q else r conditional (if p q r)
Precedence:
The following precedence conventions are obeyed by the infix operators:
[ ( !
^^
~
* / %
+ -
<< >>
< == > <= != >=
&
^
|
not
and
or
= += -= *= /=
,
if
then else
] )
Note that logical negation has lower precedence than numeric comparison so that "not a<b" becomes (not (< a b)), which is different from the C precedence conventions. You can change the precedence conventions by modifying the value of the variable *operator-ordering*.
package.lisp (file)
string->prefix (function)
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported functions |
Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Convert a string to a prefix s-expression using the infix reader. If the argument is not a string, just return it as is.
cmu-infix.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal special variables | ||
• Internal macros | ||
• Internal functions |
Next: Internal macros, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
cmu-infix.lisp (file)
cmu-infix.lisp (file)
Ordered list of operators of equal precedence.
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
Next: Internal functions, Previous: Internal special variables, Up: Internal definitions [Contents][Index]
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
Previous: Internal macros, Up: Internal definitions [Contents][Index]
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
Gathers an expression whose operators all exceed the precedence of the operator to the left.
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
cmu-infix.lisp (file)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | C F L |
---|
Jump to: | C F L |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | A D F G I M O P R S T V |
---|
Jump to: | A D F G I M O P R S T V |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
S |
---|
Jump to: | *
S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C P S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
C | |||
cmu-infix : | The cmu-infix system | ||
cmu-infix : | The cmu-infix package | ||
| |||
P | |||
Package, cmu-infix : | The cmu-infix package | ||
| |||
S | |||
System, cmu-infix : | The cmu-infix system | ||
|
Jump to: | C P S |
---|