diff options
author | aleksei <aleksei@aj.org> | 2024-04-13 11:09:45 +1000 |
---|---|---|
committer | aleksei <aleksei@aj.org> | 2024-04-13 11:09:45 +1000 |
commit | 3b2b63913b1a550c8469acd3943abafbf22ccd13 (patch) | |
tree | d948d603f0eb380c6f171df568dd11e02a84733c /utilities.lisp | |
parent | fafbeb6051a15232df1858ce64ff0375597b5044 (diff) |
macro table gen. , syntax-rule works with *grammar*
Diffstat (limited to 'utilities.lisp')
-rw-r--r-- | utilities.lisp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/utilities.lisp b/utilities.lisp index 414f0f2..c231f72 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |# (defun extract-keys (alist) - "Extract the keys of associative lists." + "Extract the keys of an associative list." (let ((return-value nil)) (progn (dolist (i alist) @@ -27,8 +27,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (cons (car i) return-value))) (reverse return-value)))) +(defun last-char (s) + (char s (- (length s) 1))) + (defun hexd? (string) - "Is a string a hexd number?" + "Is string a hexadecimal number?" (let ((stack ())) (dotimes (i (length string)) (push @@ -45,9 +48,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (eval stack))) (defun hex2dec (string) - "Convert an arbitrarily sized hexd number (as string) to a positive decimal." + "Convert an arbitrarily sized hexadecimal number (as string) to a positive decimal." (if (hexd? string) - (flet ((hex (c) ;Return character as hexadecimal + ;; Return a character as a hexadecimal digit. + (flet ((hex (c) (cond ((and (char-not-lessp c #\0) (char-not-greaterp c #\9)) @@ -58,6 +62,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (+ (- (char-code (char-downcase c)) (char-code #\a)) 10))))) (let ((return-value 0)) + ;; Loop through string and convert. (do ((i 0 (incf i)) (j (- (length string) 1) (decf j))) ((minusp j) ()) @@ -66,4 +71,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (* (expt 16 j) (hex (char string i)))))) return-value)) - nil)) + ;; Return nil if string was not a hexadecimal number. + nil)) |