Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the mexpr Reference Manual, version 0.2.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 14:23:56 2020 GMT+0.
• Introduction | What mexpr 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 |
Macro for Common Lisp to allow infix syntax for mathematical expressions.
The mexpr package contains the infix
macro which converts infix expressions into Lisp S-Expressions.
The easiest way to install mexpr is with quicklisp.
(ql:quickload :mexpr)
The following are examples of how the infix
macro can be used:
CL-USER> (infix 3 + 4)
7
CL-USER> (infix [ 3 + 4 ] * 5)
35
CL-USER (infix 3 + 4 * 5)
23
CL-USER> (let ((x 0))
(infix [ 4 + (1+ x) ] / (sqrt 4)))
2.5
CL-USER> (infix 4 + 4 < 7 or 2 > 6 / 16)
T
CL-USER> (infix 5 = 6)
NIL
CL-USER> (infix 5 = 5)
T
CL-USER> (infix 2 expt 5)
32
You can use defop
to add new operators:
CL-USER> (defop union 10) ; use function name and precedence
CL-USER> (infix '(1 2) union '(2 3))
(2 1 3 4)
CL-USER> (defop ++ 100 append) ; use operator symbol, precedence, and defition symbol
CL-USER> (infix '(1 2) ++ '(3 4))
(1 2 3 4)
CL-USER> (defop p 110 (lambda (a b) (+ (* a a) (* b b)))) ; use lambda for definition
CL-USER> (infix 3 p 4)
25
You can use a reader macro to make it a little simpler:
CL-USER> (enable-infix-syntax) ; equivalent to (cl-syntax:use-syntax :mexpr)
CL-USER> #n(3 + 4 ** 2)
19
The mexpr
(or more verbose bytecurry.mexpr
) package contains two main macros.
The infix
macro parses it's arguments as an infix expression and produces the corresponding s-expression. Each argument
is evaluated as one of the following forms:
[
and ]
are used for grouping expressions. (Parentheses were already taken.)defop
macro. It represents a binary operation.The infix
macro can detect some syntax errors, in which case it will create a syntax-error
condition. The type of the
syntax error can be obtained with syntax-error-type
. Unfortunately, at the moment some invalid forms simply produce strange results, such as a transposition of a operator and operand.
The defop
macro can be used to define new operators. It takes two parameters, the first is the unquoted symbol of the
operator, the second is the desired precedence of the operator (see below for precedence table). The symbol
should correspond to a function or macro which can accept exactly two arguments (although it may have more optional arguments).
The function infix-reader
is macro dispatch function which is available to the user to use in
any reader macro he/she desires. The package also registers the "#n" dispatch with cl-syntax, so
you can enable syntax of the form #n(<expr>)
with (cl-syntax:use-syntax :mexpr)
. Alternatively,
enable-infix-syntax
is a wrapper around cl-syntax:use-syntax
.
Unlike prefix and postfix notations, infix notation uses operator precedence to determine the order of evaluation.
mexpr
uses a numeric precedence system, where the precedence of an operator is a positive integer. A higher number
corresponds to a higher precedence. The precedence of the default operators is given below:
| Operator | Precedence | Translation of a <op> b
|:----------:|-----------:|:--------------------------
| ** | 110 | (expt a b)
| expt | 110 | (expt a b)
| * | 100 | (* a b)
| / | 100 | (/ a b)
| % | 100 | (mod a b)
| mod | 100 | (mod a b)
| rem | 100 | (rem a b)
| + | 90 | (+ a b)
| - | 90 | (- a b)
| ash | 80 | (ash a b)
| << | 80 | (ash a b)
| >> | 80 | (ash a (- b))
| < | 70 | (< a b)
| > | 70 | (> a b)
| <= | 70 | (<= a b)
| >= | 70 | (>= a b)
| = | 60 | (= a b)
| /= | 60 | (/= a b)
| logand | 50 | (logand a b)
| & | 50 | (logand a b)
| logxor | 40 | (logxor a b)
| ^ | 40 | (logxor a b)
| logior | 30 | (logior a b)
| \|| 30 | (logior a b)
| and | 20 | (and a b)
| or | 10 | (or a b)
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The mexpr system |
Thayne McCombs <bytecurry.software@gmail.com>
LLPGL
Macro for infix math expressions.
mexpr is a library which contains a macro for
embedding mathematical expressions in lisp code with a more traditional
infix syntax. It also contains a reader macro for said syntax, and a macro
to extend the syntax with additional operators.
0.2.0
mexpr.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The mexpr.asd file | ||
• The mexpr/package.lisp file | ||
• The mexpr/mexpr.lisp file | ||
• The mexpr/operators.lisp file |
Next: The mexpr/package․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
mexpr.asd
mexpr (system)
Next: The mexpr/mexpr․lisp file, Previous: The mexpr․asd file, Up: Lisp files [Contents][Index]
mexpr (system)
package.lisp
Next: The mexpr/operators․lisp file, Previous: The mexpr/package․lisp file, Up: Lisp files [Contents][Index]
package.lisp (file)
mexpr (system)
mexpr.lisp
Previous: The mexpr/mexpr․lisp file, Up: Lisp files [Contents][Index]
mexpr.lisp (file)
mexpr (system)
operators.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The bytecurry.mexpr package |
A library for embedding mathematical expressions in lisp code using traditional infix syntax.
package.lisp (file)
mexpr
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 macros | ||
• Exported functions | ||
• Exported generic functions | ||
• Exported conditions |
Next: Exported functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Define a new infix operator with the given name and precedence.
NAME is the symbol which will be used as a binary operator in an infix expression
PRECEDENCE is a positive integer for the precedence of the operator
FUNC is a symbol or lambda form that the operator will translate into during macro-expansion
mexpr.lisp (file)
Enable infix syntax with ’#n’, for example: #n(3 + 4) => 7
mexpr.lisp (file)
Macro to convert an infix expression, into an s-expression.
mexpr.lisp (file)
Next: Exported generic functions, Previous: Exported macros, Up: Exported definitions [Contents][Index]
Reader macro function to read infix expressions.
mexpr.lisp (file)
Next: Exported conditions, Previous: Exported functions, Up: Exported definitions [Contents][Index]
mexpr.lisp (file)
Previous: Exported generic functions, Up: Exported definitions [Contents][Index]
Error due to invalid syntax in infix expression
mexpr.lisp (file)
error (condition)
syntax-error-type (method)
:type
syntax-error-type (generic function)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal special variables | ||
• Internal functions | ||
• Internal structures | ||
• Internal types |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
Hash map of operator symbols to precedence.
mexpr.lisp (file)
Next: Internal structures, Previous: Internal special variables, Up: Internal definitions [Contents][Index]
mexpr.lisp (file)
mexpr.lisp (file)
Do the operation for the operands on the stack.
mexpr.lisp (file)
mexpr.lisp (file)
Get the symbol or lambda form for the operator.
mexpr.lisp (file)
Get the precedence of an operator.
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
Convert an infix expression, into an s-expression –implementation.
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
mexpr.lisp (file)
Next: Internal types, Previous: Internal functions, Up: Internal definitions [Contents][Index]
Structure for state of the operation stacks.
mexpr.lisp (file)
structure-object (structure)
list
op-state-operands (function)
(setf op-state-operands) (function)
list
op-state-operators (function)
(setf op-state-operators) (function)
Struct for information about an operator.
mexpr.lisp (file)
structure-object (structure)
integer
0
operator-precedence (function)
(setf operator-precedence) (function)
bytecurry.mexpr::form-head
(quote values)
operator-func (function)
(setf operator-func) (function)
Previous: Internal structures, Up: Internal definitions [Contents][Index]
The first subform of a compound form.
mexpr.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: | F L M |
---|
Jump to: | F L M |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | (
C D E F G H I M O P R S |
---|
Jump to: | (
C D E F G H I M O P R S |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
F O P S T |
---|
Jump to: | *
F O P S T |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | B C F M O P S T |
---|
Jump to: | B C F M O P S T |
---|