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

New function find-parameter-symbol

parent c9f6aa81
;; Standard metadata to attach to variables.
;; Liam Healy 2013-02-16 20:51:14HST variable-metadata.lisp
;; Time-stamp: <2013-04-20 13:19:45EDT variable-metadata.lisp>
;; Time-stamp: <2013-05-20 22:50:07EDT variable-metadata.lisp>
;; Copyright 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -83,17 +83,26 @@
(error "Parameter value ~a is not the required type or dimension ~a"
value type))))
(defun export-parameter-symbol (category name)
(export ',symbol ,(package-name (symbol-package symbol))))
(defun find-parameter-symbol (category name)
(canonical-parameter-name (find-symbol (string name) (ensure-package category))))
(defun find-parameter-symbol-exporting (category name)
(let ((symbol (find-parameter-symbol category name)))
(export symbol (package-name (symbol-package symbol)))
(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))))
(let* ((symbol (find-parameter-symbol-exporting category name))
(syns (mapcar (alexandria:curry 'find-parameter-symbol-exporting category) synonyms)))
(when type-supplied-p (check-parameter-type value type t))
(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*)
......@@ -104,3 +113,7 @@
:type (or null fixnum (member :tex :short :readable))
:synonyms (:foo)
:description "Style of format, plain (nil), LaTeX (:tex), or plain but")
(defmacro parameter-value (category name)
"Get or set the parameter value."
`(symbol-value ',(find-parameter-symbol category name)))
Markdown is supported
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