Browse Source

Update.

master
Michael Fiano 2 months ago
parent
commit
e50ddecb0c
Signed by: mfiano
GPG Key ID: F87DF4666D70FC63
  1. 14
      README.md
  2. 8
      mfiano-utils.asd
  3. 2
      src/array.lisp
  4. 7
      src/character.lisp
  5. 2
      src/closure.lisp
  6. 2
      src/filesystem.lisp
  7. 2
      src/hash-table.lisp
  8. 2
      src/list-alist.lisp
  9. 16
      src/list-plist.lisp
  10. 2
      src/list.lisp
  11. 39
      src/macro.lisp
  12. 2
      src/math.lisp
  13. 6
      src/misc.lisp
  14. 2
      src/number.lisp
  15. 24
      src/package.lisp
  16. 8
      src/sequence.lisp
  17. 2
      src/string.lisp
  18. 20
      src/symbol.lisp
  19. 7
      src/type.lisp

14
README.md

@ -1,23 +1,19 @@
# golden-utils
# mfiano-utils
Auxiliary Utilities (AU).
My personal utilities library.
## Overview
A collection of personal utilities that have been found useful.
A collection of personal utilities that I have found useful.
## Install
```lisp
(ql:quickload :golden-utils)
(ql:quickload :mfiano-utils)
```
## Usage
TODO
## License
Copyright © 2017-2020 Michael Fiano <mail@mfiano.net>
Copyright © 2017-2022 Michael Fiano <mail@mfiano.net>
Licensed under the MIT License.

8
golden-utils.asd → mfiano-utils.asd

@ -1,10 +1,12 @@
(asdf:defsystem #:golden-utils
(asdf:defsystem #:mfiano-utils
:description "A utility library."
:author ("Michael Fiano <mail@mfiano.net>")
:author "Michael Fiano <mail@mfiano.net>"
:license "MIT"
:homepage "https://git.mfiano.net/mfiano/golden-utils"
:homepage "https://github.com/mfiano/mfiano-utils"
:version "0.1.0"
:encoding :utf-8
:depends-on (#:alexandria
#:serapeum
#:uiop)
:pathname "src"
:serial t

2
src/array.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(declaim (inline make-b8-array))
(defun make-b8-array (size &optional (initial-element 0))

7
src/character.lisp

@ -1,9 +1,4 @@
(in-package #:golden-utils)
(defun ascii-char-p (char)
"Check if the character `CHAR` is an ASCII character."
(and (characterp char)
(<= 0 (char-code char) 127)))
(in-package #:mfiano-utils)
(defun ascii-lowercase-p (char)
"Check if the character `CHAR` is a lowercase ASCII character."

2
src/closure.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
;;; The following is an implementation of "Pandoric Macros", documented by Doug
;;; Hoyte in "Let Over Lambda". Some minor improvements and style changes are

2
src/filesystem.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defmacro with-file-input ((stream path) &body body)
"Open the file at location `PATH` as input and perform `BODY`."

2
src/hash-table.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defmacro do-hash ((key value table &optional result) &body body)
"Iterates over hash table `TABLE`, binding each key to `KEY`, and its value to

2
src/list-alist.lisp

@ -1,7 +1,7 @@
;;;; Association lists.
;;;; Various functions dealing with association lists.
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(deftype alist () '(satisfies alist-p))

16
src/list-plist.lisp

@ -1,7 +1,7 @@
;;;; Property lists
;;;; Various functions dealing with property lists.
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(deftype plist () '(satisfies plist-p))
@ -25,20 +25,6 @@
(define-modify-macro plist-removef (&rest keys) plist-remove
"Place-modifying macro for PLIST-REMOVE.")
(defun plist-keys (plist)
"Get a list of all keys in `PLIST`."
(if (plist-p plist)
(loop :for (key nil) :on plist :by #'cddr
:collect key)
(error "~a is not a property list." plist)))
(defun plist-values (plist)
"Get a list of all values in `PLIST`."
(if (plist-p plist)
(loop :for (nil value) :on plist :by #'cddr
:collect value)
(error "~a is not a property list." plist)))
(defun plist->alist (plist)
"Convert `PLIST` to an association list."
(if (plist-p plist)

2
src/list.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun interleave (&rest lists)
"Interleave the elements of `LISTS`."

39
src/macro.lisp

@ -1,22 +1,11 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defmacro define-printer ((object stream &key (type t) identity) &body body)
(defmacro define-printer ((object stream &key (type t) (identity t)) &body body)
"Define a PRINT-OBJECT method for `OBJECT`."
`(defmethod print-object ((,object ,object) ,stream)
(print-unreadable-object (,object ,stream :type ,type :identity ,identity)
,@body)))
(defmacro defun-inline (name args &body body)
"Conveniently define the function `NAME` and also inline it."
(multiple-value-bind (body decls doc)
(alexandria:parse-body body :documentation t)
`(progn
(declaim (inline ,name))
(defun ,name ,args
,@(when doc `(,doc))
,@decls
,@body))))
(defmacro when-found ((var lookup) &body body)
"If `LOOKUP` is successful, perform `BODY` with `VAR` bound to the result.
`LOOKUP` is an expression that returns two values, with the second value
@ -108,10 +97,6 @@ GETHASH."
(declare (ignorable ,@(hash-keys mapping)))
,@body))))))
(defmacro eval-always (&body body)
`(eval-when (:compile-toplevel :load-toplevel :execute)
,@body))
(defmacro with-temp-package (&body body)
(with-gensyms (package package-name)
`(let ((,package (or (find-package ',package-name)
@ -120,3 +105,23 @@ GETHASH."
(let ((*package* ,package))
,@body)
(delete-package ,package)))))
(defmacro define-package (package &body options)
(let ((extension-keywords '(:inherit :inherit-external)))
`(defpackage ,package
,@(remove-if (lambda (x) (member x extension-keywords)) options :key #'car)
,@(mappend
(lambda (x)
(destructuring-bind (package . symbols) (rest x)
`((:shadowing-import-from ,package ,@symbols)
(:export ,@symbols))))
(remove :inherit options :key #'car :test (complement #'eq)))
,@(mappend
(lambda (x)
(destructuring-bind (package) (rest x)
(let ((symbols (collect-external-symbols
package
:key (lambda (x) (make-symbol (symbol-name x))))))
`((:shadowing-import-from ,package ,@symbols)
(:export ,@symbols)))))
(remove :inherit-external options :key #'car :test (complement #'eq))))))

2
src/math.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(declaim (inline degrees->radians))
(defun degrees->radians (degrees)

6
src/misc.lisp

@ -1,4 +1,8 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun doc (string)
"Convenience function for writing docstrings; intended to be read-evaluation with `#.`."
(format nil string))
(defun noop (&rest args)
"Do nothing."

2
src/number.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun count-digits (integer)
"Return the number of digits of `INTEGER`."

24
src/package.lisp

@ -1,15 +1,18 @@
(in-package #:cl-user)
(uiop:define-package #:golden-utils
(uiop:define-package #:mfiano-utils
(:use #:cl)
(:mix-reexport #:alexandria)
(:mix-reexport #:serapeum #:alexandria)
(:shadow
#:make-keyword)
#:dict
#:href
#:make-keyword
#:mvlet
#:mvlet*)
;; Macros
(:export
#:define-package
#:define-printer
#:defun-inline
#:eval-always
#:fn->
#:if-found
#:mvlet
@ -45,8 +48,6 @@
#:f64
#:f64a
#:fixnum-array
#:octet
#:octet-vector
#:ub8
#:ub8a
#:ub16
@ -68,7 +69,6 @@
;; Characters
(:export
#:ascii-alphanumeric-p
#:ascii-char-p
#:ascii-control-p
#:ascii-letter-p
#:ascii-lowercase-p
@ -102,6 +102,7 @@
(:export
#:do-seq
#:enumerate
#:find-all
#:flatten-tree
#:flatten-numbers)
;; Lists
@ -139,10 +140,8 @@
#:plist
#:plist-p
#:plist-get
#:plist-keys
#:plist-remove
#:plist-removef
#:plist-values
#:plist->alist
#:plist->hash)
;; Hash tables
@ -151,12 +150,12 @@
#:do-hash
#:do-hash-keys
#:do-hash-values
#:href
#:hash-keys
#:hash-merge
#:hash-values
#:hash->alist
#:hash->plist)
#:hash->plist
#:href)
;; Filesystem
(:export
#:file->string
@ -176,4 +175,5 @@
#:radians->degrees)
;; Misc
(:export
#:doc
#:noop))

8
src/sequence.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun flatten-tree (sequence)
"Traverses a sequence in order, collecting non-nil values into a list. This is
@ -41,3 +41,9 @@ incrementing from `START` by `STEP`, and each cdr being the element of
"Iterates over `SEQUENCE`, binding `VAR` to each element. Like DOLIST, but for
all sequence types."
`(map nil (lambda (,var) ,@body) ,sequence))
(defun find-all (item sequence &rest args &key (test #'eql) test-not &allow-other-keys)
"Find all elements in `SEQUENCE` that match `ITEM`. Taken from PAIP."
(if test-not
(apply #'remove item sequence :test-not (complement test-not) args)
(apply #'remove item sequence :test (complement test) args)))

2
src/string.lisp

@ -1,4 +1,4 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun string-merge (&rest strings)
"Merge `STRINGS` into a single string."

20
src/symbol.lisp

@ -1,17 +1,23 @@
(in-package #:golden-utils)
(in-package #:mfiano-utils)
(defun collect-symbols (&optional (package *package*))
(defun collect-symbols (package &key key test)
"Collect a list of all symbols of `PACKAGE`."
(let (symbols)
(let ((key (or key #'identity))
(test (or test (constantly t)))
(symbols nil))
(do-symbols (symbol package)
(push symbol symbols))
(when (funcall test symbol)
(push (funcall key symbol) symbols)))
(nreverse symbols)))
(defun collect-external-symbols (&optional (package *package*))
(defun collect-external-symbols (package &key key test)
"Collect a list of all external symbols of `PACKAGE`."
(let (symbols)
(let ((key (or key #'identity))
(test (or test (constantly t)))
(symbols nil))
(do-external-symbols (symbol package)
(push symbol symbols))
(when (funcall test symbol)
(push (funcall key symbol) symbols)))
(nreverse symbols)))
(defun make-keyword (object)

7
src/type.lisp

@ -1,9 +1,4 @@
(in-package #:golden-utils)
(deftype octet () '(unsigned-byte 8))
(deftype octet-vector (&optional length)
`(simple-array octet ,(if (integerp length) `(,length) length)))
(in-package #:mfiano-utils)
(deftype fixnum-array (&optional length)
`(simple-array fixnum ,(if (integerp length) `(,length) length)))

Loading…
Cancel
Save