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

Parameters as exported dynamic variables

Parameters implemented as dynamic variables with exported symbols have
replaced the old representation.
parent 87ac601d
No preview for this file type
......@@ -186,14 +186,18 @@ This section will describe the definitions for organizing computations. At pres
@node Parameters, , Introduction to organization, Organization of Computation
@section Parameters
@cindex Parameters
Parameters are named values that are defined and used in computations or in presentation; the concept is distinct from Common Lisp's @url{http://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm#defparameter,defparameter} macro. They are organized into named categories; Antik itself defines one category, @code{NF}, which is used for numerical formatting. Each parameter is defined with a default value and description. The value can be changed with @code{(setf parameter-value)} and used with @code{parameter-value}, or changed locally (analogous to @code{let} for CL variables) with @code{with-parameters}.
Parameters are named values that are defined and used in computations or in presentation. The @url{http://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm#defparameter,defparameter} macro defines parameters (dynamic variables) but Antik has definitions that permit grouping them and including properties such as the type, which will be checked when values are assigned, and defining synonyms. The grouping is in named categories; Antik itself defines one category, @code{NF}, which is used for numerical formatting. Each category used will become a package, and the symbols exported from that package. The value can be changed with @code{(setf parameter-value)} and used with @code{parameter-value}, or changed locally (analogous to @code{let} for CL variables) with @code{with-parameters}. It is also permissible to assign as a normal variable (e.g., with let and setf), but no type checking is performed.
@example
;;; 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.")
(define-parameter kepler foo
:value 122
:type fixnum
:documentation "A fixnum parameter of kepler.")
(define-parameter kepler bar
:value "hi"
:type string
:documentation "A string parameter of kepler.")
;;; Get their values
(parameter-value kepler bar)
......@@ -212,7 +216,7 @@ foo: 122, bar: "hi"
NIL
;;; Locally change values
(with-parameters (kepler foo 143 bar "bye")
(with-parameters (kepler (foo 143) (bar "bye"))
(show-foo-bar))
foo: 143, bar: "bye"
NIL
......@@ -222,30 +226,31 @@ foo: 122, bar: "hi"
NIL
;;; Make a mistake
(with-parameters (kepler foo 143 bar -44)
(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")
(setf (parameter-value kepler bar) "a new value")
(show-foo-bar)
foo: 122, bar: "a new value"
;;; Set multple values
;;; Set multiple values
(set-parameters kepler bar "xyz" foo 1)
(show-foo-bar)
foo: 1, bar: "xyz"
;;; Get information about the categories and parameters
(parameter-help)
Parameter categories: KEPLER.
Parameter categories: KEPLER and NF.
(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
Type is STRING,
Current value is "xyz".
@end example
@include include/macro-antik-define-parameter-category.texinfo
......
......@@ -55,6 +55,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Mathematics.html#Mathematics">Mathemati
<blockquote><p><a name="index-antik_003ahandling_002dcomplex_002dnumber-80"></a>A handler to make the complex number.
</p></blockquote></div>
<!-- This needs node information -->
<h3 class="section">2.3 Iterate generalized numbers</h3>
<p>Extensions to the <a href="http://common-lisp.net/project/iterate/"><samp><span class="command">iterate</span></samp></a>
......
......@@ -34,13 +34,17 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Organization-of-Computation.html#Organi
<h3 class="section">3.2 Parameters</h3>
<p><a name="index-Parameters-83"></a>Parameters are named values that are defined and used in computations or in presentation; the concept is distinct from Common Lisp's <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm#defparameter">defparameter</a> macro. They are organized into named categories; Antik itself defines one category, <code>NF</code>, which is used for numerical formatting. Each parameter is defined with a default value and description. The value can be changed with <code>(setf parameter-value)</code> and used with <code>parameter-value</code>, or changed locally (analogous to <code>let</code> for CL variables) with <code>with-parameters</code>.
<pre class="example"> ;;; First create the category
(define-parameter-category kepler)
<p><a name="index-Parameters-83"></a>Parameters are named values that are defined and used in computations or in presentation. The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm#defparameter">defparameter</a> macro defines parameters (dynamic variables) but Antik has definitions that permit grouping them and including properties such as the type, which will be checked when values are assigned, and defining synonyms. The grouping is in named categories; Antik itself defines one category, <code>NF</code>, which is used for numerical formatting. Each category used will become a package, and the symbols exported from that package. The value can be changed with <code>(setf parameter-value)</code> and used with <code>parameter-value</code>, or changed locally (analogous to <code>let</code> for CL variables) with <code>with-parameters</code>. It is also permissible to assign as a normal variable (e.g., with let and setf), but no type checking is performed.
<pre class="example">
;;; 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.")
(define-parameter kepler foo
:value 122
:type fixnum
:documentation "A fixnum parameter of kepler.")
(define-parameter kepler bar
:value "hi"
:type string
:documentation "A string parameter of kepler.")
;;; Get their values
(parameter-value kepler bar)
......@@ -59,7 +63,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Organization-of-Computation.html#Organi
NIL
;;; Locally change values
(with-parameters (kepler foo 143 bar "bye")
(with-parameters (kepler (foo 143) (bar "bye"))
(show-foo-bar))
foo: 143, bar: "bye"
NIL
......@@ -69,30 +73,31 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Organization-of-Computation.html#Organi
NIL
;;; Make a mistake
(with-parameters (kepler foo 143 bar -44)
(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")
(setf (parameter-value kepler bar) "a new value")
(show-foo-bar)
foo: 122, bar: "a new value"
;;; Set multple values
;;; Set multiple values
(set-parameters kepler bar "xyz" foo 1)
(show-foo-bar)
foo: 1, bar: "xyz"
;;; Get information about the categories and parameters
(parameter-help)
Parameter categories: KEPLER.
Parameter categories: KEPLER and NF.
(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
Type is STRING,
Current value is "xyz".
</pre>
<div class="defun">
&mdash; Macro: <b>antik:define-parameter-category</b><var> name<a name="index-antik_003adefine_002dparameter_002dcategory-84"></a></var><br>
......
......@@ -35,12 +35,12 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Physical-dimension.html#Physical-dimens
<h4 class="subsection">5.3.4 Systems of units</h4>
<p>A <dfn>system of units</dfn> is a set of units, one for each of the physical dimensions that Antik can handle. A system of units is needed by Antik for printing output and in special cases for converting physical quantities that have a physical dimension defined (e.g. length), but no units. The system of units defined by
<code>*system-of-units*</code> is used to determine the units in which the output is printed. There are pre-defined several systems of units, <code>*siu*</code>, <code>*englishu*</code>, <code>*cgsu*</code>:
<code>(nf-option :system-of-units)</code> is used to determine the units in which the output is printed. There are pre-defined several systems of units, <code>*siu*</code>, <code>*englishu*</code>, <code>*cgsu*</code>:
<pre class="example"> ANTIK-USER&gt; (defparameter *length1* #_10_m)
*LENGTH1*
ANTIK-USER&gt; *length1*
#_10.000000000000000_m
ANTIK-USER&gt; (setf *system-of-units* *englishu*)
ANTIK-USER&gt; (set-default-system-of-units *englishu*)
(((1 0 0 0 0 0 0 0 0) . FOOT) ((0 0 0 0 0 0 0 0 1) . RADIAN)
((0 0 1 0 0 0 0 0 0) . SLUG) ((0 1 0 0 0 0 0 0 0) . SECOND)
((1 -2 1 0 0 0 0 0 0) . POUND-FORCE) ((2 -3 1 0 0 0 0 0 0) . HORSEPOWER)
......@@ -50,10 +50,10 @@ Up:&nbsp;<a rel="up" accesskey="u" href="Physical-dimension.html#Physical-dimens
#_32.808398950131235_ft
</pre>
<p>So by setting the system of units, you can convert values as needed,
<pre class="example"> ANTIK-USER&gt; (setf *system-of-units* *siu*)
<pre class="example"> ANTIK-USER&gt; (set-default-system-of-units *siu*)
ANTIK-USER&gt; #_12_feet
#_3.657600000000000d0_m
ANTIK-USER&gt; (setf *system-of-units* *englishu*)
ANTIK-USER&gt; (set-default-system-of-units *englishu*)
ANTIK-USER&gt; #_3_m
#_9.842519685039370d0_ft
</pre>
......
@deffn {Function} {antik:knots} breakpoints workspace
@findex antik:knots
Compute the knots associated with the given breakpoints and store
them in the workspace.
@end deffn
@deffn {Function} {antik:linear-least-squares-1d} observations @&optional times
@findex antik:linear-least-squares-1d
Find the one dimensional least squares (linear regression) solution of slope and intercept.
Values returned: slope, intercept, and their standard errors.
@end deffn
@deffn {Function} {antik:low-discrepancy-sample} count make-function @&rest parameters
@findex antik:low-discrepancy-sample
Call the make function to generate a set of objects with the
parameters sampled according to a low-discrepancy sequence. Each
parameter will be either a fixed value, specified as a list of key
and value, or a range from which the sample is taken, specified as
a list of key, lower value, and upper value. For example,
@@example
(low-discrepancy-sample
@code{5}
'make-orbit
'(:semimajor-axis #_7000_km #_9000_km)
'(:eccentricity @code{0}.0)
'(:inclination #_95_deg #_105_deg))
@@end example
@end deffn
@deffn {Function} {antik:make-parameter-with-attribute} category name attribute @&optional type description default
@findex antik:make-parameter-with-attribute
Make a parameter that has an attribute.
@end deffn
@deffn {Function} {antik:make-parameters-from-table} table @&key headerp category type prefix
@findex antik:make-parameters-from-table
From the list of lists, define the parameters. The optional header should have column names. These column names include 'category 'name 'default 'value 'type 'description ('value and 'default mean the same thing). Any column names not specified will receive a default value. Any values in the cells that are empty will receive a default value. Any columns given with a header not on the list will be ignored. Category must already exist.
@end deffn
@deffn {Function} {antik:orbit} sir ephemeral ephemeral-value @&optional generate-state epoch
@findex antik:orbit
Make a new sir from an old with all invariant attributes of the sir
the same: sir data and elements. Define exactly one ephemeral quantity,
possibly the same as in the original sir. Note: specifying generate-state
@code{t} will insure that the orbital state (non-ephemeral quantities) are
carried over to the new sir. However, this will not be possible if the
full state is not known, e.g., only the planar elements a, e are known.
In this case, the user should insure those elements exist prior
to calling this function.
@end deffn
@deffn {Function} {antik:org-table-line} list @&optional stream
@findex antik:org-table-line
Format the list for a line of an org-mode table.
@end deffn
@deffn {Function} {antik:org-table} list-of-lists @&optional stream
@findex antik:org-table
Format the table.
@end deffn
@deffn {Generic Function} {antik:psi} x
@findex antik:psi
The psi, or digamma, function.
@end deffn
@deffn {Method} {antik:psi} (x float)
Domain: x /= @code{0}.@code{0}, @code{-1}.@code{0}, @code{-2}.@code{0}, ...
@end deffn
@deffn {Method} {antik:psi} (n integer)
Domain: n integer, n > @code{0}.
@end deffn
@deffn {Function} {antik:si} x
@findex antik:si
The Sine integral Si(x) = int_0^x dt sin(t)/t.
@end deffn
@deffn {Function} {antik:solve-linear} matrix vector
@findex antik:solve-linear
Solve the linear algebra equation.
@end deffn
;; Floating point numbers.
;; Liam Healy Wed May 8 2002 - 10:47
;; Time-stamp: <2013-03-24 18:11:47EDT float.lisp>
;; Time-stamp: <2013-05-26 18:41:07EDT float.lisp>
;; Copyright 2011, 2012 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -214,12 +214,14 @@
;;;;****************************************************************************
(define-parameter nf :fracpart-digits
3 (or null fixnum)
:value 3 :type (or null fixnum)
:documentation
"The number of digits to the right of the decimal floating point numbers
when :significant-figures is nil.")
(define-parameter nf :full-precision
nil t
:value nil :type t
:documentation
"If non-nil, ignore :fracpart-digits, :intpart-digits, :significant-figures,
and format floating point numbers to full precision.")
......
;; Format numerical output
;; Liam Healy Wed Dec 11 2002 - 16:37
;; Time-stamp: <2013-03-24 18:52:25EDT format-output.lisp>
;; Time-stamp: <2013-05-26 18:46:55EDT format-output.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -27,18 +27,11 @@
;;;; Parameters
;;;;****************************************************************************
(define-parameter-category nf)
(define-parameter nf :style 20
(or null fixnum (member :tex :short :readable))
"Style of format, plain (nil), LaTeX (:tex), or plain but
(possibly) shortened (:short or a number). If :short a short
form will be used if available, if a fixnum is supplied, the
short form will be used if available and the space available is
less than the space taken by the long form. If :readable, a form
that is readable to CL is produced, if :reproducible a readble
form is produced, and on reading object will be recreated
exactly.")
(define-parameter nf :style
:value 20
:type (or null fixnum (member :tex :short :readable))
:documentation
"Style of format, plain (nil), LaTeX (:tex), or plain but (possibly) shortened (:short or a number). If :short a short form will be used if available, if a fixnum is supplied, the short form will be used if available and the space available is less than the space taken by the long form. If :readable, a form that is readable to CL is produced, if :reproducible a readble form is produced, and on reading object will be recreated exactly.")
;;;;****************************************************************************
;;;; Macros for parameter access
......@@ -58,7 +51,7 @@
(defmacro with-nf-options ((&rest name-values) &body body)
"Set the options for all nf calls within body to inherit."
`(with-parameters (nf ,@name-values)
`(with-parameters (nf ,@(loop for (n v) on name-values by #'cddr collect (list n v)))
,@body))
(define-symbol-macro texstyle
......@@ -92,21 +85,24 @@
;;;; Numbers nf
;;;;****************************************************************************
(define-parameter nf :significant-figures 4
(or null fixnum)
(define-parameter nf :significant-figures :value 4
:type (or null fixnum)
:documentation
"The number of significant figures formatted for numbers.
If nil, formatting of numbers is done using :intpart-digits
and, if a float, :fracpart-digits.")
(define-parameter nf :intpart-digits
nil (or null fixnum)
:value nil :type (or null fixnum)
:documentation
"The minimum space allowed for the whole-number part of numbers
when :significant-figures is nil. If this is larger than
the actual number of digits, pad to the left with spaces.
If this value is nil, allow enough space to accomodate the number.")
(define-parameter nf :print-sign
nil t
:value nil :type t
:documentation
"Whether leading `+' is printed.")
(defmethod nf
......@@ -131,28 +127,34 @@
;;;;****************************************************************************
(define-parameter nf :vector-format
:horizontal (member :horizontal :vertical :coordinate-unit-vectors)
:value :horizontal :type (member :horizontal :vertical :coordinate-unit-vectors)
:documentation
"Rank-1 grids (vectors) are formatted as rows, columns or as linear
combination of coordinate unit vectors.")
(define-parameter nf :components
'("I" "J" "K") list
:value '("I" "J" "K") :type list
:documentation
"Names of vector components to use :vector-format is :coordinate-unit-vectors.")
(define-parameter nf :tex-element-separator
(format nil " \\\\~%") string
:value (format nil " \\\\~%") :type string
:documentation
"What to put between vertically separated elements for LaTeX.")
(define-parameter nf :tex-decimal-align
t boolean
:value t :type boolean
:documentation
"Align columns of numbers on decimal point in LaTeX.")
(define-parameter nf :vertical-element-separator
#\Newline character
:value #\Newline :type character
:documentation
"What to put between vertically separated elements for plain style.")
(define-parameter nf :horizontal-element-separator
#\space character
:value #\space :type character
:documentation
"What to put between horizontally separated elements for plain style.")
(defun vector-component-names (i)
......
;; Exchange data through org-mode, particularly org-babel.
;; Liam Healy 2013-01-21 12:35:10EST org-mode.lisp
;; Time-stamp: <2013-03-21 22:17:30EDT org-mode.lisp>
;; Time-stamp: <2013-05-26 18:45:04EDT org-mode.lisp>
;; Copyright 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -52,7 +52,6 @@
+ Example of Lisp code
#+name: anexample(parameters=test-table)
#+BEGIN_SRC lisp
(define-parameter-category :testcat)
(make-parameters-from-table parameters)
(* (parameter-value :testcat :a) (parameter-value :testcat :b) (parameter-value :testcat :c))
#+END_SRC
......
This diff is collapsed.
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