;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: macros.lisp,v 1.1 2003/04/28 23:51:59 kevin Exp $
+;;;; $Id: macros.lisp,v 1.5 2003/08/06 11:37:23 kevin Exp $
;;;;
;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
;;;; *************************************************************************
-(in-package :kmrcl)
+(in-package #:kmrcl)
(defmacro let-when ((var test-form) &body body)
`(let ((,var ,test-form))
`(labels ((self ,parms ,@body))
#'self))
-
(defmacro aif2 (test &optional then else)
(let ((win (gensym)))
`(multiple-value-bind (it ,win) ,test
(print-seconds secs)
(format t ", time per iteration: ")
(print-seconds (coerce (/ secs ,n) 'double-float))))))))
+
+(defmacro mv-bind (vars form &body body)
+ `(multiple-value-bind ,vars ,form
+ ,@body))
+
+;; From USENET
+(defmacro deflex (var val &optional (doc nil docp))
+ "Defines a top level (global) lexical VAR with initial value VAL,
+ which is assigned unconditionally as with DEFPARAMETER. If a DOC
+ string is provided, it is attached to both the name |VAR| and the
+ name *STORAGE-FOR-DEFLEX-VAR-|VAR|* as a documentation string of
+ kind 'VARIABLE. The new VAR will have lexical scope and thus may
+ be shadowed by LET bindings without affecting its global value."
+ (let* ((s0 (load-time-value (symbol-name '#:*storage-for-deflex-var-)))
+ (s1 (symbol-name var))
+ (p1 (symbol-package var))
+ (s2 (load-time-value (symbol-name '#:*)))
+ (backing-var (intern (concatenate 'string s0 s1 s2) p1)))
+ `(progn
+ (defparameter ,backing-var ,val ,@(when docp `(,doc)))
+ ,@(when docp
+ `((setf (documentation ',var 'variable) ,doc)))
+ (define-symbol-macro ,var ,backing-var))))