From aee87b691f1b63157221335d29ab008c45e2eca3 Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Wed, 28 Oct 2009 08:19:09 +0100 Subject: [PATCH] factored out xls compat for data stuff. Signed-off-by: AJ Rossini --- cls.asd | 1 + src/data/data-xls-compat.lisp | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/data/data-xls-compat.lisp diff --git a/cls.asd b/cls.asd index 63bf807..e5e7385 100644 --- a/cls.asd +++ b/cls.asd @@ -194,6 +194,7 @@ (:file "dataframe-matrixlike") (:file "dataframe-listoflist") (:file "data") + (:file "data-xls-compat") (:file "import") ;;(:file "listoflist") )) diff --git a/src/data/data-xls-compat.lisp b/src/data/data-xls-compat.lisp new file mode 100644 index 0000000..d5fe9bc --- /dev/null +++ b/src/data/data-xls-compat.lisp @@ -0,0 +1,80 @@ +;;; -*- mode: lisp -*- + +;;; Time-stamp: <2009-09-24 10:34:53 tony> +;;; Creation: <2009-03-12 17:14:56 tony> +;;; File: template.lisp +;;; Author: AJ Rossini +;;; Copyright: (c)2009--, AJ Rossini. Currently licensed under MIT +;;; license. See file LICENSE.mit in top-level directory +;;; for information. +;;; Purpose: Template header file + +;;; What is this talk of 'release'? Klingons do not make software +;;; 'releases'. Our software 'escapes', leaving a bloody trail of +;;; designers and quality assurance people in its wake. + +;;; This organization and structure is new to the 21st Century +;;; version.. Think, "21st Century Schizoid Man". + +(in-package :lisp-stat-data) + +;; XLISPSTAT compatibility functions. + +;;;; +;;;; Listing and Saving Variables and Functions (XLispStat compatibility) +;;;; + +(defvar *variables* nil) +(defvar *ask-on-redefine* nil) + +(defmacro def (symbol value) + "Syntax: (def var form) +VAR is not evaluated and must be a symbol. Assigns the value of FORM to +VAR and adds VAR to the list *VARIABLES* of def'ed variables. Returns VAR. +If VAR is already bound and the global variable *ASK-ON-REDEFINE* +is not nil then you are asked if you want to redefine the variable." + `(progn + (unless (and *ask-on-redefine* + (boundp ',symbol) + (not (y-or-n-p "Variable has a value. Redefine?"))) + (defparameter ,symbol ,value)) + (pushnew ',symbol *variables*) + ',symbol)) + +(defun variables-list () + "Return list of variables as a lisp list of strings." + (mapcar #'intern (sort-data (mapcar #'string *variables*)))) + +(defun variables () + "Args:() +Returns a list of the names of all def'ed variables to STREAM" + (if *variables* + (mapcar #'intern (sort-data (mapcar #'string *variables*))))) + +(defun savevar (vars file) +"Args: (vars file-name-root) +VARS is a symbol or a list of symbols. FILE-NAME-ROOT is a string (or a symbol +whose print name is used) not endinf in .lsp. The VARS and their current values +are written to the file FILE-NAME-ROOT.lsp in a form suitable for use with the +load command." + (with-open-file (f (concatenate 'string (namestring file) ".lsp") + :direction :output) + (let ((vars (if (consp vars) vars (list vars)))) + (flet ((save-one (x) + (let ((v (symbol-value x))) + (if (objectp v) + (format f "(def ~s ~s)~%" x (send v :save)) + (format f "(def ~s '~s)~%" x v))))) + (mapcar #'save-one vars)) + vars))) + +(defun undef (v) +"Args: (v) +If V is the symbol of a defined variable the variable it is unbound and +removed from the list of defined variables. If V is a list of variable +names each is unbound and removed. Returns V." + (dolist (s (if (listp v) v (list v))) + (when (member s *variables*) + (setq *variables* (delete s *variables*)) + (makunbound s))) + v) -- 2.11.4.GIT