From 7647011120e2be941aaba3ff23b5b5ab881ce077 Mon Sep 17 00:00:00 2001 From: Ringo Wantanabe Date: Tue, 22 Jan 2019 17:44:39 +0000 Subject: [PATCH] few more --- utils.lisp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/utils.lisp b/utils.lisp index 0ff7b8a..3ddac2d 100644 --- a/utils.lisp +++ b/utils.lisp @@ -7,7 +7,7 @@ (defparameter *-utils-lisp* t) (defparameter *-utils-depends* '(#:cl-ppcre)) -(defparameter *-utils-version* "0.0.2") +(defparameter *-utils-version* "0.1.2") ;;; -- Handle internal exporting -- @@ -40,7 +40,7 @@ contents))) (export? file-get-contents) -(defun utils->system (input output &key (name :utils) (description "Some random utilities") (author "Ringo ") (license "None")) +(defun utils->system (input output &key (name :iflan-utils) (description "Some random utilities") (author "Ringo ") (license "None")) "Write this file to an ASDF system." (let ((this (cadddr (read-from-string (file-get-contents input)))) (sysdef `(asdf:defsystem ,name @@ -63,6 +63,62 @@ ;;; --- actual (exported) code goes here --- +(defun true (f) + (not (null f))) + +(defun nop () + nil) + +(defun yep () + t) + +(defun mapline (input fi &key (read-line #'read-line)) + "Map lines from stream" + (loop for line = (funcall read-line input nil) + while line do (funcall fi line))) + +(defmacro strcat (&rest str) + `(apply #'concatenate (cons 'string ,@str))) + +(defmacro until (stmt) + `(let ((ret nil)) + (loop while (null (setf ret ,stmt))) + ret)) + +(defmacro until-trace (stmt) + `(let ((ret nil)) + (loop while (null (setf ret ,stmt)) + collect ret))) + +(defmacro popor (li or) + `(if (atom ,li) ,or + (pop ,li))) + +(defun rand-in (l &key (random #'random) ) + "Random member of, slide right if nil" + (let ((rng (funcall random (list-length l)))) + (let ((nl (nth rng l))) + (until (pop nl))))) + +(defun regex-replace-many (str matches replwith) + "Replace list of regexes with list of new string" + (let ((ret str)) + (loop for match in matches + for repl in replwith + do (setf ret (cl-ppcre:regex-replace-all match ret repl))))) + +(defun in-range(num r s) + (and (>= num r) + (<= num s))) + +(defun format-string (fmt &rest r) + (with-output-to-string (stream) + (apply #'format `(,stream ,fmt . ,r)))) + +(defmacro val-if-or (val test or) + `(let ((vv ,val)) + (if (funcall ,test vv) vv ,or))) + (defmacro popto (li val &key (test #'eql)) "pop() list
  • until (car li) is equal to , return elements pop()ed in new list" `(loop while (not (funcall ,test (car ,li) ,val))