Browse files

Bug fix: including some of the utility functions that I was using fro…

…m Toolbox.

These were previously not present and the library was technically broken when I
removed the toolbox dependency.  I'm guessing that due to some stale fasl files,
the library seemed to work without actually including them.
  • Loading branch information...
1 parent 32bd76b commit 79b3b937d6e09228e17e48a50288c2277ed1f3d7 @smithzvk committed Oct 26, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 utils.lisp
@@ -6,6 +6,48 @@
(setf (cdr (last circular-list)) circular-list)
+(defun format-ext (str control-string &rest args)
+ "Just like format, except convert certain elements in the arg list into forms
+more readable by other programs. For instance, print all number types in the
+1e0 format \(i.e. no fractions or 1d0s), and print pathnames as namestrings.
+Format has all sorts of nooks and crannies, so I bet that this facility can be
+broken without too much effort."
+ (let ((*read-default-float-format* 'long-float))
+ (apply #'format str control-string
+ (labels
+ ((convert-to-external (tree)
+ (cond ((null tree) nil)
+ ((atom tree)
+ (typecase tree
+ (integer tree)
+ (number (float tree 0L0))
+ (pathname (namestring tree))
+ (t tree)))
+ ((consp tree)
+ (mapcar #'convert-to-external tree)))))
+ (convert-to-external args)))))
+;;; Symbol/string utilities
+(defun mkstr (&rest args)
+ "MaKe STRing"
+ (with-output-to-string (s)
+ (dolist (a args) (princ a s))))
+(defun mkdstr (&rest args)
+ "MaKe space Delimited STRing"
+ (apply #'mkdstr* " " args))
+(defun mkdstr* (delimiter &rest args)
+ "MaKe arbitrarily Delimited STRing"
+ (let ((new-args
+ (and args (shuffle args (make-list (1- (length args))
+ :initial-element delimiter)))))
+ (with-output-to-string (s)
+ (dolist (a new-args)
+ (princ a s)))))
;;; PPCRE extensions
(defun reg-scan-to-string (regex target-string &key (start 0) (end (length target-string)))
(multiple-value-bind (matches registers) (ppcre:scan-to-strings regex target-string :start start :end end)

0 comments on commit 79b3b93

Please sign in to comment.