You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ At its simplest,
15
15
16
16
You can use various operators (which is just a fancy name for a function) at once and they're grouped according to the precedence.
17
17
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.
19
19
20
20
($ 1 + 2 * 3) ; gets converted to (+ 1 (* 2 3))
21
21
($ 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
35
35
36
36
The package, named `:ugly-tiny-lisp-macro` with the nickname `:ugly-infix` exports three symbols -
37
37
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.
41
41
42
42
## Customizing The List of Operators and Their Priorities
43
43
44
44
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:
45
45
46
-
(setf ugly-infix:*operator-precedence-alist*
46
+
(setf ugly-infix:*operator-precedence-alist*
47
47
'(( / . 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)))
51
51
52
52
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.
Copy file name to clipboardExpand all lines: default-operator-precedence-alist.lisp
+9-5
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
(in-package:ugly-tiny-infix-macro)
2
2
;; 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++
;; this is an exported symbol, and may be changed/reset by the user
6
6
(defparameter*operator-precedence-alist*
@@ -18,13 +18,17 @@
18
18
(=.9)
19
19
(/=.9)
20
20
(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
24
27
(and.13)
25
28
(or.14)))
26
29
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
0 commit comments