The cmu-infix Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cmu-infix Reference Manual

This is the cmu-infix Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:44:48 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

CMU-INFIX

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 in-line with contemporary Common Lisp usage.

Example Use

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))

Modernization Updates

The library has been updated in the following ways:

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](LICENSE.t


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cmu-infix

Maintainer

Robert Smith <robert@rigetti.com>

Author

Mark Kantrowitz

License

Custom (See LICENSE.txt)

Description

Mathematical infix notation for Common Lisp.

Dependency

named-readtables

Source

cmu-infix.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cmu-infix.asd

Location

/home/quickbuilder/quicklisp/dists/quicklisp/software/cmu-infix-20180228-git/cmu-infix.asd

Systems

cmu-infix (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cmu-infix/package.lisp

Parent

cmu-infix (system)

Location

package.lisp

Packages

cmu-infix


Previous: , Up: Lisp files   [Contents][Index]

3.1.3 cmu-infix/cmu-infix.lisp

Dependency

package.lisp (file)

Parent

cmu-infix (system)

Location

cmu-infix.lisp

Exported Definitions

string->prefix (function)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 cmu-infix

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*.

Source

package.lisp (file)

Use List
Exported Definitions

string->prefix (function)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Functions

Function: string->prefix STRING

Convert a string to a prefix s-expression using the infix reader. If the argument is not a string, just return it as is.

Package

cmu-infix

Source

cmu-infix.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Special variables

Special Variable: *infix-readtable*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *normal-readtable*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *operator-ordering*

Ordered list of operators of equal precedence.

Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *peeked-token*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *right-associative-operators*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *token-infix-operator-table*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *token-operators*
Package

cmu-infix

Source

cmu-infix.lisp (file)

Special Variable: *token-prefix-operator-table*
Package

cmu-infix

Source

cmu-infix.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Macros

Macro: define-character-tokenization CHAR FUNCTION
Package

cmu-infix

Source

cmu-infix.lisp (file)

Macro: define-token-operator OPERATOR-NAME &key PREFIX INFIX
Package

cmu-infix

Source

cmu-infix.lisp (file)

Macro: infix-error FORMAT-STRING &rest ARGS
Package

cmu-infix

Source

cmu-infix.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Functions

Function: apply-token-infix-operator TOKEN LEFT STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: apply-token-prefix-operator TOKEN STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: fancy-number-format-p LEFT OPERATOR STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: gather-superiors PREVIOUS-OPERATOR STREAM

Gathers an expression whose operators all exceed the precedence of the operator to the left.

Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: get-first-token STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: get-next-token STREAM LEFT
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: get-token-infix-operator TOKEN
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: get-token-prefix-operator TOKEN
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: infix-read-delimited-list END-TOKEN DELIMITER-TOKEN STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: infix-reader STREAM SUBCHAR ARG
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: operator-lessp OP1 OP2
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: operator-right-associative-p OPERATOR
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: peek-token STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: post-process-expression EXPRESSION
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: read-infix STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: read-regular STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: read-token STREAM
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: same-operator-p X Y
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: same-token-p X Y
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: token-operator-p TOKEN
Package

cmu-infix

Source

cmu-infix.lisp (file)

Function: valid-numberp STRING
Package

cmu-infix

Source

cmu-infix.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cmu-infix.asd: The cmu-infix<dot>asd file
cmu-infix/cmu-infix.lisp: The cmu-infix/cmu-infix<dot>lisp file
cmu-infix/package.lisp: The cmu-infix/package<dot>lisp file

F
File, Lisp, cmu-infix.asd: The cmu-infix<dot>asd file
File, Lisp, cmu-infix/cmu-infix.lisp: The cmu-infix/cmu-infix<dot>lisp file
File, Lisp, cmu-infix/package.lisp: The cmu-infix/package<dot>lisp file

L
Lisp File, cmu-infix.asd: The cmu-infix<dot>asd file
Lisp File, cmu-infix/cmu-infix.lisp: The cmu-infix/cmu-infix<dot>lisp file
Lisp File, cmu-infix/package.lisp: The cmu-infix/package<dot>lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   A   D   F   G   I   M   O   P   R   S   T   V  
Index Entry  Section

A
apply-token-infix-operator: Internal functions
apply-token-prefix-operator: Internal functions

D
define-character-tokenization: Internal macros
define-token-operator: Internal macros

F
fancy-number-format-p: Internal functions
Function, apply-token-infix-operator: Internal functions
Function, apply-token-prefix-operator: Internal functions
Function, fancy-number-format-p: Internal functions
Function, gather-superiors: Internal functions
Function, get-first-token: Internal functions
Function, get-next-token: Internal functions
Function, get-token-infix-operator: Internal functions
Function, get-token-prefix-operator: Internal functions
Function, infix-read-delimited-list: Internal functions
Function, infix-reader: Internal functions
Function, operator-lessp: Internal functions
Function, operator-right-associative-p: Internal functions
Function, peek-token: Internal functions
Function, post-process-expression: Internal functions
Function, read-infix: Internal functions
Function, read-regular: Internal functions
Function, read-token: Internal functions
Function, same-operator-p: Internal functions
Function, same-token-p: Internal functions
Function, string->prefix: Exported functions
Function, token-operator-p: Internal functions
Function, valid-numberp: Internal functions

G
gather-superiors: Internal functions
get-first-token: Internal functions
get-next-token: Internal functions
get-token-infix-operator: Internal functions
get-token-prefix-operator: Internal functions

I
infix-error: Internal macros
infix-read-delimited-list: Internal functions
infix-reader: Internal functions

M
Macro, define-character-tokenization: Internal macros
Macro, define-token-operator: Internal macros
Macro, infix-error: Internal macros

O
operator-lessp: Internal functions
operator-right-associative-p: Internal functions

P
peek-token: Internal functions
post-process-expression: Internal functions

R
read-infix: Internal functions
read-regular: Internal functions
read-token: Internal functions

S
same-operator-p: Internal functions
same-token-p: Internal functions
string->prefix: Exported functions

T
token-operator-p: Internal functions

V
valid-numberp: Internal functions

Jump to:   A   D   F   G   I   M   O   P   R   S   T   V  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
S  
Index Entry  Section

*
*infix-readtable*: Internal special variables
*normal-readtable*: Internal special variables
*operator-ordering*: Internal special variables
*peeked-token*: Internal special variables
*right-associative-operators*: Internal special variables
*token-infix-operator-table*: Internal special variables
*token-operators*: Internal special variables
*token-prefix-operator-table*: Internal special variables

S
Special Variable, *infix-readtable*: Internal special variables
Special Variable, *normal-readtable*: Internal special variables
Special Variable, *operator-ordering*: Internal special variables
Special Variable, *peeked-token*: Internal special variables
Special Variable, *right-associative-operators*: Internal special variables
Special Variable, *token-infix-operator-table*: Internal special variables
Special Variable, *token-operators*: Internal special variables
Special Variable, *token-prefix-operator-table*: Internal special variables

Jump to:   *  
S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

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