factored out xls compat for data stuff.
[CommonLispStat.git] / src / data / data-xls-compat.lisp
blobd5fe9bc448453e9e8a08a22f217e55a9780780cd
1 ;;; -*- mode: lisp -*-
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
9 ;;; for information.
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.
23 ;;;;
24 ;;;; Listing and Saving Variables and Functions (XLispStat compatibility)
25 ;;;;
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."
36 `(progn
37 (unless (and *ask-on-redefine*
38 (boundp ',symbol)
39 (not (y-or-n-p "Variable has a value. Redefine?")))
40 (defparameter ,symbol ,value))
41 (pushnew ',symbol *variables*)
42 ',symbol))
44 (defun variables-list ()
45 "Return list of variables as a lisp list of strings."
46 (mapcar #'intern (sort-data (mapcar #'string *variables*))))
48 (defun variables ()
49 "Args:()
50 Returns a list of the names of all def'ed variables to STREAM"
51 (if *variables*
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
59 load command."
60 (with-open-file (f (concatenate 'string (namestring file) ".lsp")
61 :direction :output)
62 (let ((vars (if (consp vars) vars (list vars))))
63 (flet ((save-one (x)
64 (let ((v (symbol-value x)))
65 (if (objectp v)
66 (format f "(def ~s ~s)~%" x (send v :save))
67 (format f "(def ~s '~s)~%" x v)))))
68 (mapcar #'save-one vars))
69 vars)))
71 (defun undef (v)
72 "Args: (v)
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*))
79 (makunbound s)))