Skip to content

Commit cc4e3d7

Browse files
committed
fix default precedence alist by correcting lisp bitwise function names; minor changes to README
1 parent cc3772b commit cc4e3d7

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ At its simplest,
1515

1616
You can use various operators (which is just a fancy name for a function) at once and they're grouped according to the precedence.
1717

18-
Default precedence of operators that ships with the project is taken from the [C++ standard](http://en.cppreference.com/w/cpp/language/operator_precedence). Check out the section on customizing the list of operators and their priorities if you wish to do so.
18+
Default precedence of operators that ships with the project is taken from the [C++ standard](http://en.cppreference.com/w/cpp/language/operator_precedence). 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.
1919

2020
($ 1 + 2 * 3) ; gets converted to (+ 1 (* 2 3))
2121
($ 1 < 2 and 2 < 3) ; gets converted to (AND (< 1 2) (< 2 3))
@@ -35,19 +35,19 @@ You may write the last example as 6 / (1 + 2) in math. Most deeply nested bracke
3535

3636
The package, named `:ugly-tiny-lisp-macro` with the nickname `:ugly-infix` exports three symbols -
3737

38-
- $ : this is the macro itself
39-
- *operator-precedence-alist* : An alist of operators (lisp functions) and their priorities
40-
- malformed-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.
38+
- `$` : this is the macro itself
39+
- `*operator-precedence-alist*` : An alist of operators (lisp functions) and their priorities
40+
- `malformed-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.
4141

4242
## Customizing The List of Operators and Their Priorities
4343

4444
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:
4545

46-
(setf ugly-infix:*operator-precedence-alist*
46+
(setf ugly-infix:*operator-precedence-alist*
4747
'(( / . 1) ; a lower number means a higher priority/precedence
48-
( * . 1) ; / and * are at the same priority/precedence
49-
( + . 2) ; a higher number means a lower priority/precedence
50-
( - . 2)))
48+
( * . 1) ; / and * are at the same priority/precedence
49+
( + . 2) ; a higher number means a lower priority/precedence
50+
( - . 2)))
5151

5252
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.
5353

default-operator-precedence-alist.lisp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(in-package :ugly-tiny-infix-macro)
22
;; default list of binary operations in the order of precedence, taken in the order that C++ takes it in sans lognor, logeqv and other binary operators unavailable in C++
3-
;; , see http://clhs.lisp.se/Body/f_logand.htm
3+
;; , see http://clhs.lisp.se/Body/f_bt_and.htm
44
;; reference used: http://en.cppreference.com/w/cpp/language/operator_precedence
55
;; this is an exported symbol, and may be changed/reset by the user
66
(defparameter *operator-precedence-alist*
@@ -18,13 +18,17 @@
1818
(= . 9)
1919
(/= . 9)
2020
(eq . 9) ; for checking boolean equality
21-
(logand . 10)
22-
(logxor . 11)
23-
(logior . 12) ; what's the i for? I hope this is same as cpp bitwise or
21+
(eql . 9) ; more ways for checking equality and returning a boolean
22+
(equal . 9)
23+
(bit-and . 10)
24+
(bit-xor . 11)
25+
(bit-ior . 12) ; ior = inclusive or = same as cpp's bitwise or
26+
;bit-nor and bit-nand are available but I'm unsure where to put them in this list
2427
(and . 13)
2528
(or . 14)))
2629

27-
;; unsure if I should add the following, they apparently serve as a way of division, see http://www.lispworks.com/documentation/HyperSpec/Body/f_floorc.htm
30+
;; unsure if I should add the following, they apparently serve as a way of division, but the second argument is optional. But the same can be said for the / function, that the second argument is optional
31+
;; see http://www.lispworks.com/documentation/HyperSpec/Body/f_floorc.htm
2832
;; (floor . 5)
2933
;; (ffloor . 5)
3034
;; (ceiling . 5)

0 commit comments

Comments
 (0)