chiark
/
gitweb
/
~mdw
/
lisp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git+ssh://metalzone.distorted.org.uk/~mdw/public-git/lisp
[lisp]
/
mdw-base.lisp
diff --git
a/mdw-base.lisp
b/mdw-base.lisp
index 0b68b8d69be12b4476f62c82ceb43c6e6217ef51..c4c3e1748224af8bb00c0c73d3aa98363880ca71 100644
(file)
--- a/
mdw-base.lisp
+++ b/
mdw-base.lisp
@@
-28,12
+28,13
@@
(defpackage #:mdw.base
(:use #:common-lisp)
(defpackage #:mdw.base
(:use #:common-lisp)
- (:export #:compile-time-defun
+ (:export #:unsigned-fixnum
+ #:compile-time-defun
#:show
#:show
- #:stringify #:listify #:fix-pair #:pairify #:parse-body
+ #:stringify #:
mappend #:
listify #:fix-pair #:pairify #:parse-body
#:whitespace-char-p
#:slot-uninitialized
#:whitespace-char-p
#:slot-uninitialized
- #:nlet #:while #:case2 #:ecase2
+ #:nlet #:while #:
until #:
case2 #:ecase2
#:with-gensyms #:let*/gensyms #:with-places
#:locp #:locf #:ref #:with-locatives
#:update-place #:update-place-after
#:with-gensyms #:let*/gensyms #:with-places
#:locp #:locf #:ref #:with-locatives
#:update-place #:update-place-after
@@
-43,6
+44,13
@@
(defpackage #:mdw.base
(in-package #:mdw.base)
(in-package #:mdw.base)
+;;;--------------------------------------------------------------------------
+;;; Useful types.
+
+(deftype unsigned-fixnum ()
+ "Unsigned fixnums; useful as array indices and suchlike."
+ `(mod ,most-positive-fixnum))
+
;;;--------------------------------------------------------------------------
;;; Some simple macros to get things going.
;;;--------------------------------------------------------------------------
;;; Some simple macros to get things going.
@@
-53,11
+61,17
@@
(defmacro compile-time-defun (name args &body body)
(defun ,name ,args ,@body)))
(defmacro show (x)
(defun ,name ,args ,@body)))
(defmacro show (x)
- "Debugging tool: print the expression X and its value."
+ "Debugging tool: print the expression X and its value
s
."
(let ((tmp (gensym)))
(let ((tmp (gensym)))
- `(let ((,tmp ,x))
- (format t "~&~S: ~S~%" ',x ,tmp)
- ,tmp)))
+ `(let ((,tmp (multiple-value-list ,x)))
+ (format t "~&")
+ (pprint-logical-block (*standard-output* nil :per-line-prefix ";; ")
+ (format t
+ "~S = ~@_~:I~:[#<no values>~;~:*~{~S~^ ~_~}~]"
+ ',x
+ ,tmp))
+ (terpri)
+ (values-list ,tmp))))
(defun stringify (str)
"Return a string representation of STR. Strings are returned unchanged;
(defun stringify (str)
"Return a string representation of STR. Strings are returned unchanged;
@@
-69,6
+83,12
@@
(defun stringify (str)
(t (with-output-to-string (s)
(princ str s)))))
(t (with-output-to-string (s)
(princ str s)))))
+(defun mappend (function list &rest more-lists)
+ "Apply FUNCTION to corresponding elements of LIST and MORE-LISTS, yielding
+ a list. Return the concatenation of all the resulting lists. Like
+ mapcan, but nondestructive."
+ (apply #'append (apply #'mapcar function list more-lists)))
+
(compile-time-defun listify (x)
"If X is a (possibly empty) list, return X; otherwise return (list X)."
(if (listp x) x (list x)))
(compile-time-defun listify (x)
"If X is a (possibly empty) list, return X; otherwise return (list X)."
(if (listp x) x (list x)))
@@
-177,9
+197,11
@@
(defmacro nlet (name binds &body body)
(defmacro while (cond &body body)
"If COND is false, evaluate to nil; otherwise evaluate BODY and try again."
(defmacro while (cond &body body)
"If COND is false, evaluate to nil; otherwise evaluate BODY and try again."
- `(loop
- (unless ,cond (return))
- ,@body))
+ `(loop (unless ,cond (return)) (progn ,@body)))
+
+(defmacro until (cond &body body)
+ "If COND is true, evaluate to nil; otherwise evaluate BODY and try again."
+ `(loop (when ,cond (return)) (progn ,@body)))
(compile-time-defun do-case2-like (kind vform clauses)
"Helper function for `case2' and `ecase2'."
(compile-time-defun do-case2-like (kind vform clauses)
"Helper function for `case2' and `ecase2'."