3 ;;; Time-stamp: <2009-09-24 10:34:53 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: template.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. Currently licensed under MIT
8 ;;; license. See file LICENSE.mit in top-level directory
10 ;;; Purpose: Template header file
12 ;;; What is this talk of 'release'? Klingons do not make software
13 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
14 ;;; designers and quality assurance people in its wake.
16 ;;; This organization and structure is new to the 21st Century
17 ;;; version.. Think, "21st Century Schizoid Man".
19 (in-package :lisp-stat-data
)
21 ;; XLISPSTAT compatibility functions.
24 ;;;; Listing and Saving Variables and Functions (XLispStat compatibility)
27 (defvar *variables
* nil
)
28 (defvar *ask-on-redefine
* nil
)
30 (defmacro def
(symbol value
)
31 "Syntax: (def var form)
32 VAR is not evaluated and must be a symbol. Assigns the value of FORM to
33 VAR and adds VAR to the list *VARIABLES* of def'ed variables. Returns VAR.
34 If VAR is already bound and the global variable *ASK-ON-REDEFINE*
35 is not nil then you are asked if you want to redefine the variable."
37 (unless (and *ask-on-redefine
*
39 (not (y-or-n-p "Variable has a value. Redefine?")))
40 (defparameter ,symbol
,value
))
41 (pushnew ',symbol
*variables
*)
44 (defun variables-list ()
45 "Return list of variables as a lisp list of strings."
46 (mapcar #'intern
(sort-data (mapcar #'string
*variables
*))))
50 Returns a list of the names of all def'ed variables to STREAM"
52 (mapcar #'intern
(sort-data (mapcar #'string
*variables
*)))))
54 (defun savevar (vars file
)
55 "Args: (vars file-name-root)
56 VARS is a symbol or a list of symbols. FILE-NAME-ROOT is a string (or a symbol
57 whose print name is used) not endinf in .lsp. The VARS and their current values
58 are written to the file FILE-NAME-ROOT.lsp in a form suitable for use with the
60 (with-open-file (f (concatenate 'string
(namestring file
) ".lsp")
62 (let ((vars (if (consp vars
) vars
(list vars
))))
64 (let ((v (symbol-value x
)))
66 (format f
"(def ~s ~s)~%" x
(send v
:save
))
67 (format f
"(def ~s '~s)~%" x v
)))))
68 (mapcar #'save-one vars
))
73 If V is the symbol of a defined variable the variable it is unbound and
74 removed from the list of defined variables. If V is a list of variable
75 names each is unbound and removed. Returns V."
76 (dolist (s (if (listp v
) v
(list v
)))
77 (when (member s
*variables
*)
78 (setq *variables
* (delete s
*variables
*))