Previous: Introduction to organization, Up: Organization of Computation


3.2 Parameters

Parameters are named values that are defined and used in computations or in presentation; the concept is distinct from Common Lisp's defparameter macro. They are organized into named categories; Antik itself defines one category, NF, which is used for numerical formatting. Each parameter is defined with a default value and description. The value can be changed with (setf parameter-value) and used with parameter-value, or changed locally (analogous to let for CL variables) with with-parameters.

     ;;; First create the category
     (define-parameter-category kepler)
     
     ;;; Then define some parameters
     (define-parameter kepler foo 122 fixnum "A fixnum parameter of kepler.")
     (define-parameter kepler bar "hi" string "A string parameter of kepler.")
     
     ;;; Get their values
     (parameter-value kepler bar)
     "hi"
     (parameter-value kepler foo)
     122
     
     ;;; Dynamic binding
     (defun show-foo-bar ()
       (format t "~&foo: ~a, bar: ~s"
     	  (parameter-value kepler foo)
     	  (parameter-value kepler bar)))
     
     (show-foo-bar)
     foo: 122, bar: "hi"
     NIL
     
     ;;; Locally change values
     (with-parameters (kepler foo 143 bar "bye")
       (show-foo-bar))
     foo: 143, bar: "bye"
     NIL
     
     (show-foo-bar)
     foo: 122, bar: "hi"
     NIL
     
     ;;; Make a mistake
     (with-parameters (kepler foo 143 bar -44)
       (show-foo-bar))
     Error: Value -44 is of type FIXNUM, not of the required type STRING.
     
     ;;; Globally change values
     (set-parameter-value kepler bar "a new value")
     foo: 122, bar: "a new value"
     
     ;;; Set multple values
     (set-parameters kepler bar "xyz" foo 1)
     
     ;;; Get information about the categories and parameters
     (parameter-help)
     Parameter categories: KEPLER.
     
     (parameter-help :kepler)
     Parameters in KEPLER: BAR and FOO.
     
     (parameter-help :kepler :bar)
     BAR: A string parameter of kepler.
     Type is: STRING, default value is "hi".
     
     (parameter-value* kepler (mkstr "FO" "O"))
     122
— Macro: antik:define-parameter-category name

Define a new category for parameters.

— Macro: antik:define-parameter category name default type description

Define the parameter name in category.

— Function: antik:parameter-help &optional category name stream

Print all information known about the parameter. If category is nil (default), names of all categories are printed. If name is nil, all defined parameters in that category are printed.

— Macro: antik:parameters-set category

A list of parameters that are set.

— Macro: antik:parameter-value category name &optional default

Get or set the parameter value.

— Macro: antik:parameter-value* category name &optional default

Get the parameter value dynamically.

— Macro: antik:reset-parameters category &rest names

Reset the parameter(s) to the default value; if none are specified, all in the category are reset.

— Macro: antik:set-parameter-value category name value

Set the parameter value, checking that the name is legitimate and the value is of the correct type.

— Macro: antik:with-parameters (category &rest name-values) &body body

Provide local scope for parameter values, and possibly bind new values.