Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the ugly-tiny-infix-macro Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 15:23:51 2020 GMT+0.
• Introduction | What ugly-tiny-infix-macro 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 |
This is a powerful lisp macro for the purpose of writing your expressions in infix notation while not losing out on lisp's power.
Let's look at a few examples
At its simplest,
($ 1 + 2) ; gets converted to (+ 1 2), where name of the macro is $
($ t and nil) ; gets converted to (and t nil)
($ 3 > 5) ; gets converted to (> 3 5)
($ 1 + 2 + 3) ; gets converted to (+ (+ 1 2) 3)
You can use various operators (which is just a fancy name for a function) at once and they're grouped according to the precedence.
Default precedence of operators that ships with the project is taken from the C++ standard. Check the default-operator-precedence-alist.lisp
file for a full list of operators available by default. Check out the section on customizing the list of operators and their priorities if you wish to do so.
($ 1 + 2 * 3) ; gets converted to (+ 1 (* 2 3))
($ 1 < 2 and 2 < 3) ; gets converted to (AND (< 1 2) (< 2 3))
Anything within parentheses at position of an operand is treated like a lisp form.
($ 2 + (max 9 10 11)) ; gets converted to (+ 2 (max 9 10 11)). It could have been any function / lisp form.
($ 6 / ($ 1 + 2)) ; gets converted to (/ 6 ($ 1 + 2)), and then subsequently to (/6 (+ 1 2))
As illustrated by the last example, nesting the macro can be used for "grouping" or "higher precedence" so that it's evaluated first like is done with brackets in mathematical notation.
You may write the last example as 6 / (1 + 2) in math. Most deeply nested brackets are executed the first, and same is the case when you nest this macro.
WARNING: As explained in the example on nesting the macro, brackets are assumed to be valid lisp forms. Do not use them for grouping. Writing ($ 6 / (1 + 2))
will give you an error as it's expanded to (/ 6 (1 + 2))
and (1 + 2)
is not a valid lisp form. Your lisp environment will try to evaluate it and find that 1
isn't name of a function that can be called with the arguments +
and 2
. This is what puts "ugly" in the the name of the project, because it's not prettiest to the eye, but some may find that it's easy to reason about.
This package is available on quicklisp. You may install it using
(ql:quickload :ugly-tiny-infix-macro)
Alternately, you can dowload the source files manually and load it via asdf
The package, named :ugly-tiny-lisp-macro
with the nickname :ugly-infix
exports three symbols -
$
: this is the macro itself*operator-precedence-alist*
: An alist of operators (lisp functions) and their prioritiesmalformed-infix-expression-error
: A condition which is signaled when something other than the operators in `operator-precedence-alist is found at even positions in the expression, or if the expression length is not an odd number.Operator precedence is stored as an alist associated with the symbol *operator-precedence-alist*
. An example of a valid alist that one may assign for DMAS precedence may look like:
(setf ugly-infix:*operator-precedence-alist*
'(( / . 1) ; a lower number means a higher priority/precedence
( * . 1) ; / and * are at the same priority/precedence
( + . 2) ; a higher number means a lower priority/precedence
( - . 2)))
You may modify *operator-precedence-alist*
in any manner by resetting, pushing, etc as long as it is a valid alist of operators and their priority. The position in the list / order of cons elements does not matter.
Note that this project only deals with binary operators, e.g. functions that accept (operate on) two arguments.
This project is licensed under the terms of APACHE 2.0 license. Please see the LICENSE
file for the text of the license.
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The ugly-tiny-infix-macro system |
Peeyush Kushwaha <peeyush.p97+dev@gmail.com>
Apache License, Version 2.0
A tiny and simple macro to allow writing binary operations in infix notation
ugly-tiny-infix-macro.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
Next: The ugly-tiny-infix-macro/defpackage․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
ugly-tiny-infix-macro.asd
ugly-tiny-infix-macro (system)
Next: The ugly-tiny-infix-macro/default-operator-precedence-alist․lisp file, Previous: The ugly-tiny-infix-macro․asd file, Up: Lisp files [Contents][Index]
ugly-tiny-infix-macro (system)
defpackage.lisp
Next: The ugly-tiny-infix-macro/error-handling․lisp file, Previous: The ugly-tiny-infix-macro/defpackage․lisp file, Up: Lisp files [Contents][Index]
defpackage.lisp (file)
ugly-tiny-infix-macro (system)
default-operator-precedence-alist.lisp
*operator-precedence-alist* (special variable)
Next: The ugly-tiny-infix-macro/ugly-tiny-infix-macro․lisp file, Previous: The ugly-tiny-infix-macro/default-operator-precedence-alist․lisp file, Up: Lisp files [Contents][Index]
ugly-tiny-infix-macro (system)
error-handling.lisp
malformed-infix-expression-error (condition)
Previous: The ugly-tiny-infix-macro/error-handling․lisp file, Up: Lisp files [Contents][Index]
error-handling.lisp (file)
ugly-tiny-infix-macro (system)
ugly-tiny-infix-macro.lisp
$ (macro)
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The ugly-tiny-infix-macro package |
defpackage.lisp (file)
ugly-infix
common-lisp
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 special variables | ||
• Exported macros | ||
• Exported conditions |
Next: Exported macros, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Next: Exported conditions, Previous: Exported special variables, Up: Exported definitions [Contents][Index]
Infix binary operations for lisp!
ugly-tiny-infix-macro.lisp (file)
Previous: Exported macros, Up: Exported definitions [Contents][Index]
error-handling.lisp (file)
error (condition)
:text
malformed-infix-expression-error-text (generic function)
:expression
malformed-infix-expression-error-expression (generic function)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal functions | ||
• Internal generic functions |
Next: Internal generic functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
ugly-tiny-infix-macro.lisp (file)
error-handling.lisp (file)
error-handling.lisp (file)
ugly-tiny-infix-macro.lisp (file)
ugly-tiny-infix-macro.lisp (file)
Previous: Internal functions, Up: Internal definitions [Contents][Index]
error-handling.lisp (file)
error-handling.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 U |
---|
Jump to: | F L U |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | $
A C F G M R S |
---|
Jump to: | $
A C F G M R S |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
E S T |
---|
Jump to: | *
E S T |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C M P S U |
---|
Jump to: | C M P S U |
---|