Commit 63025912 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Initial definition of parameters as dynamic variables

New macro definition define-parameter which defines (or uses) a package for the category, and expands to define a dynamic variable. Macro expansion looks sensible, but more definitions are needed to make this usable.
parent c5216683
;; Standard metadata to attach to variables.
;; Liam Healy 2013-02-16 20:51:14HST variable-metadata.lisp
;; Time-stamp: <2013-02-16 22:12:48HST variable-metadata.lisp>
;; Time-stamp: <2013-04-07 19:31:01EDT variable-metadata.lisp>
;; Copyright 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -18,21 +18,16 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
(in-package :antik)
;;; Properties: default type description attribute latex latex-supplement
;;; From the previous parameters implementation,
;;; properties: default type description attribute latex latex-supplement
(defvar *variable-properties*
'(default type documentation attribute symbol))
;;; symbol will be both plain, latex or latex-supplement if attribute
;;; Some information needed on how to format output,
;;; for eac hformat form plain, latex or latex-supplement if attribute
;;; (subscript 1)
;;; (plain "sma" latex "a")
(defun set-variable-metadata (symbol property value)
(if (member property *variable-properties*)
(setf (get symbol property) value)
(error "Property ~a is not one of ~a." property *variable-properties*)))
;;; For globals
;;; Proclaim the type.
;;; Proclaim the variable special.
......@@ -41,3 +36,44 @@
;;; Non-top-level
;;; (proclaim '(special a))
;;; (proclaim '(type velocity a)) ; will be checked at least by SBCL.
;;;; [2013-04-07 Sun 18:31] Start over
(defvar *categories* nil "Categories of parameters, which correspond to packages.")
(defvar *parameters* nil "Parameters.")
(defvar *symbols* (make-hash-table) "Parameter symbols.")
;;; define an add-to-symbol-table
(defun ensure-package (package)
"If the non-nil package designator designates an existing package, return it. If it designates a non-existent package, make and return it. Otherwise, return the current package."
;; Check that we're not trying to use the keyword, etc. package?
(or (when package (or (find-package package) (make-package package)))
(defun add-to-symbol-table (list canonical-symbol)
"Add the list of symbols to the hash table."
;; warn if redefining?
(mapcar (lambda (symb) (setf (gethash symb *symbols*) canonical-symbol)) list))
(defmacro define-parameter
(category name
&key value (type nil type-supplied-p) (attribute nil attribute-supplied-p) description synonyms)
"Define the parameter (global special variable) with the given name. It will be defined in the package named by category (which will be created if necessary), and exported from it."
(let* ((package (ensure-package category))
(symbol (let ((*package* package)) (alexandria:symbolicate name)))
(syns (let ((*package* package)) (mapcar 'alexandria:symbolicate synonyms))))
(check-parameter-type value type t symbol 'delete-this) ; will need to be rewritten to not take symbol
(defparameter ,symbol ,value ,description)
(export ,symbol ,(package-name package))
,@(when type-supplied-p `((setf (get ',symbol :type) ',type)))
,@(when attribute-supplied-p `((setf (get ',symbol :attribute) ',attribute)))
(pushnew ',symbol *parameters*)
(add-to-symbol-table ,(cons symbol syns) ,symbol))))
;;; Test definition
(define-parameter nf :style :value 20
:type (or null fixnum (member :tex :short :readable))
:description "Style of format, plain (nil), LaTeX (:tex), or plain but")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment