id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
33,778
todo.lsp
rwoldford_Quail/source/probability/distributions/todo.lsp
::: Begin optimization of files after poisson #| (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= >= <= abs log)
226
Common Lisp
.l
5
37
69
0.548387
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
37499571bc2fda50021f6d004858356c3aea95f0f16b263cef238b4a242d4254
33,778
[ -1 ]
33,779
prob-measure.lsp
rwoldford_Quail/source/probability/distributions/prob-measure.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prob-measure.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prob-measure lower-bound-of upper-bound-of pdf-at cdf-at random-value quantile-at probability expectation))) (defclass prob-measure (quail-object) ((lower-bound :accessor lower-bound-of :initarg :lower-bound :initform -infinity) (upper-bound :accessor upper-bound-of :initarg :upper-bound :initform +infinity)) (:documentation "A generic probability distribution.") ) (defmethod initialize-instance :after ((self prob-measure) &key lower-bound upper-bound) (setf lower-bound (or lower-bound (lower-bound-of self))) (setf upper-bound (or upper-bound (upper-bound-of self))) (unless (and lower-bound upper-bound (< (eref lower-bound 0) (eref upper-bound 1))) (quail-error "Initialization error: Upper-bound = ~s <= lower-bound = ~s." upper-bound lower-bound)) self) ;;; ;;; Generic functions ;;; (defgeneric pdf-at (distribution value) (:documentation "Probability density function (or probability function) ~ of distribution evaluated at value")) (defgeneric cdf-at (distribution value) (:documentation "Cumulative distribution function of distribution evaluated ~ at value")) (defgeneric random-value (distribution &optional n) (:documentation "Produce n random values from distribution.~ Default is n=1.")) (defgeneric quantile-at (distribution value &key start) (:documentation "Quantile of distribution at value. Because this is often ~ determined by finding the root of an equation, the keyword ~ start gives a starting value for any iterative root finder ~ that is used.")) (defgeneric probability (distribution set) (:documentation "The probability of the set for this distribution.")) (defgeneric expectation (distribution &optional g) (:documentation "Expectation of a function g with respect to the given distribution. ~ If function is absent the mean of the distribution is returned."))
2,821
Common Lisp
.l
61
37.639344
108
0.568713
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
926833fecd8e73d04e52466cdd1720fb4365029bcf369c61ca2209fa8d95e4ad
33,779
[ -1 ]
33,780
bernoulli.lsp
rwoldford_Quail/source/probability/distributions/bernoulli.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; bernoulli.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Ward Quinlan and ;;; Frankie and Joyce and Wai Hong ;;; R.W. Oldford ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(bernoulli density-bernoulli quantile-bernoulli random-bernoulli dist-bernoulli))) (defclass bernoulli (binomial-dist) ((lower-bound :reader lower-bound-of :initform 0 :allocation :class) (upper-bound :reader upper-bound-of :initform 1 :allocation :class)) (:documentation "The bernoulli distribution") ) (defmethod (setf number-of-trials) (new-value (dist bernoulli)) (unless (= new-value 1) (quail-error "NUMBER-OF-TRIALS for class ~s must be 1." (class-name (class-of dist))))) (defmethod (setf upper-bound-of) (new-value (dist bernoulli)) (unless (= new-value 0) (quail-error "UPPER-BOUND-OF for class ~s must be 1." (class-name (class-of dist))))) ;;------------------------------------------------------------------ ;; Bernoulli Distribution (Bernoulli(p)) ;; ;; 1. Parameter: p = probability of success. ;; 2. Range: x - integer ;; 3. pdf: f(x) = p ,when x = 1 ;; = (1 - p) ,when x = 0 ;; 4. cdf: F(x) = 0 ,when x < 0 ;; = (1 - p) ,when x = 0 ;; = 1 ,when x >= 1 ;; 5. r.v.: rv = 1 ,when r.v. of Unif[0,1] < p ;; = 0 ,otherwise ;; 6. quantile: F(x) = q ;; x = 1 ,when q > p ;; x = 0, ,otherwise ;;------------------------------------------------------------------ (defmethod pdf-at ((distribution bernoulli) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions ( = - ) (let ((p (eref (p-of distribution) 0))) (cond ((= x 0) (- 1 p)) ((= x 1) p) (t 0)) ))) (defmethod cdf-at ((distribution bernoulli) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions ( = - < >) (let ((p (eref (p-of distribution) 0))) (cond ((< x 0) 0) ((< x 1) (- 1 p)) (t 1)) ))) (defmethod random-value ((distribution bernoulli) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (< =) (let ((p (p-of distribution))) (flet ((generate-one () (if (< (random-uniform) p) 1 0))) (if (= n 1) (generate-one) (array (loop for i from 1 to n collect (generate-one))) ) ) )) ) (defmethod quantile-at ((distribution bernoulli) q &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (>) (if (> q (p-of distribution)) 1 0) )) (defmethod quantile-at ((be bernoulli) (prob number) &key (start 0)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (bisection be prob)) (defvar *bernoulli* NIL "An instance of a bernoulli representing the bernoulli distribution. ~ This instance is used by the standard bernoulli functions random-bernoulli, ~ quantile-bernoulli, etc.") (defun density-bernoulli (x &key (p 0.5)) "Returns the value of a bernoulli probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *bernoulli*)) (let ((saved-p (prob-success *bernoulli*)) result) (setf (prob-success *bernoulli*) p) (setf result (pdf-at *bernoulli* x)) (setf (prob-success *bernoulli*) saved-p) result ) ) (defun quantile-bernoulli (prop &key (p 0.5)) "Returns the value of the prop'th bernoulli quantile. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *bernoulli*)) (let ((saved-p (prob-success *bernoulli*)) result) (setf (prob-success *bernoulli*) p) (setf result (quantile-at *bernoulli* prop)) (setf (prob-success *bernoulli*) saved-p) result)) (defun random-bernoulli (&key (n 1) (p 0.5)) "Returns n pseudo-random values from the bernoulli. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg p 0.5 The probability of success at each trial.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *bernoulli*)) (let ((saved-p (prob-success *bernoulli*)) result) (setf (prob-success *bernoulli*) p) (setf result (random-value *bernoulli* n)) (setf (prob-success *bernoulli*) saved-p) result) ) (defun dist-bernoulli (x &key (p 0.5)) "Calculates and returns the value of the specified bernoulli distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *bernoulli*)) (let ((saved-p (prob-success *bernoulli*)) result) (setf (prob-success *bernoulli*) p) (setf result (cdf-at *bernoulli* x)) (setf (prob-success *bernoulli*) saved-p) result))
6,381
Common Lisp
.l
172
29.94186
84
0.514832
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
721a989edb9cf02d9c08ec59c689af4dbc2627e0599dbdd15ddf66a09164f2d5
33,780
[ -1 ]
33,781
data-prob.lsp
rwoldford_Quail/source/probability/distributions/data-prob.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; data-prob.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (defmethod-multi lower-bound-of ((distribution ((eql -infinity) (eql +infinity) number sequence array dimensioned-ref-object))) (min distribution)) (defmethod-multi upper-bound-of ((distribution ((eql -infinity) (eql +infinity) number sequence array dimensioned-ref-object))) (max distribution)) (defmethod-multi cdf-at ((distribution ((eql -infinity) (eql +infinity) sequence array dimensioned-ref-object)) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (/ float <= - ) (let* ((sorted-x (sort (sel distribution) #'CL:<)) (i 0) (n (number-of-elements sorted-x))) ; (loop for j from 0 to (- n 1) ; while (<= (row-major-eref sorted-x j) value) do (do ((j 0 (incf j))) ((or (= j n) (> (row-major-eref sorted-x j) value))) (incf i)) (float (/ i n))))) (defmethod-multi cdf-at :around ((distribution ((eql -infinity) (eql +infinity) sequence array dimensioned-ref-object)) (value (sequence array dimensioned-ref-object))) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let* ((result (make-dimensioned-result (dimensions-of value) value)) (n-result (number-of-elements value)) (sorted-x (sort (sel distribution) #'CL:<)) (n (number-of-elements sorted-x))) (with-CL-functions (/ float <= - ) ; (loop for i from 0 to (- n-result 1) do (do ((i 0 (incf i))) ((= i n-result)) (let ((index 0) (this-val (column-major-eref value i))) ; (loop for j from 0 to (- n 1) ; while (<= (row-major-eref sorted-x j) this-val) do (do ((j 0 (incf j))) ((or (= j n) (> (row-major-eref sorted-x j) this-val))) (incf index)) (setf (column-major-eref result i) (float (/ index n))))) result))) (defmethod-multi pdf-at ((distribution ((eql -infinity) (eql +infinity) sequence array dimensioned-ref-object)) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let* ((sorted-x (sort (sel distribution) #'CL:<)) (i 0) (n (number-of-elements sorted-x))) (with-CL-functions (/ float <= - =) (loop for j from 0 to (- n 1) when (= (row-major-eref sorted-x j) value) do (incf i)) (float (/ i n))))) (defmethod-multi pdf-at :around ((distribution ((eql -infinity) (eql +infinity) sequence array dimensioned-ref-object)) (value (sequence array dimensioned-ref-object))) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let* ((result (make-dimensioned-result (dimensions-of value) value)) (n-result (number-of-elements value)) (sorted-x (sort (sel distribution) #'cl::<)) (n (number-of-elements sorted-x))) (with-CL-functions (- = / float) ; (loop for i from 0 to (- n-result 1) do (do ((i 0 (incf i))) ((= i n-result)) (let ((index 0) (this-val (column-major-eref value i))) (loop for j from 0 to (- n 1) when (= (row-major-eref sorted-x j) this-val) do (incf index)) (setf (column-major-eref result i) (float (/ index n))))) result))) (defmethod-multi quantile-at ((distribution ((eql -infinity) (eql +infinity) (eql NaN) number)) (value number) &key start) (declare (ignorable start value)) ;(declare (ignore start value)) ; 31JUL2023 distribution) (defmethod-multi quantile-at ((distribution (sequence array dimensioned-ref-object)) (value number) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let* ((sorted-x (sort (sel distribution) #'qk::ext_<)) (n (number-of-elements sorted-x)) (n*val (* (- n 1) value)) index frac) (multiple-value-setq (index frac) (truncate n*val)) (if (zerop frac) (row-major-eref sorted-x index) (qk::ext_+ (qk::ext_* (cl::- 1.0 value) (row-major-eref sorted-x index)) (qk::ext_* value (row-major-eref sorted-x (cl::+ index 1))))))) (defmethod-multi quantile-at ((distribution ((eql -infinity) (eql +infinity) (eql NaN) number)) (value (sequence array dimensioned-ref-object)) &key start) (declare (ignore start)) (let* ((result (make-dimensioned-result (dimensions-of value) value)) (n (number-of-elements result))) ; (loop for i from 0 to (- n 1) do (do ((i 0 (incf i))) ((= i n)) (setf (row-major-eref result i) (quantile-at distribution (row-major-eref value i)))) result)) (defmethod-multi quantile-at ((distribution (sequence array dimensioned-ref-object)) (value (sequence array dimensioned-ref-object)) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let* ((result (make-dimensioned-result (dimensions-of value) value)) (n-result (number-of-elements result)) (sorted-x (sort (sel distribution) #'qk::ext_<)) (n (number-of-elements sorted-x)) val n*val index frac) ; (loop for i from 0 to (- n-result 1) do (do ((i 0 (incf i))) ((= i n-result)) (setf val (row-major-eref value i)) (setf n*val (* (- n 1) val)) (multiple-value-setq (index frac) (truncate n*val)) (setf (row-major-eref result i) (if (zerop frac) (row-major-eref sorted-x index) (qk::ext_+ (qk::ext_* (cl::- 1.0 val) (row-major-eref sorted-x index)) (qk::ext_* val (row-major-eref sorted-x (cl::+ index 1))))))) result)) (defmethod-multi random-value ((distribution ((eql -infinity) (eql +infinity) (eql NaN) number)) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (array (list distribution) :dimensions (list n)) ) (defmethod-multi random-value ((distribution (sequence array dimensioned-ref-object)) &optional (n 1)) "Uses a generalized probability integral transform from a uniform (0,1).~ Does not depend on quantile-at." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let* ((proportions (random-uniform :n n)) (result (make-dimensioned-result (dimensions-of proportions) distribution)) (sorted-x (sort (sel distribution) #'qk::ext_<)) (big-n (number-of-elements sorted-x)) ) ; (loop for index from 0 to (- n 1) do (do ((index 0 (incf index))) ((= index n)) (let ((i 0) (n*val (* big-n (row-major-eref proportions index))) ) (loop for jump from 1 to big-n while (> n*val jump) do (incf i)) (setf (row-major-eref result index) (row-major-eref sorted-x i)))) result))
9,238
Common Lisp
.l
209
29.885167
88
0.463645
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6235b57b1623a70c78e01dd303fdf6999863cbc603efdd86dfd559df3e7ab0b3
33,781
[ -1 ]
33,782
gamma.lsp
rwoldford_Quail/source/probability/distributions/gamma.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; gamma.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993, 1995 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Colin and Dan ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(gamma-dist location-of shape-of scale-of density-gamma quantile-gamma random-gamma dist-gamma))) (defclass gamma-dist (continuous-dist) ((location :initarg :location :initform 0) (lower-bound :reader lower-bound-of :initarg :lower-bound :initform 0) (shape :accessor shape-of :initarg :shape :initform 2) (scale :accessor scale-of :initarg :scale :initform 1)) (:documentation "The Gamma distribution, at 'location', scaled by 'scale', and ~ with shape parameter 'shape'.") ) (defmethod location-of ((self gamma-dist)) (lower-bound-of self)) (defmethod (setf location-of) (new-value (dist gamma-dist)) (setf (slot-value dist 'location) new-value) (setf (slot-value dist 'lower-bound) new-value) new-value) (defmethod (setf lower-bound-of) (new-value (dist gamma-dist)) (setf (slot-value dist 'lower-bound) new-value) (setf (slot-value dist 'location) new-value) new-value) ; GAMMA DISTRIBUTION ; This set of methods defines the probability density function (pdf), cumulative ; density function (cdf), the quantile function, and a random value for the ; gamma distribution with parameters shape (a), location (u), and scale. ; The following closed forms and techniques are implemented: ; pdf at x: 1 (a - 1) - ((x - u) / scale) ; -------------------- * (x - u) * e ; a ; gamma (a) * (scale) ; ; cdf at x : INCOMPLETE GAMMA FUNCTION ; ; random value : REJECTION TECHNIQUES ; ; quantile at p : Applied Statistics AS91 ... percentiles of chi ;*************************** ;*************************** ;*************************** (defmethod initialize-instance :after ((self gamma-dist) &key (lower-bound NIL) (location NIL)) (cond ((and lower-bound location) (unless (= lower-bound location) (quail-error "Gamma-dist: lower bound ~s /= location ~s" lower-bound location))) (lower-bound (setf (location-of self) lower-bound)) (location (setf (lower-bound-of self) location)) ) self) (defmethod pdf-at :around ((distribution gamma-dist) (x number)) (if (cl::<= x (eref (location-of distribution) 0)) 0 (call-next-method))) (defmethod pdf-at ((distribution gamma-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= >= <= abs log) (let ((location (eref (location-of distribution) 0)) (scale (eref (scale-of distribution) 0)) (shape (eref (shape-of distribution) 0))) (exp (- (* (- shape 1) (log (- x location))) (/ (- x location) scale) (log-gamma shape) (* shape (log scale))))))) #| (* (/ 1 (* (exp (log-gamma shape)) (expt scale shape))) (expt (- x location) (- shape 1)) (exp (- 0 (/ (- x location) scale)))) ))) |# ;*************************** (defmethod quantile-at ((distribution gamma-dist) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ - * / log exp expt abs < > <= >= =) (let (chi-result (location (eref (location-of distribution) 0)) (scale (eref (scale-of distribution) 0)) (shape (eref (shape-of distribution) 0)) ) (setf chi-result (let* ((half 5.0D-1) (one 1.0D0) (two 0.2D1) (three 0.3D1) (six 0.6D1) (aa 0.6931471806) (e 0.5D-8) (v (* 2 shape)) (xx (* half v)) (c (- xx one)) (g (log-gamma xx)) (c1 0.01) (c2 0.222222) (c3 0.32) (c4 0.4) (c5 1.24) (c6 2.2) (c7 4.67) (c8 6.66) (c9 6.73) (c10 13.32) (c11 60.0) (c12 70.0) (c13 84.0) (c14 105.0) (c15 120.0) (c16 127.0) (c17 140.0) (c18 175.0) (c19 210.0) (c20 252.0) (c21 264.0) (c22 294.0) (c23 346.0) (c24 420.0) (c25 462.0) (c26 606.0) (c27 672.0) (c28 707.0) (c29 735.0) (c30 889.0) (c31 932.0) (c32 966.0) (c33 1141.0) (c34 1182.0) (c35 1278.0) (c36 1740.0) (c37 2520.0) (c38 5040.0) a z0 current-value return-z0? ) (flet ((update-approx (ch) ;; calculation of seven term taylor series ;; (format *terminal-io* "~&ch = ~s" ch) (let* ((p1 (* half ch)) (p2 (- p (incomplete-gamma xx p1 :max-iterations 1000))) (tt (* p2 (exp (- (+ (* xx aa) g p1) (* c (log ch)))))) (b (/ tt ch)) (a (- (* half tt) (* b c))) (s1 (/ (+ c19 (* a (+ c17 (* a (+ c14 (* a (+ c13 (* a (+ c12 (* a c11)))))))))) c24)) (s2 (/ (+ c24 (* a (+ c29 (* a (+ c32 (* a (+ c33 (* a c35)))))))) c37)) (s3 (/ (+ c19 (* a (+ c25 (* a (+ c28 (* a c31)))))) c37)) (s4 (/ (+ c20 (* a (+ c27 (* a c34))) (* c (+ c22 (* a (+ c30 (* a c36)))))) c38)) (s5 (/ (+ c13 (* a c21) (* c (+ c18 (* a c26)))) c37)) (s6 (/ (+ c15 (* c (+ c23 (* c c16)))) c38)) ) (setq ch (+ ch (* tt (- (+ one (* half tt s1)) (* b c (- s1 (* b (- s2 (* b (- s3 (* b (- s4 (* b (- s5 (* b s6))))))))))))))) ;; (format *terminal-io* "~&ch(out) = ~s" ch) ch) ) (close-enough-p (old new) (<= (abs (- (/ old new) one)) e)) (z0-close-enough-p (old new) (<= (abs (- (/ old new) one)) c1)) ) ;; get starting approximation (cond ;; starting approximation for small chi-squared ((< v (* (- c5) (log p))) (setq z0 (expt (* p xx (exp (+ g (* xx aa)))) (/ one xx))) (if (<= z0 e) (setf return-z0? T)) ) ;; starting approximation for v > 0.32 ((> v c3) (let* ((x (quantile-gaussian p)) (p1 (/ c2 v))) ;; starting approximation using wilson and hilferty estimate ;; (setq z0 (* v (expt (- (+ (* x (sqrt p1)) one) p1) 3))) ;; starting approximation for p tending to 1 ;; (if (> z0 (+ (* c6 v) six)) (setq z0 (* -2.0 (+ (- (log (- one p)) (* c (log (* half z0)))) g)))) )) (T ;; starting approximation for v <= 0.32 ;; may require iteration (flet ((update-z0 (ch) (let* ((p1 (+ one (* ch (+ c7 ch)))) (p2 (* ch (+ c9 (* ch (+ c8 ch))))) (tt (- (/ (+ c7 (* two ch)) p1) half (/ (+ c9 (* ch (+ c10 (* ch three)))) p2)))) (- ch (/ (- one (/ (* (exp (+ a g (* half ch) (* c aa))) p2) p1)) tt)))) ) (setq z0 c4) (setf a (log (- one p))) (setq current-value (update-z0 z0)) (if (z0-close-enough-p z0 current-value) (setf z0 current-value) (loop until (z0-close-enough-p z0 current-value) do (setf z0 current-value) (setf current-value (update-z0 z0)) finally (setf z0 current-value)))))) (cond (return-z0? z0) (T (setq current-value (update-approx z0)) ;; (format *terminal-io* "~&current-value = ~s" current-value) (if (close-enough-p z0 current-value) (setf z0 current-value) (loop until (close-enough-p z0 current-value) do ;; (format *terminal-io* "~&current-value = ~s" current-value) (setf z0 current-value) (setf current-value (update-approx z0)))) current-value)) ) ) ) (+ (* scale chi-result 0.5) location) ) ) ) ;*************************** (defmethod cdf-at ((distribution gamma-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline incomplete-gamma)) (let ((location (eref (location-of distribution) 0)) (scale (eref (scale-of distribution) 0)) (shape (eref (shape-of distribution) 0)) result) (with-CL-functions (/ -) (setf result (incomplete-gamma shape (/ (- x location) scale) :max-iterations 1000)) result))) ;*************************** (defmethod random-value ((distribution gamma-dist) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((location (eref (location-of distribution) 0)) (scale (eref (scale-of distribution) 0)) (shape (eref (shape-of distribution) 0)) v1 v2 y am gamdev e s x dum uprv b) ;; keep) (cond ((and (integerp shape) (< shape 6)) ; For integer values of shape less than 6, a standard gamma deviate is ; created by adding shape number of exponential deviates (setf gamdev 1) ; (loop for index from 1 to shape do (do ((index 1 (incf index))) ((> index shape)) (setf gamdev (* gamdev (random-uniform :n n)))) (setf gamdev (- (log gamdev))) (setf gamdev (+ (* scale gamdev) location))) ((< shape 1) ; For 0 < shape < 1, a rejection method is used with a combination of the ; exponential and a polynomial of degree shape as the overlying function. ; This algorithm is described in Question #3 of Assignment #3 (setf gamdev (loop for i from 1 to n collect (progn (loop (setf dum (* (random-uniform) (* (/ 1 (exp (log-gamma shape))) (+ (/ 1 shape) (exp (- 0 1)))))) (cond ((<= dum (/ 1 (* shape (exp (log-gamma shape))))) (setf uprv (expt (* shape (exp (log-gamma shape)) dum) (/ 1 shape))) ;;(setf keep 0) ) (T (setf uprv (- 0 (log (+ (/ 1 shape) ( - (exp (- 0 1)) (* dum (exp (log-gamma shape)) )))))) ;;(setf keep 1) )) (setf b (* (random-uniform) (cond ((< uprv 1) (/ (expt uprv (- shape 1)) (exp (log-gamma shape)))) (T (/ (exp (- 0 uprv)) (exp (log-gamma shape))))))) (cond ((<= b (pdf-at distribution uprv)) (setf gamdev uprv) (return)) )) (+ (* scale gamdev) location) ) ) ) (if (= n 1) (setf gamdev (first gamdev)) (setf gamdev (array gamdev))) ) (T ; For other values of shape > 1, a rejection method is used with the ; Cauchy distribution as the overlying function. This exact algorithm ; was created by Ahrens and is described in 'Numerical Recipes' on page 206 (setf gamdev (loop for i from 1 to n collect (progn (loop (loop (loop (setf v1 (- (* 2 (random-uniform)) 1)) (setf v2 (- (* 2 (random-uniform)) 1)) (if (<= (+ (* v1 v1) (* v2 v2)) 1) (return))) (setf y (/ v2 v1)) (setf am (- shape 1)) (setf s (sqrt (+ (* 2 am) 1))) (setf x (+ (* s y) am)) (if (>= x 0) (return))) (setf e (* (+ (* y y) 1) (exp (- (* am (log (/ x am))) (* s y))))) (if (<= (random-uniform) e) (return))) (+ (* scale x) location) ))) (if (= n 1) (setf gamdev (first gamdev)) (setf gamdev (array gamdev))) )) gamdev)) ;*************************** (defvar *gamma-dist* NIL "An instance of a gamma-dist representing the gamma distribution. ~ This instance is used by the standard gamma functions random-gamma, ~ quantile-gamma, etc.") (defun density-gamma (x &key (shape 2.0) (location 0.0) (scale 1.0)) "Returns the value of a location scale gamma density at x. ~ Location 0 and scale 1 define the standard gamma distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg shape 2.0 The shape parameter of the gamma distribution. The gamma is ~ skewed to the right. The smaller the shape parameter shape, ~ the greater is this skewness.) ~ (:arg location 0.0 The location of the gamma density. The gamma has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *gamma-dist*)) (let ((saved-l (location-of *gamma-dist*)) (saved-s (scale-of *gamma-dist*)) (saved-a (shape-of *gamma-dist*)) result) (setf (location-of *gamma-dist*) location) (setf (scale-of *gamma-dist*) scale) (setf (shape-of *gamma-dist*) shape) (setf result (pdf-at *gamma-dist* x)) (setf (location-of *gamma-dist*) saved-l) (setf (scale-of *gamma-dist*) saved-s) (setf (shape-of *gamma-dist*) saved-a) result ) ) (defun quantile-gamma (p &key (shape 2.0) (location 0.0) (scale 1.0)) "Returns the value of a location scale gamma quantile at p. ~ Location 0 and scale 1 define the standard gamma distribution. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg shape 2.0 The shape parameter of the gamma distribution. The gamma is ~ skewed to the right. The smaller the shape parameter shape, ~ the greater is this skewness.) ~ (:arg location 0.0 The location of the gamma density. The gamma has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))~ (:references Algorithm AS 91 ... Applied Statistics Algorithms - 1985; by D.J. Best and D.E.~ Roberts.)" (declare (special *gamma-dist*)) (let ((saved-l (location-of *gamma-dist*)) (saved-s (scale-of *gamma-dist*)) (saved-a (shape-of *gamma-dist*)) result) (setf (location-of *gamma-dist*) location) (setf (scale-of *gamma-dist*) scale) (setf (shape-of *gamma-dist*) shape) (setf result (quantile-at *gamma-dist* p)) (setf (location-of *gamma-dist*) saved-l) (setf (scale-of *gamma-dist*) saved-s) (setf (shape-of *gamma-dist*) saved-a) result) ) (defun random-gamma (&key (n 1) (shape 2.0) (location 0.0) (scale 1.0)) "Returns n pseudo-random values from the location scale gamma. ~ Location 0 and scale 1 define the standard gamma distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg shape 2.0 The shape parameter of the gamma distribution. The gamma is ~ skewed to the right. The smaller the shape parameter shape, ~ the greater is this skewness.) ~ (:arg location 0.0 The location of the gamma density. The gamma has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *gamma-dist*)) (let ((saved-l (location-of *gamma-dist*)) (saved-s (scale-of *gamma-dist*)) (saved-a (shape-of *gamma-dist*)) result) (setf (location-of *gamma-dist*) location) (setf (scale-of *gamma-dist*) scale) (setf (shape-of *gamma-dist*) shape) (setf result (random-value *gamma-dist* n)) (setf (location-of *gamma-dist*) saved-l) (setf (scale-of *gamma-dist*) saved-s) (setf (shape-of *gamma-dist*) saved-a) result) ) (defun dist-gamma (x &key (shape 2.0) (location 0.0) (scale 1.0)) "Calculates and returns the value of the specified gamma distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ Location 0 and scale 1 define the standard gamma distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg shape 2.0 The shape parameter of the gamma distribution. The gamma is ~ skewed to the right. The smaller the shape parameter shape, ~ the greater is this skewness.) ~ (:arg location 0.0 The location of the gamma density. The gamma has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) " (declare (special *gamma-dist*)) (let ((saved-l (location-of *gamma-dist*)) (saved-s (scale-of *gamma-dist*)) (saved-a (shape-of *gamma-dist*)) result) (setf (location-of *gamma-dist*) location) (setf (scale-of *gamma-dist*) scale) (setf (shape-of *gamma-dist*) shape) (setf result (cdf-at *gamma-dist* x)) (setf (location-of *gamma-dist*) saved-l) (setf (scale-of *gamma-dist*) saved-s) (setf (shape-of *gamma-dist*) saved-a) result) )
25,313
Common Lisp
.l
582
24.438144
136
0.375482
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8266582a33420dd2114f0265b2f274ab6d8384886f80966e0e69a0e19c6d1365
33,782
[ -1 ]
33,783
hypergeometric.lsp
rwoldford_Quail/source/probability/distributions/hypergeometric.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; hypergeometric.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Joe Leung ;;; R.W. Oldford 1995. ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(hypergeometric total-successes-of total-failures-of sample-size-of population-size-of density-hypergeometric quantile-hypergeometric random-hypergeometric dist-hypergeometric))) (defclass hypergeometric (discrete-dist) ((total-successes :reader total-successes-of :initarg :total-successes) (total-failures :accessor total-failures-of :initarg :total-failures) (sample-size :reader sample-size-of :initarg :sample-size) (lower-bound :accessor lower-bound-of :allocation :class :initform 0)) (:documentation "The Hypergeometric distribution for number of successes in ~ sample-size draws without replacement from a total of ~ total-successes + total-failures units.")) (defmethod initialize-instance :after ((self hypergeometric) &rest initargs &key sample-size) (declare (ignore initargs)) (if sample-size (setf (sample-size-of self) sample-size)) (setf (upper-bound-of self) (min (total-successes-of self) (sample-size-of self))) ) (defmethod (setf lower-bound-of) (new-value (dist hypergeometric)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (unless (and (integerp (eref new-value 0)) (= new-value 0)) (quail-error "Lower bound is zero and cannot be changed to ~s ." new-value)) ) (defmethod (setf upper-bound-of) (new-value (dist hypergeometric)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (unless (and (integerp (eref new-value 0)) (= new-value (min (total-successes-of dist) (sample-size-of dist)))) (quail-error "Upper bound cannot be changed. Change either the ~ sample-size-of or the total-successes-of ~s." dist)) ) (defmethod (setf sample-size-of) (new-value (dist hypergeometric)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (unless (and (integerp (eref new-value 0)) (> new-value 0) (<= new-value (+ (total-successes-of dist) (total-failures-of dist)))) (quail-error "Sample-size must be an integer in the range (0,~s], ~ not ~s ." (+ (total-successes-of dist) (total-failures-of dist)) new-value)) (setf (slot-value dist 'sample-size) new-value) (setf (slot-value dist 'upper-bound) (min (total-successes-of dist) (sample-size-of dist))) new-value) (defmethod (setf total-successes-of) (new-value (dist hypergeometric)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (unless (and (integerp (eref new-value 0)) (>= new-value (sample-size-of dist))) (quail-error "Total number of successes must be an integer and >= ~s , ~ not ~s ." (sample-size-of dist) new-value)) (setf (slot-value dist 'total-successes) new-value) (setf (slot-value dist 'upper-bound) (min (total-successes-of dist) (sample-size-of dist))) new-value) (defmethod population-size-of ((dist hypergeometric)) "Returns the total number of successes and failures of the hypergeometric ~ distribution." (+ (total-successes-of dist) (total-failures-of dist))) ;;;----------------------------------------------------------------------- ;;; Hypergeometric ( Hyper(n,total-successes,total-failures) ) ;;; ;;; 1. Parameters: n = sample size ;;; total-successes = population size of type 1 elements ;;; total-failures = population size of type 2 elements ;;; where total population size = N = total-successes + total-failures ;;; 2. Range: x = 0,1,...,min(n,total-successes) ;;; ;;; /total-successes\ / total-failures\ ;;; \ x / \ n-x / ;;; 3. pdf: f(x) = --------------------------------- ;;; /N\ ;;; \n/ ;;; ;;; 4. cdf: / 0 ,if x < 0 ;;; | ;;; F(x) =< SUM(from t = 0 to x){f(t)} ,if 0 <= x <= min(n,total-successes) ;;; | ;;; \ 1 ,if x > min(n,total-successes) ;;; 5. mean: ;;; 6. variance: ;;; ;;; @ written by Joe Leung (ID# 89115226) ;;; ;;;----------------------------------------------------------------------- ;;;------------------------------------------ ;;; PDF-AT ;;;------------------------------------------ (defmethod pdf-at ((dist hypergeometric) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - >= <= ) (let ((successes (eref (total-successes-of dist) 0)) (failures (eref (total-failures-of dist) 0)) (sample-size (eref (sample-size-of dist) 0))) (if (integerp x) (if (and (>= x 0) (<= x sample-size) (<= x successes)) (* (choose successes x) (/ (choose failures (- sample-size x)) (choose (+ successes failures) sample-size))) 0) 0) ))) ;------------------------------------------ ; CDF-AT ;------------------------------------------ (defmethod cdf-at ((dist hypergeometric) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (floor >= < ) (let ((intx (floor x))) (cond ((< intx 0) 0) ((>= intx (eref (sample-size-of dist) 0)) 1) (T (loop for i from 0 to intx sum (pdf-at dist i))))))) ;------------------------------------------ ; QUANTILE-AT ;------------------------------------------ (defmethod quantile-at ((dist hypergeometric) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (bisection dist p) ) ;------------------------------------------ ; RANDOM-VALUE ;------------------------------------------ (defmethod random-value ((dist hypergeometric) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (if (= n 1) (quantile-at dist (random-uniform )) (array (loop for i from 1 to n collect (quantile-at dist (random-uniform )) ) :dimensions (list n)))) (defvar *hypergeometric* NIL "An instance of a hypergeometric representing the hypergeometric ~ distribution. ~ A hypergeometric distribution is characterized by three ~ parameters: total-successes, total-failures, and sample-size. ~ A total of sample-size units are drawn without replacement from ~ a finite population of total-successes + total-failures. ~ The random quantity is the number of successes observed in the sample. ~ This instance is used by the standard functions random-hypergeometric, ~ quantile-hypergeometric, etc.") (defun density-hypergeometric (x &key (total-successes 1) (total-failures 1) (sample-size 1)) "Returns the value of a hypergeometric probability at x. ~ (:elaboration ~ A hypergeometric distribution is characterized by three ~ parameters: total-successes, total-failures, and sample-size. ~ A total of sample-size units are drawn without replacement from ~ a finite population of total-successes + total-failures.) ~ The random quantity is the number of successes observed in the sample. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg total-successes 1 The total number of successful ~ units available to draw from.) ~ (:arg total-failures 1 The total number of failed ~ units available to draw from.) ~ (:arg sample-size 1 The number of draws to take without replacement from ~ the total of successful and failed units available.))" (declare (special *hypergeometric*)) (let ((saved-s (total-successes-of *hypergeometric*)) (saved-f (total-failures-of *hypergeometric*)) (saved-n (sample-size-of *hypergeometric*)) result) (setf (total-successes-of *hypergeometric*) total-successes) (setf (total-failures-of *hypergeometric*) total-failures) (setf (sample-size-of *hypergeometric*) sample-size) (setf result (pdf-at *hypergeometric* x)) (setf (total-successes-of *hypergeometric*) saved-s) (setf (total-failures-of *hypergeometric*) saved-f) (setf (sample-size-of *hypergeometric*) saved-n) result ) ) (defun quantile-hypergeometric (prop &key (total-successes 1) (total-failures 1) (sample-size 1)) "Returns the value of the prop'th hypergeometric quantile. ~ (:elaboration ~ A hypergeometric distribution is characterized by three ~ parameters: total-successes, total-failures, and sample-size. ~ A total of sample-size units are drawn without replacement from ~ a finite population of total-successes + total-failures.) ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg total-successes 1 The total number of successful ~ units available to draw from.) ~ (:arg total-failures 1 The total number of failed ~ units available to draw from.) ~ (:arg sample-size 1 The number of draws to take without replacement from ~ the total of successful and failed units available.))" (declare (special *hypergeometric*)) (let ((saved-s (total-successes-of *hypergeometric*)) (saved-f (total-failures-of *hypergeometric*)) (saved-n (sample-size-of *hypergeometric*)) result) (setf (total-successes-of *hypergeometric*) total-successes) (setf (total-failures-of *hypergeometric*) total-failures) (setf (sample-size-of *hypergeometric*) sample-size) (setf result (quantile-at *hypergeometric* prop)) (setf (total-successes-of *hypergeometric*) saved-s) (setf (total-failures-of *hypergeometric*) saved-f) (setf (sample-size-of *hypergeometric*) saved-n) result ) ) (defun random-hypergeometric (&key (n 1) (total-successes 1) (total-failures 1) (sample-size 1)) "Returns n pseudo-random values from the hypergeometric. ~ (:elaboration ~ A hypergeometric distribution is characterized by three ~ parameters: total-successes, total-failures, and sample-size. ~ A total of sample-size units are drawn without replacement from ~ a finite population of total-successes + total-failures.) ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg total-successes 1 The total number of successful ~ units available to draw from.) ~ (:arg total-failures 1 The total number of failed ~ units available to draw from.) ~ (:arg sample-size 1 The number of draws to take without replacement from ~ the total of successful and failed units available.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *hypergeometric*)) (let ((saved-s (total-successes-of *hypergeometric*)) (saved-f (total-failures-of *hypergeometric*)) (saved-n (sample-size-of *hypergeometric*)) result) (setf (total-successes-of *hypergeometric*) total-successes) (setf (total-failures-of *hypergeometric*) total-failures) (setf (sample-size-of *hypergeometric*) sample-size) (setf result (random-value *hypergeometric* n)) (setf (total-successes-of *hypergeometric*) saved-s) (setf (total-failures-of *hypergeometric*) saved-f) (setf (sample-size-of *hypergeometric*) saved-n) result ) ) (defun dist-hypergeometric (x &key (total-successes 1) (total-failures 1) (sample-size 1)) "Calculates and returns the value of the specified hypergeometric distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:elaboration ~ A hypergeometric distribution is characterized by three ~ parameters: total-successes, total-failures, and sample-size. ~ A total of sample-size units are drawn without replacement from ~ a finite population of total-successes + total-failures.) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg total-successes 1 The total number of successful ~ units available to draw from.) ~ (:arg total-failures 1 The total number of failed ~ units available to draw from.) ~ (:arg sample-size 1 The number of draws to take without replacement from ~ the total of successful and failed units available.))" (declare (special *hypergeometric*)) (let ((saved-s (total-successes-of *hypergeometric*)) (saved-f (total-failures-of *hypergeometric*)) (saved-n (sample-size-of *hypergeometric*)) result) (setf (total-successes-of *hypergeometric*) total-successes) (setf (total-failures-of *hypergeometric*) total-failures) (setf (sample-size-of *hypergeometric*) sample-size) (setf result (cdf-at *hypergeometric* x)) (setf (total-successes-of *hypergeometric*) saved-s) (setf (total-failures-of *hypergeometric*) saved-f) (setf (sample-size-of *hypergeometric*) saved-n) result ) )
15,001
Common Lisp
.l
329
37.170213
132
0.56868
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
057f01a9c3537947b86de3c180de417839c0445bb619fbaa0a87855279afaf84
33,783
[ -1 ]
33,784
discrete-uniform.lsp
rwoldford_Quail/source/probability/distributions/discrete-uniform.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; discrete-uniform.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Joe Leung (ID# 89115226) ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(discrete-uniform density-discrete-uniform quantile-discrete-uniform random-discrete-uniform dist-discrete-uniform))) (defclass discrete-uniform (discrete-dist) ((lower-bound :reader lower-bound-of :initarg :lower-bound :initform 0) (upper-bound :accessor upper-bound-of :initarg :upper-bound :initform 10)) (:documentation "Finite-discrete-uniform. A finite set of values can be taken by ~ the random variable. Without loss of generality, we take these to ~ be the values from lower-bound-of this distribution increasing by ~ 1 until the upper-bound-of this distribution is attained. ~ The set of values include the end-points.") ) (defmethod (setf lower-bound-of) (new-value (dist discrete-uniform)) (unless (and (integerp new-value) (< new-value (upper-bound-of dist))) (quail-error "Lower bound must be an integer that is less than ~ the upper bound (= ~s), not ~s ." (upper-bound-of dist) new-value)) (setf (slot-value dist 'lower-bound) new-value)) (defmethod (setf upper-bound-of) (new-value (dist discrete-uniform)) (unless (and (integerp new-value) (> new-value (lower-bound-of dist))) (quail-error "Upper bound must be an integer that is greater than ~ the lower bound (= ~s), not ~s ." (lower-bound-of dist) new-value)) (setf (slot-value dist 'upper-bound) new-value)) (defun set-discrete-uniform-bounds (dist &key (from NIL) (to NIL)) (when (and from to) (let ((intl (truncate from)) (intu (truncate to))) (if (or (> intl intu) (/= intl from) (/= intu to)) (quail-error "Upper and lower bounds must be integers such that the ~ upper-bound (= ~s) is greater the lower bound (= ~s)." to from)) (setf (slot-value dist 'upper-bound) intu) (setf (slot-value dist 'lower-bound) intl)))) (defmethod initialize-instance :after ((dist discrete-uniform) &rest initargs &key (lower-bound NIL) (upper-bound NIL)) (declare (ignore initargs)) (cond ((and lower-bound upper-bound) (let ((intl (truncate lower-bound)) (intu (truncate upper-bound))) (if (or (> intl intu) (/= intl lower-bound) (/= intu upper-bound)) (quail-error "Upper and lower bounds must be integers such that the ~ upper-bound (= ~s) is greater the lower bound (= ~s)." upper-bound lower-bound)) (setf (slot-value dist 'upper-bound) intu) (setf (slot-value dist 'lower-bound) intl))) (upper-bound (let ((intu (truncate upper-bound))) (if (/= intu upper-bound) (quail-error "Upper and lower bounds must be integers; here ~ upper-bound = ~s ." upper-bound)) (setf (upper-bound-of dist) intu))) (lower-bound (let ((intl (truncate lower-bound))) (if (/= intl lower-bound) (quail-error "Upper and lower bounds must be integers; here ~ lower-bound = ~s ." lower-bound)) (setf (lower-bound-of dist) intl))) (T NIL))) ;;;----------------------------------------------------------------------- ;;; Finite Discrete Uniform Distribution ( UD(a,b) ) ;;; - This is a discrete version of the uniform distribution. It takes a ;;; number of values, each with the same probability. The key characteristics ;;; of distribution are summarized as following: ;;; ;;; 1. Parameters: a = lower bound ;;; b = upper bound ;;; where a,b must be integers and b > a. ;;; 2. Range: x = a,a+1,...,b-1,b ;;; 3. pdf: f(x) = 1/(b-a+1) ;;; 4. cdf: / 0 ,if x < a ;;; F(x) =< (x-a+1)/(b-a+1) ,if a <= x <= b ;;; \ 1 ,if x > b ;;; 5. mean: (b+a)/2 ;;; 6. variance: ((b-a+1)^2 -1 )/12 ;;; ;;; ;;;----------------------------------------------------------------------- ;------------------------------------------ ;;; PDF-AT ;------------------------------------------ (defmethod pdf-at ((dist discrete-uniform) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (integerp + * / - exp expt sqrt > < = /= ) (if (integerp x) (if (and (>= x (lower-bound-of dist)) (<= x (upper-bound-of dist))) (/ 1 (+ 1 (- (upper-bound-of dist) (lower-bound-of dist)))) 0) 0))) ;------------------------------------------ ; CDF-AT ;------------------------------------------ (defmethod cdf-at ((dist discrete-uniform) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (let ((intx (if (< x 0) (ceiling x) (floor x)))) (cond ((< intx (lower-bound-of dist)) 0) ((> intx (upper-bound-of dist)) 1) (T (/ (+ intx (- 1 (lower-bound-of dist))) (+ 1 (- (upper-bound-of dist) (lower-bound-of dist))))) )) )) ;------------------------------------------ ; QUANTILE-AT ;------------------------------------------ (defmethod quantile-at ((dist discrete-uniform) (p number) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * - ceiling) (+ (ceiling (* (+ 1 (- (upper-bound-of dist) (lower-bound-of dist))) p)) (- (lower-bound-of dist) 1)) )) ;------------------------------------------ ; RANDOM-VALUE ;------------------------------------------ (defmethod random-value ((dist discrete-uniform) &optional (n 1)) (quantile-at dist (random-uniform :n n)) ) (defvar *discrete-uniform* NIL "An instance of a discrete-uniform representing the uniform ~ distribution on a finite number of elements. ~ The discrete-uniform distribution is characterized here by two ~ parameters: the lower-bound-of it and the upper-bound-of it. ~ Inclusive of the bounds, the set of elements are those running from the ~ lower-bound and increasing by one until the upper-bound is attained. ~ This instance is used by the standard functions random-discrete-uniform, ~ quantile-discrete-uniform, etc.") (defun density-discrete-uniform (x &key (from 0) (to 9)) "Returns the value of a discrete-uniform probability at x. ~ (:elaboration ~ The discrete-uniform distribution is characterized here by two ~ parameters: the lower-bound-of it and the upper-bound-of it. ~ Inclusive of the bounds, the set of elements are those running from the ~ lower-bound and increasing by one until the upper-bound is attained.) ~ The random quantity is the number of successes observed in the sample. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg from 0 The lower bound of the discrete uniform.) ~ (:arg to 9 The upper bound of the discrete uniform; this must be larger ~ than the lower bound.) ~ )" (declare (special *discrete-uniform*)) (let ((saved-l (lower-bound-of *discrete-uniform*)) (saved-u (upper-bound-of *discrete-uniform*)) result) (set-discrete-uniform-bounds *discrete-uniform* :from from :to to) (setf result (pdf-at *discrete-uniform* x)) (set-discrete-uniform-bounds *discrete-uniform* :from saved-l :to saved-u) result ) ) (defun quantile-discrete-uniform (prop &key (from 0) (to 9)) "Returns the value of the prop'th discrete-uniform quantile. ~ (:elaboration ~ The discrete-uniform distribution is characterized here by two ~ parameters: the lower-bound-of it and the upper-bound-of it. ~ Inclusive of the bounds, the set of elements are those running from the ~ lower-bound and increasing by one until the upper-bound is attained.) ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg from 0 The lower bound of the discrete uniform.) ~ (:arg to 9 The upper bound of the discrete uniform; this must be larger ~ than the lower bound.) ~ )" (declare (special *discrete-uniform*)) (let ((saved-l (lower-bound-of *discrete-uniform*)) (saved-u (upper-bound-of *discrete-uniform*)) result) (set-discrete-uniform-bounds *discrete-uniform* :from from :to to) (setf result (quantile-at *discrete-uniform* prop)) (set-discrete-uniform-bounds *discrete-uniform* :from saved-l :to saved-u) result ) ) (defun random-discrete-uniform (&key (n 1) (from 0) (to 9)) "Returns n pseudo-random values from the discrete-uniform. ~ (:elaboration ~ The discrete-uniform distribution is characterized here by two ~ parameters: the lower-bound-of it and the upper-bound-of it. ~ Inclusive of the bounds, the set of elements are those running from the ~ lower-bound and increasing by one until the upper-bound is attained.) ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg from 0 The lower bound of the discrete uniform.) ~ (:arg to 9 The upper bound of the discrete uniform; this must be larger ~ than the lower bound.) ~ ) ~ (:returns A vector of n pseudo-random values.)" (declare (special *discrete-uniform*)) (let ((saved-l (lower-bound-of *discrete-uniform*)) (saved-u (upper-bound-of *discrete-uniform*)) result) (set-discrete-uniform-bounds *discrete-uniform* :from from :to to) (setf result (random-value *discrete-uniform* n)) (set-discrete-uniform-bounds *discrete-uniform* :from saved-l :to saved-u) result ) ) (defun dist-discrete-uniform (x &key (from 0) (to 9)) "Calculates and returns the value of the specified discrete-uniform distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:elaboration ~ The discrete-uniform distribution is characterized here by two ~ parameters: the lower-bound-of it and the upper-bound-of it. ~ Inclusive of the bounds, the set of elements are those running from the ~ lower-bound and increasing by one until the upper-bound is attained.) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg from 0 The lower bound of the discrete uniform.) ~ (:arg to 9 The upper bound of the discrete uniform; this must be larger ~ than the lower bound.) ~ )" (declare (special *discrete-uniform*)) (let ((saved-l (lower-bound-of *discrete-uniform*)) (saved-u (upper-bound-of *discrete-uniform*)) result) (set-discrete-uniform-bounds *discrete-uniform* :from from :to to) (setf result (cdf-at *discrete-uniform* x)) (set-discrete-uniform-bounds *discrete-uniform* :from saved-l :to saved-u) result ) )
13,003
Common Lisp
.l
291
34.896907
88
0.530606
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c51b8359334c7700855b04676e328f52a2726d3899a69a000a7783f9455d30d3
33,784
[ -1 ]
33,785
F-dist.lsp
rwoldford_Quail/source/probability/distributions/F-dist.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; F-dist.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when(:compile-toplevel :load-toplevel :execute) (export '(F-dist location-of df-num-of df-den-of density-F quantile-F random-F dist-F))) (defclass F-dist (continuous-dist) ((df-num :reader df-num-of :initarg :df-num :initform 1.0 :documentation "The numerator degrees of freedom.") (df-den :reader df-den-of :initarg :df-den :initform 1.0 :documentation "The denominator degrees of freedom.")) (:documentation "The F distribution parameterized by its numerator and ~ denominator degrees of freedom df-num and ~ df-den respectively.") ) ;;; F DISTRIBUTION ;;; This set of methods defines the probability density function (pdf), ;;; cumulative density function (cdf), the quantile function, and a random ;;; value for the F distribution with parameters df-num (a) ;;; and df-den (b). ;;; ;;; With the exception of the pdf, most methods appeal to the relationship ;;; between F and Beta random-variables. ;;; ;;; In particular if x is beta(m,n) then y = (n * x)/(m * (1 - x)) is ;;; distributed as an F(m,n) random variable. ;;; ;;; (m/2) ;;; pdf at y: gamma((m+n)/2) (m/n) (m/2 - 1) - ((m+n)/2) ;;; ----------------------- * y * (1 + my/n) ;;; gamma (m/2) gamma(n/2) ;;; ;;; (m/2) ;;; (m/n) (m/2 - 1) -((m+n)/2) ;;; = ----------------------- * y * (1 + my/n) ;;; Beta((m/2),(n/2)) ;;; ;;; cdf at y : From beta distribution. ;;; If y ~ F(m,n) , then ;;; P(y <= a) = P(nx <= m(1-x)a) ;;; = P(nx + mxa <= ma) ;;; = P(x <= ma/(n+ma)) ;;; where x ~ Beta(m/2,n/2) ;;; ;;; ;;; random value : y = (n * x)/(m * (1 - x)) where x ~ Beta(m/2,n/2) ;;; ;;; quantile at p : p = P(y <= a) = P(x <= ma/(n+ma)) ;;; So if q is the p'th quantile from a beta(m/2,n/2) ;;; Then a = nq/(m(1-q)) is the p'th for F(m,n) ;;;*************************** ;;;*************************** ;;;*************************** (defmethod initialize-instance :after ((self F-dist) &key) (setf (lower-bound-of self) 0.0) (setf (df-num-of self) (float (df-num-of self))) (setf (df-den-of self) (float (df-den-of self)))) (defmethod df-of ((self F-dist)) "Returns a list of the numerator and denominator ~ degrees of freedom for an F-distribution." (list (df-num-of self) (df-den-of self))) (defmethod (setf df-of) ((new-value number) (self F-dist)) "Sets the numerator and denominator ~ degrees of freedom for an F-distribution. ~ (:required (:arg new-value A list of the numerator and denominator ~ degrees of freedom.)) ~ (:see-also df-num-of df-den-of)" (quail-error "~&(SETF DF-OF): The degrees of freedom for an F-dist ~ must be two numbers in a list or other ~ ref'able object, not ~s ." new-value)) (defmethod (setf df-of) ((new-value T) (self F-dist)) "Sets the numerator and denominator ~ degrees of freedom for an F-distribution. ~ (:required (:arg new-value A list of the numerator and denominator ~ degrees of freedom.)) ~ (:see-also df-num-of df-den-of)" (with-CL-functions (float) (setf (df-num-of self) (float (eref new-value 0))) (setf (df-den-of self) (float (eref new-value 1))))) (defmethod (setf df-num-of) (new-value (self F-dist)) "Sets the numerator degrees of freedom for an F-distribution to be ~ the float of the new value." (with-CL-functions (float) (setf (slot-value self 'df-num) (float new-value)))) (defmethod (setf df-den-of) (new-value (self F-dist)) "Sets the denominator degrees of freedom for an F-distribution to be ~ the float of the new value." (with-CL-functions (float) (setf (slot-value self 'df-den) (float new-value)))) (defmethod pdf-at ((distribution F-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline log-gamma)) (with-CL-functions (+ * / - exp log =) (if (= x 0.0) 0.0 (let* ((m (df-num-of distribution)) (n (df-den-of distribution)) (m/2 (/ m 2.0)) (n/2 (/ n 2.0)) (m+n/2 (/ (+ m n) 2.0)) (constant (- (+ (log-gamma m+n/2) (* m/2 (- (log m) (log n)))) (log-gamma m/2) (log-gamma n/2)))) (exp (+ constant (* (- m/2 1.0) (log x)) (* (- m+n/2) (log (+ 1.0 (* x (/ m n))))))))))) ;;;*************************** (defmethod cdf-at ((distribution F-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (*) (let* ((m (df-num-of distribution)) (n (df-den-of distribution)) (mx (* m x))) (dist-beta (/ mx (+ mx n)) :a (/ m 2) :b (/ n 2))))) ;;;*************************** (defmethod random-value ((distribution F-dist) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let* ((m (df-num-of distribution)) (d (df-den-of distribution)) (x (random-beta :n n :a (/ m 2) :b (/ d 2)))) (* (/ d m) (/ x (- 1.0 x))))) ;*************************** (defmethod quantile-at ((distribution F-dist) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (* / -) (let* ((m (df-num-of distribution)) (n (df-den-of distribution)) (q (quantile-beta p :a (/ m 2) :b (/ n 2)))) (* (/ n m) (/ q (- 1.0 q)))))) (defvar *F-dist* NIL "An instance of a F-dist representing the F distribution. ~ This instance is used by the standard F functions random-F, ~ quantile-F, etc.") (defun density-F (x &key (df-num 1) (df-den 1)) "Returns the value of an F density at x. ~ Parameters df-num and df-den define the standard F distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg df-num 1 The numerator degrees of freedom of the F distribution.) ~ (:arg df-den 1 The denominator degrees of freedom of the F distribution.) ~ )" (declare (special *F-dist*)) (let ((saved-n (df-den-of *F-dist*)) (saved-m (df-num-of *F-dist*)) result) (setf (df-den-of *F-dist*) df-den) (setf (df-num-of *F-dist*) df-num) (setf result (pdf-at *F-dist* x)) (setf (df-den-of *F-dist*) saved-n) (setf (df-num-of *F-dist*) saved-m) result ) ) (defun quantile-F (p &key (df-num 1) (df-den 1)) "Returns the pth quantiles from an F distribution. ~ Parameters df-num and df-den define the standard F distribution. ~ (:required ~ (:arg p The percentile at which to determine the quantile.)) ~ (:key ~ (:arg df-num 1 The numerator degrees of freedom of the F distribution.) ~ (:arg df-den 1 The denominator degrees of freedom of the F distribution.) ~ )" (declare (special *F-dist*)) (let ((saved-n (df-den-of *F-dist*)) (saved-m (df-num-of *F-dist*)) result) (setf (df-den-of *F-dist*) df-den) (setf (df-num-of *F-dist*) df-num) (setf result (quantile-at *F-dist* p)) (setf (df-den-of *F-dist*) saved-n) (setf (df-num-of *F-dist*) saved-m) result )) (defun random-F (&key (n 1) (df-num 1) (df-den 1)) "Returns n pseudo-random values from an F distribution. ~ Parameters df-num and df-den define the standard F distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg df-num 1 The numerator degrees of freedom of the F distribution.) ~ (:arg df-den 1 The denominator degrees of freedom of the F distribution.) ~ ) ~ (:returns A vector of n pseudo-random values.)" (declare (special *F-dist*)) (let ((saved-n (df-den-of *F-dist*)) (saved-m (df-num-of *F-dist*)) result) (setf (df-den-of *F-dist*) df-den) (setf (df-num-of *F-dist*) df-num) (setf result (random-value *F-dist* n)) (setf (df-den-of *F-dist*) saved-n) (setf (df-num-of *F-dist*) saved-m) result ) ) (defun dist-F (x &key (df-num 1) (df-den 1)) "Calculates and returns the value of the specified F distribution ~ function at x. (i.e. prob(X <= x) .) ~ Parameters df-num and df-den define the standard F distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg df-num 1 The numerator degrees of freedom of the F distribution.) ~ (:arg df-den 1 The denominator degrees of freedom of the F distribution.) ~ )" (declare (special *F-dist*)) (let ((saved-n (df-den-of *F-dist*)) (saved-m (df-num-of *F-dist*)) result) (setf (df-den-of *F-dist*) df-den) (setf (df-num-of *F-dist*) df-num) (setf result (cdf-at *F-dist* x)) (setf (df-den-of *F-dist*) saved-n) (setf (df-num-of *F-dist*) saved-m) result ) )
10,256
Common Lisp
.l
247
34.939271
84
0.515524
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
83ca3469da7a70689dc7b2a0225254bb6bb8dd0ef4a1206a35696b9a884e2837
33,785
[ -1 ]
33,786
continuous-dist.lsp
rwoldford_Quail/source/probability/distributions/continuous-dist.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; continuous-dist.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993 ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(continuous-dist))) (defclass continuous-dist (prob-measure) () (:documentation "A generic continuous probability distribution.") ) (defmethod cdf-at ((cont continuous-dist) value) (cond ((and (= (lower-bound-of cont) -INFINITY) (< (upper-bound-of cont) +INFINITY)) (flet ((func (x) (pdf-at cont x))) (- 1 (extended-simpsons #'func (eref value 0) (eref (upper-bound-of cont) 0) :max-iterations 500)))) ((> (lower-bound-of cont) -INFINITY) (flet ((func (x) (pdf-at cont x))) (extended-simpsons #'func (eref (lower-bound-of cont) 0) (eref value 0) :max-iterations 500))) ;; worst case, don't know anything, return NIL ((and (= (lower-bound-of cont) -INFINITY) (= (upper-bound-of cont) +INFINITY)) (missing-method 'cdf-at cont (eref value 0)))) ) ;; return pdf-at value (defmethod pdf-at ((cont continuous-dist) value) (labels ((func (x) (cdf-at cont x))) (let ((fprime (deriv #'func))) (funcall fprime value)))) ;; return quantile-at value (defmethod quantile-at ((cont continuous-dist) (p number) &key (start 0.5)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline newton illinois)) (with-CL-functions (+ * / -) (if (and (> (lower-bound-of cont) -INFINITY) (< (upper-bound-of cont) +INFINITY)) (flet ((g-fun (x) (- (cdf-at cont x) p))) (illinois #'g-fun (eref (lower-bound-of cont) 0) (eref (upper-bound-of cont) 0))) (flet ((g-fun (x) (- (cdf-at cont x) p)) (g-prime (x) (pdf-at cont x))) (newton #'g-fun :start start :deriv #'g-prime)) ))) (defmethod expectation ((dist continuous-dist) &optional g) (let ((l (lower-bound-of dist)) (u (upper-bound-of dist))) (cond ((>= l u) 0) (T (if (= u +infinity) (setf u most-positive-double-float) ) (if (= l -infinity) (setf l most-negative-double-float) ) (if g (extended-simpsons (function (lambda (x) (* (funcall g x) (pdf-at dist x)))) l u) (extended-simpsons (function (lambda (x) (pdf-at dist x))) l u))) ) ))
3,024
Common Lisp
.l
78
30.564103
84
0.492579
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
80518ec007d11d1c817ff7bf98b78e2a692bbc335458888007cc79b5b80cb650
33,786
[ -1 ]
33,787
negative-binomial.lsp
rwoldford_Quail/source/probability/distributions/negative-binomial.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; negative-binomial.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; by frankie (ID:89103738), Ward ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(negative-binomial number-of-successes prob-success density-negative-binomial quantile-negative-binomial random-negative-binomial dist-negative-binomial))) (defclass negative-binomial (discrete-dist) ((p :accessor p-of :initarg :p :initform NIL) (lower-bound :accessor lower-bound-of :initarg :successes :initform 1) (upper-bound :reader upper-bound-of :initform +INFINITY :allocation :class)) (:documentation "The Negative Binomial distribution.") ) (defmethod initialize-instance :after ((self negative-binomial) &rest initargs &key (successes NIL)) (declare (ignore initargs)) (if (and successes (numberp successes) (> successes 0)) (setf (number-of-successes self) successes)) ) (defmethod number-of-successes ((dist negative-binomial)) (lower-bound-of dist)) (defmethod (setf number-of-successes) (new-value (dist negative-binomial)) (if (and (integerp new-value) (> new-value 0)) (setf (lower-bound-of dist) new-value) (quail-error "Total number of successes must be an integer greater than zero, ~ not ~s ." new-value))) (defmethod (setf upper-bound-of) (new-value (dist negative-binomial)) (unless (= new-value (upper-bound-of dist)) (quail-error "Upper-bound is ~s for ~s, ~ not ~s ." (upper-bound-of dist) (class-name (class-of dist)) new-value)) ) (defmethod prob-success ((dist negative-binomial)) (p-of dist)) (defmethod (setf prob-success) (new-value (dist negative-binomial)) (if (and (<= new-value 1.0) (>= new-value 0.0)) (setf (p-of dist) new-value) (quail-error "Probability of success must be a number between 0.0 ~ and 1.0 inclusive, ~ not ~s ." new-value))) ;;;------------------------------------------------------------------------ ; Negative-Binomial Distribution (Negative-Binomial (n,p)) ; ; 1) Parameter : p = the probability of success ; x = the number of success ; ; 2) pdf : f(n) = /n-1\*p^x*(1-p)^(n-x) , n >= x ; \x-1/ ; ; 3) cdf : / 0 ,if x > a ; F(a) = | ; \ SUM(from t = x to a){f(t)} ,if x <= a ; ;;------------------------------------------------------------------------ (defmethod pdf-at ((dist negative-binomial) (n number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt sqrt >=) (let ((x (eref (number-of-successes dist) 0)) (p (eref (p-of dist) 0))) (if (and (integerp n) (>= n x)) (* (choose (- n 1) (- x 1)) (expt p x) (expt (- 1 p) (- n x))) 0)))) (defmethod cdf-at ((dist negative-binomial) (n number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt sqrt >=) (let ((x (eref (number-of-successes dist) 0)) (p (eref (p-of dist) 0))) (if (>= (truncate n) x) (incomplete-beta x (truncate n) (- 1 p)) 0) ))) (defmethod quantile-at ((dist negative-binomial) (prob number) &key (start NIL)) (declare (ignore start)) (multiple-value-bind (l u) (find-limits dist prob) (bisection dist prob :lower l :upper u)) ) (defmethod random-value ((dist negative-binomial) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((x (eref (number-of-successes dist) 0)) (p (eref (p-of dist) 0)) (sum 0)) ; (loop for i from 1 to x do (do ((i 1 (incf i))) ((> i x)) (setf sum (+ sum (random-geometric :p p :n n)))) sum)) (defvar *negative-binomial* NIL "An instance of a negative-binomial representing the negative-binomial ~ distribution. ~ This instance is used by the standard functions random-negative-binomial, ~ quantile-negative-binomial, etc.") (defun density-negative-binomial (x &key (successes 1) (p 0.5)) "Returns the value of a negative-binomial probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg successes 1 The total number of successful ~ trials for the negative-binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *negative-binomial*)) (let ((saved-s (number-of-successes *negative-binomial*)) (saved-p (prob-success *negative-binomial*)) result) (setf (number-of-successes *negative-binomial*) successes) (setf (prob-success *negative-binomial*) p) (setf result (pdf-at *negative-binomial* x)) (setf (number-of-successes *negative-binomial*) saved-s) (setf (prob-success *negative-binomial*) saved-p) result ) ) (defun quantile-negative-binomial (prop &key (successes 1) (p 0.5)) "Returns the value of the prop'th negative-binomial quantile. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg successes 1 The total number of successful ~ trials for the negative-binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *negative-binomial*)) (let ((saved-s (number-of-successes *negative-binomial*)) (saved-p (prob-success *negative-binomial*)) result) (setf (number-of-successes *negative-binomial*) successes) (setf (prob-success *negative-binomial*) p) (setf result (quantile-at *negative-binomial* prop)) (setf (number-of-successes *negative-binomial*) saved-s) (setf (prob-success *negative-binomial*) saved-p) result)) (defun random-negative-binomial (&key (n 1) (successes 1) (p 0.5)) "Returns n pseudo-random values from the negative-binomial. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg successes 1 The total number of successful ~ trials for the negative-binomial.) ~ (:arg p 0.5 The probability of success at each trial.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *negative-binomial*)) (let ((saved-s (number-of-successes *negative-binomial*)) (saved-p (prob-success *negative-binomial*)) result) (setf (number-of-successes *negative-binomial*) successes) (setf (prob-success *negative-binomial*) p) (setf result (random-value *negative-binomial* n)) (setf (number-of-successes *negative-binomial*) saved-s) (setf (prob-success *negative-binomial*) saved-p) result) ) (defun dist-negative-binomial (x &key (successes 1) (p 0.5)) "Calculates and returns the value of the specified negative-binomial distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg successes 1 The total number of successful ~ trials for the negative-binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *negative-binomial*)) (let ((saved-s (number-of-successes *negative-binomial*)) (saved-p (prob-success *negative-binomial*)) result) (setf (number-of-successes *negative-binomial*) successes) (setf (prob-success *negative-binomial*) p) (setf result (cdf-at *negative-binomial* x)) (setf (number-of-successes *negative-binomial*) saved-s) (setf (prob-success *negative-binomial*) saved-p) result))
8,655
Common Lisp
.l
203
35.320197
116
0.571633
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3ca87da1d5ed49121ab4c49a12f6346700a3d016055c10e2a9b0fab2ebf0b09b
33,787
[ -1 ]
33,788
gaussian.lsp
rwoldford_Quail/source/probability/distributions/gaussian.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; gaussian.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(gaussian-dist location-of scale-of density-gaussian quantile-gaussian dist-gaussian random-gaussian))) (defclass gaussian-dist (student) ((df :initform +INFINITY :reader df-of :allocation :class) (prob-list :initform (list 0.15641707759018236 0.14730805612132933 0.13328984115671988 0.11587662110459311 0.09678828980765734 0.07767442199328518 0.05989098625429795 0.044368333871782226 0.03158006332035766 0.021596386605275224 0.014189837138492575 0.008957812117937159 0.0054331876934742476 0.003166180633191985 0.001772739364775203 0.0021023412956437393 0.005016008194985072 0.007360440011075997 0.008918817004809176 0.009611999122311088 0.009496744827013612 0.008735036934679752 0.007546401021936107 0.006157884387109194 0.004763984114857969 0.0035035321889076015 0.002454012531309788 0.0016395078185443635 0.001045934646646905 6.377250010757031E-4 0.0026997961257424485) :reader prob-list-of :allocation :class)) (:documentation "The Gaussian or Normal distribution.") ) ;;; Since the integral of the pdf for the normal cannot be found in closed form ;;; the incomplete-gamma function was used for cdf-at and the Illinois function was ;;; used for quantile-at. For random-value the rectangle-wedge-tail method was used ;;; which required using cdf-at and the Illinois function. (defmethod cdf-at ((N gaussian-dist) (X number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline incomplete-gamma)) (with-CL-functions (+ * / - exp expt sqrt > < =) (let ((z (/ (- x (location-of n)) (scale-of n)))) (if (< z 0) (- .5 (* .5 (incomplete-gamma .5 (* z z .5)))) (- 1 (- .5 (* .5 (incomplete-gamma .5 (* z z .5)))))) ))) (defmethod pdf-at ((N gaussian-dist) (X number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < =) (let ((sigma (eref (scale-of N) 0)) (location (eref (location-of N) 0))) (/ (exp (* -.5 (expt (/ (- x location) sigma) 2))) (* (sqrt (* 2 pi)) sigma))))) (defmethod quantile-at ((dist gaussian-dist) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) "Calculates the inverse of the gaussian cumulative distribution ~ function for p between 10^-20 and 1 - 10^-20. ~ (:elaboration Algorithm used is that developed by Odeh and Evans, 1974 ~ and is based on a rational fraction approximation. The code is based ~ on the algorithm GAUINV as found in Kennedy and Gentle, 1980.) ~ (:references Kennedy, W.J. and J.E. Gentle 1980 Statistical Computing ~ Marcel-Dekker, New York; Odeh, R.E., and J.O. Evans, 1974, Algorithm ~ AS 70: Percentage Points of the Normal Distribution, Applied Statistics 23, ~ pp. 96-97.)" (with-CL-functions (+ * / - log expt sqrt > < =) (let ((location (eref (location-of dist) 0)) (scale (eref (scale-of dist) 0)) (lim 10D-20) (p0 -0.322232431088) (p1 -1.0) (p2 -0.342242088547) (p3 -0.0204231210245) (p4 -0.453642210148D-4) (q0 0.0993484626060) (q1 0.588581570495) (q2 0.531103462366) (q3 0.103537752850) (q4 0.38560700634D-2) (error? NIL) xp y (flip-sign? T)) (when (> p .5) (setf flip-sign? NIL) (setf p (- 1 p))) (cond ((= p 0.5) (setf xp 0.0)) ((< p lim) (setf error? T)) (T (setf y (sqrt (log (/ 1.0 (* p p))))) (setf xp (+ y (/ (+ p0 (* y (+ p1 (* y (+ p2 (* y (+ p3 (* y p4)))))))) (+ q0 (* y (+ q1 (* y (+ q2 (* y (+ q3 (* y q4))))))))))))) (if error? (if flip-sign? (values +infinity :out-of-bounds) (values -infinity :out-of-bounds)) (if flip-sign? (+ location (* -1.0 xp scale)) (+ location (* xp scale)))) ))) (defmethod random-value ((dist gaussian-dist) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline random-uniform) ) (with-CL-functions (+ * / - log expt sqrt > < =) (array (loop for i from 1 to n collect (let ((upick (random-uniform))(f 0) (j 0) urect z utail vtail s xc h uwedge vwedge u1wedge u2wedge c chold d r) (loop for i from 1 while(< f upick) do (setf f (+ f (elt (prob-list-of dist) (- i 1)))) (setf j (+ j 1))) ;; generate the rectangles: (cond ((< j 16) (setf urect (random-uniform)) (setf z (+ (* .2 urect) (/ (- j 1) 5)))) ;; generate the tail: ((= j 31) (setf utail (random-uniform)) (setf vtail (random-uniform)) (loop for i from 1 while (>= vtail (* 3 (expt (- 9 (* 2 (log utail))) -.5))) do (setf vtail (random-uniform)) (setf utail (random-uniform))) (setf z (expt (- 9 (* 2 (log utail))) .5))) ;; generate the wedges: (T (setf s (/ (- (- j 15) 1) 5)) (setf r (/ (- j 15) 5)) (flet ((solve-for-x (x) (- (* x (exp (/ (- 0 (expt x 2)) 2))) (* 5 (- (exp (/ (- 0 (expt s 2)) 2)) (exp (/ (- 0 (expt r 2)) 2)))))) (f-j-of-x (x) (/ (- (* 2 (density-gaussian x)) (* 2 (density-gaussian r))) (elt (prob-list-of dist) (- (- j 15) 1))))) (setf xc (illinois #'solve-for-x s r)) (setf d (f-j-of-x s)) (setf c (+ (* -5 d (- s xc)) (f-j-of-x xc))) (cond ((> j 20) (setf chold c) (setf c d) (setf d chold) (setf h .2)) (T (setf h (- c d .2)))) (setf u1wedge (random-uniform)) (setf u2wedge (random-uniform)) (cond ((> u1wedge u2wedge) (setf uwedge u2wedge) (setf vwedge u1wedge)) (T (setf uwedge u1wedge) (setf vwedge u2wedge))) (loop for i from 1 while (> vwedge (+ uwedge (/ (f-j-of-x (+ s (* h uwedge))) c))) do (setf u1wedge (random-uniform)) (setf u2wedge (random-uniform)) (setf uwedge (min u1wedge u2wedge)) (setf vwedge (max u1wedge u2wedge))) (setf z (+ s (* h uwedge)))))) ;; assign a positive or negative sign to the random value: (if (< (random-uniform) .5) (+ (location-of dist) (* (scale-of dist) -1.0 z)) (+ (location-of dist) (* (scale-of dist) z))) )) :dimensions (list n) ))) (defvar *gaussian-dist* NIL "An instance of a gaussian-dist representing the gaussian or normal distribution. ~ This instance is used by the standard normal functions random-gaussian, ~ quantile-gaussian, etc.") (defun density-gaussian (x &key (location 0.0) (scale 1.0)) "Returns the value of a location scale gaussian density at x. ~ Location 0 and scale 1 define the standard gaussian distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg location 0.0 The location of the gaussian density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *gaussian-dist*)) (let ((saved-l (location-of *gaussian-dist*)) (saved-s (scale-of *gaussian-dist*)) result) (setf (location-of *gaussian-dist*) location) (setf (scale-of *gaussian-dist*) scale) (setf result (pdf-at *gaussian-dist* x)) (setf (location-of *gaussian-dist*) saved-l) (setf (scale-of *gaussian-dist*) saved-s) result ) ) (defun quantile-gaussian (p &key (location 0.0) (scale 1.0)) "Returns the value of a location scale gaussian quantile at p. ~ Location 0 and scale 1 define the standard gaussian distribution. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg location 0.0 The location of the gaussian density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *gaussian-dist*)) (let ((saved-l (location-of *gaussian-dist*)) (saved-s (scale-of *gaussian-dist*)) result) (setf (location-of *gaussian-dist*) location) (setf (scale-of *gaussian-dist*) scale) (setf result (quantile-at *gaussian-dist* p)) (setf (location-of *gaussian-dist*) saved-l) (setf (scale-of *gaussian-dist*) saved-s) result)) (defun random-gaussian (&key (n 1) (location 0.0) (scale 1.0)) "Returns n pseudo-random values from the location scale gaussian. ~ Location 0 and scale 1 define the standard gaussian distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg location 0.0 The location of the gaussian density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *gaussian-dist*)) (let ((saved-l (location-of *gaussian-dist*)) (saved-s (scale-of *gaussian-dist*)) result) (setf (location-of *gaussian-dist*) location) (setf (scale-of *gaussian-dist*) scale) (setf result (random-value *gaussian-dist* n)) (setf (location-of *gaussian-dist*) saved-l) (setf (scale-of *gaussian-dist*) saved-s) result) ) (defun dist-gaussian (x &key (location 0.0) (scale 1.0)) "Calculates and returns the value of the specified gaussian distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ Location 0 and scale 1 define the standard gaussian distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg location 0.0 The location of the gaussian density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) " (declare (special *gaussian-dist*)) (let ((saved-l (location-of *gaussian-dist*)) (saved-s (scale-of *gaussian-dist*)) result) (setf (location-of *gaussian-dist*) location) (setf (scale-of *gaussian-dist*) scale) (setf result (cdf-at *gaussian-dist* x)) (setf (location-of *gaussian-dist*) saved-l) (setf (scale-of *gaussian-dist*) saved-s) result))
12,406
Common Lisp
.l
265
34.924528
100
0.525892
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a74bd1d6331dc027b2a55fd33d58c4d9a27155f79b4438e549c4c7e9c494ff66
33,788
[ -1 ]
33,789
finite-mixture.lsp
rwoldford_Quail/source/probability/distributions/finite-mixture.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; finite-mixture.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Joe Leung 1992 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(finite-mixture mixing-probs-of distributions-of))) (defclass finite-mixture (prob-measure) ((mixing-probs :accessor mixing-probs-of :initarg :mixing-probs :initform NIL) (distributions :accessor distributions-of :initarg :distributions :initform NIL) (number :accessor num-of :initarg :num :initform NIL)) (:documentation "Finite discrete mixtures.") ) ;;; ************************************************************************* ; Finite Discrete Mixtures ; ; 1. Parameters: p1, p2,...,pn denote the mixing probability ; where p1 + p2 +...+ pn = 1. ; f1, f2,...,fn denote the corresponding pdf. ; ; 2. pdf: f(x) = p1*f1(x) + p2*f2(x) + ... + pn*fn(x) ; ; 3. cdf: F(x) = p1*F1(x) + p2*F2(x) + ... + pn*Fn(x) ; ; 4. Randge: Suppose X1,X2,...,Xn denote the sets of random variable ; space for the corresponding pdf's. Then, the space for ; the mixture is UNION of Xi, for i from 1 to n. ; ; @written by Joe Leung (ID# 89115226) ;**************************************************************************** ;------------------------------------------ ; PDF-AT ;------------------------------------------ (defmethod pdf-at ((dist finite-mixture) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (*) (loop for f in (distributions-of dist) as p in (mixing-probs-of dist) sum (* p (pdf-at f x)) ) )) ;------------------------------------------ ; CDF-AT ;------------------------------------------ (defmethod cdf-at ((dist finite-mixture) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (*) (loop for f in (distributions-of dist) as p in (mixing-probs-of dist) sum (* p (cdf-at f x)) ) )) ;------------------------------------------ ; QUANTILE-AT ; - For the quantile of the mixture, only ; the pure mixture is allowed. That is, ; the mixture with discrete variable ; only and with continuous variable only. ; - Firstly, determine what type of the ; mixture is. This can be done by the ; routines "all-discrete" and "all-con- ; tinuous". Then , use the corresponding ; quantile-at routine to find the quantile ; of the mixture. ;;;---------------------------------------- (defmethod quantile-at ((dist finite-mixture) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (cond ((all-continuous dist) (Cquantile-at dist p)) ((all-discrete dist) (Dquantile-at dist p)) (T (quail-error "This program cannot handle the mixtures which include discrete and continous random variates.")) ) ) (defmethod all-continuous ((dist finite-mixture)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((all-type-continuous T)) (loop for f in (distributions-of dist) do (setf all-type-continuous (and all-type-continuous (typep f 'continuous-dist))) ) all-type-continuous )) (defmethod all-discrete ((dist finite-mixture)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((all-type-discrete T)) (loop for f in (distributions-of dist) do (setf all-type-discrete (and all-type-discrete (typep f 'discrete-dist))) ) all-type-discrete )) (defmethod Dquantile-at ((dist finite-mixture) p) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ <= abs log) (let ((sum 0) (count 0)) (loop for mp in (mixing-probs-of dist) do (setf sum (+ sum mp)) (when (<= p sum) (return (quantile-at (nth count (distributions-of dist)) p))) (setf count (+ count 1)) ) ) )) (defmethod Cquantile-at ((dist finite-mixture) p) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (multiple-value-bind (l u) (find-limits dist p) (bisection dist p :lower l :upper u)) ) ;------------------------------------------ ; RANDOM-VALUE ; - to determine the random-value from ; the mixture, we first determine the ; corresponding pdf in which the random ; value should be from. This can be done ; by invention method. ;------------------------------------------ (defmethod random-value ((dist finite-mixture) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((u-s (random-uniform :n n))) (array ; (loop for i from 0 to (- n 1) do (do ((i 0 (incf i))) ((= i n)) (with-CL-functions ( - + <= ) (let ((u (eref u-s i)) (sum 0) (count 0)) (loop for j from 0 to (- (length (distributions-of dist)) 1) do (setf sum (+ sum (nth j (mixing-probs-of dist)))) (when (<= u sum) (return (random-value (nth count (distributions-of dist)) n)) ) (setf count (+ count 1)) )))) )))
6,520
Common Lisp
.l
172
29.546512
116
0.464715
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d6b5948d7d0867772c16049cceb4ec2aa186f290a0f6a14d4fd267071a2c438c
33,789
[ -1 ]
33,790
K-dist.lsp
rwoldford_Quail/source/probability/distributions/K-dist.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; K-dist.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(K-dist df-of density-K quantile-K random-K dist-K))) (defclass K-dist (continuous-dist) ((df :reader df-of :initarg :df)) (:documentation "The K-dist distribution, with degrees of freedom = df. ~ (:elaboration ~ A K random-variable is simply a one to one transform of ~ a chi-squared random variable. If x has a chi-squared distribution ~ on m degrees of freedom, then y = sqrt(x/m) has a K distribution ~ on m degrees of freedom. For gaussian data, the ratio of ~ the sample standard deviation to the true standard deviation ~ is distributed as a K random-variable.)") ) (defmethod initialize-instance :after ((self K-dist) &key) (setf (lower-bound-of self) 0.0)) (defmethod (setf df-of) (new-value (dist K-dist)) (cond ((> new-value 0) (setf (slot-value dist 'df) new-value) new-value) (T (quail-error "~&Degrees of Freedom must be greater than zero, not = ~s" new-value)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; K DISTRIBUTION ;;; This set of methods defines the probability density function (pdf), cumulative ;;; density function (cdf), the quantile function, and a random value for the ;;; K distribution with parameter degrees of freedom (m). ;;; ;;; A K random-variable is simply a one to one transform of ;;; a chi-squared random variable. If x has a chi-squared distribution ;;; on m degrees of freedom, then y = sqrt(x/m) has a K distribution ;;; on m degrees of freedom. ;;; The methods depend on this close relation. ;;; (m/2) ;;; pdf at x: m (m - 1) -(myy/2) ;;; ------------------------------ * y e ;;; (m/2)-1 ;;; 2 * gamma (m/2) ;;; ;;; ;;; cdf at x : from the chi-squared P(Y <= a) = P(Y^2 <= a^2) ;;; = P(m*Y^2 <= m*a^2) ;;; = P(x <= m*a^2) ;;; ;;; ;;; random value : from the chi-squared y = sqrt(x/m) ;;; ;;; quantile at p : from the chi-squared p = P(Y <= a) ;;; = P(x <= ma^2) ;;; so if Qx is the p'th quantile of a chi-squared(m), ;;; then the p'th quantile "a" of the K(m) distribution is just ;;; a = sqrt(Qx/m) ;;;*************************** (defmethod pdf-at ((distribution K-dist) (y number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline log-gamma)) (with-CL-functions (+ * / - exp log =) (if (= y 0.0) 0.0 (let* ((m (eref (df-of distribution) 0)) (m/2 (/ m 2.0D0)) (constant (- (* m/2 (log m)) (* (- m/2 1) (log 2.0D0)) (log-gamma m/2)))) (exp (+ constant (* (- m 1.0) (log y)) (- (* m/2 y y)))) )))) ;;;*************************** (defmethod cdf-at ((distribution K-dist) (x number)) "Derived from relation to Chi-squared." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline incomplete-gamma)) (if (> x 0) (with-CL-functions (/ -) (let ((m (eref (df-of distribution) 0))) (dist-chi (* m x x) :df m))) 0)) ;;;*************************** (defmethod random-value ((distribution K-dist) &optional (n 1)) "Derived from relation to Chi-squared." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let* ((m (eref (df-of distribution) 0))) (sqrt (/ (random-chi :n n :df m) m )))) ;;;*************************** ;;; (defmethod quantile-at ((distribution K-dist) (p number) &key (start NIL)) "Derived from relation to Chi-squared." (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((m (eref (df-of distribution) 0))) (sqrt (/ (quantile-chi p :df m) m)))) (defvar *K-dist* NIL "An instance of a K-dist representing the K-dist distribution ~ with df degrees of freedom. ~ This instance is used by the standard K-dist functions random-K, ~ quantile-K, etc.") (defun density-K (x &key (df 1)) "Returns the value of a K-dist density at x. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the parameter of the K-dist distribution. ~ The K-dist is slightly skewed right. The smaller the degrees of fredom, ~ the greater is this skewness. As degrees of freedom increase the density ~ becomes more symmetric and converges to the point mass at 1.0))" (declare (special *K-dist*)) (let ((saved-df (df-of *K-dist*)) result) (setf (df-of *K-dist*) df) (setf result (pdf-at *K-dist* x)) (setf (df-of *K-dist*) saved-df) result ) ) (defun quantile-K (p &key (df 1)) "Returns the value of a K-dist quantile at p with df degrees of freedom. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the parameter of the K-dist distribution. ~ The K-dist is ~ skewed to the right. The smaller the parameter df, ~ the greater is this skewness. As degrees of freedom increase the density ~ becomes more symmetric and converges to the point mass at 1.0) ~ )" (declare (special *K-dist*)) (let ((saved-df (df-of *K-dist*)) result) (setf (df-of *K-dist*) df) (setf result (quantile-at *K-dist* p)) (setf (df-of *K-dist*) saved-df) result) ) (defun random-K (&key (n 1) (df 1)) "Returns n pseudo-random values from the K-dist on df degrees of freedom. ~ ;;Location 0 and scale 1 define the standard K-dist distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg df 1 The degrees of freedom. ~ This is the parameter of the K-dist distribution. ~ The K-dist is ~ skewed to the right. The smaller the parameter df, ~ the greater is this skewness. As degrees of freedom increase the density ~ becomes more symmetric and converges to the point mass at 1.0) ~ ) ~ (:returns A vector of n pseudo-random values.)" (declare (special *K-dist*)) (let ((saved-df (df-of *K-dist*)) result) (setf (df-of *K-dist*) df) (setf result (random-value *K-dist* n)) (setf (df-of *K-dist*) saved-df) result) ) (defun dist-K (x &key (df 1)) "Calculates and returns the value of the K-dist distribution function ~ on df degrees of freedom at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the parameter of the K-dist distribution. ~ The K-dist is ~ skewed to the right. The smaller the parameter df, ~ the greater is this skewness. As degrees of freedom increase the density ~ becomes more symmetric and converges to the point mass at 1.0) ~ ) " (declare (special *K-dist*)) (let ((saved-df (df-of *K-dist*)) result) (setf (df-of *K-dist*) df) (setf result (cdf-at *K-dist* x)) (setf (df-of *K-dist*) saved-df) result) )
8,445
Common Lisp
.l
204
34.818627
119
0.524275
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4c26b633901c621e3958d779d20766f3f655939dc58cb74d6121985b8468033c
33,790
[ -1 ]
33,791
chi-squared.lsp
rwoldford_Quail/source/probability/distributions/chi-squared.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; chi-squared.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Colin and Dan ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(chi-squared df-of density-chi quantile-chi random-chi dist-chi))) (defclass chi-squared (gamma-dist) ((df :reader df-of :initarg :df :initform 1) (scale :reader scale-of :initform 2.0 :allocation :class)) (:documentation "The Chi-squared distribution, with degrees of freedom = df") ) (defmethod shape-of ((dist chi-squared)) (/ (df-of dist) 2)) (defmethod (setf df-of) (new-value (dist chi-squared)) (cond ((> new-value 0) (setf (slot-value dist 'shape) (/ new-value 2)) (setf (slot-value dist 'df) new-value) new-value) (T (quail-error "~&Degrees of Freedom must be greater than zero, not = ~s" new-value)))) (defmethod (setf shape-of) (new-value (dist chi-squared)) (call-next-method) (setf (df-of dist) (* new-value 2))) (defmethod location-of ((dist chi-squared)) 0) (defmethod (setf lower-bound-of) (new-value (dist chi-squared)) (declare (ignorable dist)) ;(declare (ignore dist)) ; 31JUL2023 (quail-error "~&(SETF LOWER-BOUND-OF):~&Chi-squared distributions have lower bound 0; ~ this cannot be changed to ~s." new-value)) (defmethod (setf location-of) (new-value (dist chi-squared)) (declare (ignorable dist)) ;(declare (ignore dist)) ;31JUL2023 (quail-error "~&(SETF LOCATION-OF):~&Chi-squared distributions have location 0; ~ this cannot be changed to ~s." new-value)) (defmethod (setf scale-of) (new-value (dist chi-squared)) (declare (ignorable dist)) ;(declare (ignore dist)) ; 31JUL2023 (quail-error "~&(SETF SCALE-OF):~&Chi-squared distributions are gammas with scale = 2.0; ~ this cannot be changed to ~s." new-value)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ; CHI-SQUARE DISTRIBUTION ; This set of methods defines the probability density function (pdf), cumulative ; density function (cdf), the quantile function, and a random value for the ; chi-square distribution with parameter degrees of freedom (V). The methods ; use the following closed forms and techniques: ; pdf at x: 1 ( v /2 - 1 ) - ( x / 2 ) ; ------------------------------ * x e ; ( v / 2 ) ; 2 * gamma ( v / 2) ; cdf at x : INSTANCE OF GAMMA WITH: shape = V / 2 ; SCALE = 2 ; ; ; random value : For V integer, even, and < 21 : Sum of V Exponentials (mean=1) ; For V integer, odd, and < 21 : Sum of V/2 Exponentials (mean=1) ; + (gaussian (0,1)) **2 ; For V non-integer : instance of gamma as above ; quantile at p : INSTANCE OF GAMMA WITH: shape = V / 2 ; SCALE = 2 ;*************************** (defmethod pdf-at ((distribution chi-squared) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline log-gamma)) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (/ (* (expt x (- (/ (df-of distribution) 2) 1)) (exp (- (/ x 2)))) (* (expt 2 (/ (df-of distribution) 2)) (exp (log-gamma (/ (df-of distribution) 2))))) )) ;*************************** ;;; cdf-at handled by gamma ;*************************** (defmethod random-value ((distribution chi-squared) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let ((w 1)) (cond ((> (df-of distribution) 20) (call-next-method)) ((evenp (df-of distribution)) ; (loop for i from 1 to (/ (df-of distribution) 2) do (do ((i 1 (incf i))) ((> i (/ (df-of distribution) 2))) (setf w (* w (random-uniform :n n)))) (* -2 (log w))) ((oddp (df-of distribution)) ; (loop for i from 1 to (/ (- (df-of distribution) 1) 2) do (do ((i 1 (incf i))) ((> i (/ (- (df-of distribution) 1) 2))) (setf w (* w (random-uniform :n n)))) (- (expt (random-gaussian :n n) 2) (* 2 (log w))))))) ;*************************** ;; ;;; quantile-at handled by gamma (defvar *chi-squared* NIL "An instance of a chi-squared representing the chi-squared distribution ~ with df degrees of freedom. ~ ;; Location 0 and scale 1 define the standard chi-squared distribution. ~ This instance is used by the standard chi-squared functions random-chi, ~ quantile-chi, etc.") (defun density-chi (x &key (df 1)) "Returns the value of a chi-squared density at x. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the shape parameter of the chi-squared distribution. ~ The chi-squared is ~ skewed to the right. The smaller the degrees of fredom, ~ the greater is this skewness.))" (declare (special *chi-squared*)) (let ((saved-df (df-of *chi-squared*)) result) (setf (df-of *chi-squared*) df) (setf result (pdf-at *chi-squared* x)) (setf (df-of *chi-squared*) saved-df) result ) ) (defun quantile-chi (p &key (df 1)) "Returns the value of a chi-squared quantile at p with df degrees of freedom. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the shape parameter of the chi-squared distribution. ~ The chi-squared is ~ skewed to the right. The smaller the shape parameter df, ~ the greater is this skewness.) ~ ;;(:arg location 0.0 The location of the chi-squared density. The chi-squared has ~ ;; positive support from the location to +infinity.) ~ ;;(:arg scale 1.0 A scale parameter to adjust the spread of the density.) ) ~ (:references Algorithm AS 91 ... Applied Statistics Algorithms - 1985; by D.J. Best and D.E.~ Roberts.)" (declare (special *chi-squared*)) (let (;;(saved-l (location-of *chi-squared*)) ;;(saved-s (scale-of *chi-squared*)) (saved-df (df-of *chi-squared*)) result) ;;(setf (location-of *chi-squared*) location) ;;(setf (scale-of *chi-squared*) scale) (setf (df-of *chi-squared*) df) (setf result (quantile-at *chi-squared* p)) ;;(setf (location-of *chi-squared*) saved-l) ;;(setf (scale-of *chi-squared*) saved-s) (setf (df-of *chi-squared*) saved-df) result) ) (defun random-chi (&key (n 1) (df 1)) "Returns n pseudo-random values from the chi-squared on df degrees of freedom. ~ ;;Location 0 and scale 1 define the standard chi-squared distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg df 1 The degrees of freedom. ~ This is the shape parameter of the chi-squared distribution. ~ The chi-squared is ~ skewed to the right. The smaller the shape parameter df, ~ the greater is this skewness.) ~ ;;(:arg location 0.0 The location of the chi-squared density. The chi-squared has ~ ;; positive support from the location to +infinity.) ~ ;;(:arg scale 1.0 A scale parameter to adjust the spread of the density.) ) ~ (:returns A vector of n pseudo-random values.)" (declare (special *chi-squared*)) (let (;;(saved-l (location-of *chi-squared*)) ;;(saved-s (scale-of *chi-squared*)) (saved-df (df-of *chi-squared*)) result) ;;(setf (location-of *chi-squared*) location) ;;(setf (scale-of *chi-squared*) scale) (setf (df-of *chi-squared*) df) (setf result (random-value *chi-squared* n)) ;;(setf (location-of *chi-squared*) saved-l) ;;(setf (scale-of *chi-squared*) saved-s) (setf (df-of *chi-squared*) saved-df) result) ) (defun dist-chi (x &key (df 1)) "Calculates and returns the value of the chi-squared distribution function ~ on df degrees of freedom at x. ~ (i.e. prob(X <= x) .) ~ ;; Location 0 and scale 1 define the standard chi-squared distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg df 1 The degrees of freedom. ~ This is the shape parameter of the chi-squared distribution. ~ The chi-squared is ~ skewed to the right. The smaller the shape parameter df, ~ the greater is this skewness.) ~ ;;(:arg location 0.0 The location of the chi-squared density. The chi-squared has ~ ;; positive support from the location to +infinity.) ~ ;;(:arg scale 1.0 A scale parameter to adjust the spread of the density.) ) " (declare (special *chi-squared*)) (let (;;(saved-l (location-of *chi-squared*)) ;;(saved-s (scale-of *chi-squared*)) (saved-df (df-of *chi-squared*)) result) ;;(setf (location-of *chi-squared*) location) ;;(setf (scale-of *chi-squared*) scale) (setf (df-of *chi-squared*) df) (setf result (cdf-at *chi-squared* x)) ;;(setf (location-of *chi-squared*) saved-l) ;;(setf (scale-of *chi-squared*) saved-s) (setf (df-of *chi-squared*) saved-df) result) )
10,376
Common Lisp
.l
237
37.413502
97
0.555257
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
37f9ea83a4a9bbca2a64a22d4281e04e940d8d84b2efd77962204649b688f2d8
33,791
[ -1 ]
33,792
student.lsp
rwoldford_Quail/source/probability/distributions/student.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; student.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Rupa and Rita and Dianne ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(student df-of location-of scale-of density-student quantile-student random-student dist-student))) (defclass student (continuous-dist) ((df :accessor df-of :initarg :df) (location :accessor location-of :initarg :location :initform 0) (scale :accessor scale-of :initarg :scale :initform 1)) (:documentation "The location-scale Student's t-distribution, ~ with location location-of, and scale scale-of.") ) ;;; Since the pdf of the student-t distribution cannot be integrated in closed form ;;; cdf-at use the incomplete-beta function. Quantile-at uses the Illinois function. ;;; The random-value was generated from a standard-gaussian and chi-squared distribution. (defmethod cdf-at ((dist student) a) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline incomplete-beta)) (with-CL-functions (+ * / - exp expt sqrt > < =) (let* ((df (df-of dist)) (d (/ df 2)) (y (/ (- a (eref (location-of dist) 0)) (eref (scale-of dist) 0))) (x (/ df (+ df (expt y 2))))) (if (< a 0) (* .5 (incomplete-beta d .5 x)) (- 1 (* .5 (incomplete-beta d .5 x))))))) (defmethod pdf-at ((dist student) a) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline log-gamma)) (with-CL-functions (+ * / - exp expt sqrt > < =) (let* ((df (eref (df-of dist) 0)) (half-df+1 (/ (+ 1.0 df) 2.0)) (sigma (eref (scale-of dist) 0)) (y (/ (- a (eref (location-of dist) 0)) sigma))) (* (/ 1 sigma) (/ (* (exp (log-gamma half-df+1)) (expt (+ 1 (/ (expt y 2) df)) (- half-df+1))) (* (sqrt df) (sqrt pi) (exp (log-gamma (/ df 2))))))))) (defmethod quantile-at ((dist student) (percentile number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < =) (let* ((location (eref (location-of dist) 0)) (scale (eref (scale-of dist) 0)) (pi/2 1.5707963267948966) (left? (if (<= percentile 0.5) T NIL)) (p (if left? (* percentile 2.0) (* (- 1.0 percentile) 2.0))) (n (eref (df-of dist) 0)) result improved-result) (cond ((= n 2) (setf result (sqrt (- (/ 2.0 (* p (- 2.0 p))) 2.0)))) ((= n 1) (setf result (* p pi/2)) (setf result (/ (cos result) (sin result)))) ((< n 1) (quail-error "~&Degrees of freedom must be >= 1, not = ~s !" n)) (T (let* ((a (/ 1.0 (- n 0.5))) (b (/ 48.0 (expt a 2))) (c (+ 96.36 (* a (- (* a (- (/ (* 20700.0 a) b)) 98.0) 16.0)))) (d (* (+ 1.0 (/ (- (/ 94.5 (+ b c)) 3.0) b)) (sqrt (* a pi/2)) n)) (x (* d p)) (y (expt x (/ 2.0 n))) ) (cond ((> y (+ 0.05 a)) (setf x (quantile-gaussian (* 0.5 p))) (setf y (expt x 2)) (if (< n 5) (setf c (+ c (* 0.3 (- n 4.5) (+ x 0.6))))) (setf c (+ (* x (- (* x (- (* x (- (* 0.05 d x) 5.0)) 7.0)) 2.0)) b c)) (setf y (* x (+ 1.0 (/ (- (/ (+ 94.5 (* y (+ 36.0 (* y (+ 6.3 (* y 0.4)))))) c) y 3.0) b)))) (setf y (* a y y)) (if (> y 0.002) (setf y (- (exp y) 1.0)) (setf y (+ y (* 0.5 y y))))) (T (setf y (+ (/ 1.0 y) (* (/ (+ n 1.0) (+ n 2.0)) (- (* y (+ (/ 0.5 (+ n 4.0)) (/ 1.0 (* 3.0 (+ n 2.0) (- (/ (+ n 6.0) (* n y)) (* 0.089 d) 0.822))))) 1.0) ))))) (setf result (sqrt (* n y))) ) ) ) ;; result is a rough approximation which can be improved as described ;; in Kennedy and Gentle as follows (flet ((improve-result (t1) (let* ((z (* 0.5 (- (* 2.0 (- 1.0 (dist-student t1 :df n))) p))) (w (/ z (density-student t1 :df n))) (n+1 (+ n 1)) (n+t2 (+ n (* t1 t1))) (psi (/ (* t1 n+1) n+t2)) (psi-prime (/ (* n+1 (- n (* t1 t1))) (* n+t2 n+t2)))) (+ t1 (* w (+ 1.0 (* w 0.5 (+ psi (* w (/ (+ (* 2.0 psi psi) psi-prime) 3.0)))))))) )) (setf improved-result (improve-result result)) (if left? (setf improved-result (* -1.0 improved-result))) (+ location (* scale improved-result)) ) ) ) ) (defmethod random-value ((dist student) &optional (n 1)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let ((df (df-of dist))) (+ (* (scale-of dist) (/ (random-gaussian :n n) (sqrt (/ (random-chi :n n :df df) df)))) (location-of dist)))) (defvar *student* NIL "An instance of a student representing the student distribution. ~ This instance is used by the standard student functions random-student, ~ quantile-student, etc.") (defun density-student (x &key (df 3) (location 0.0) (scale 1.0)) "Returns the density at x of a location scale student on df ~ degrees of freedom. ~ Location 0 and scale 1 define the standard student distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg df 3 The degrees of freedom of the student distribution. ~ A positive number, the smaller are the degrees of freedom, ~ the more probability lies in the symmetric tails of the ~ student density.) ~ (:arg location 0.0 The location of the student density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *student*)) (if (and df (> df 0)) (let ((saved-l (location-of *student*)) (saved-s (scale-of *student*)) (saved-df (df-of *student*)) result) (setf (location-of *student*) location) (setf (scale-of *student*) scale) (setf (df-of *student*) df) (setf result (pdf-at *student* x)) (setf (location-of *student*) saved-l) (setf (scale-of *student*) saved-s) (setf (df-of *student*) saved-df) result ) (quail-error "Degrees of freedom cannot be ~s for a student distribution!" df)) ) (defun quantile-student (p &key (df 3) (location 0.0) (scale 1.0)) "Returns the quantile at p of a location scale student on df degrees ~ of freedom. ~ Location 0 and scale 1 define the standard student distribution. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.) ~ ) ~ (:key ~ (:arg df 3 The degrees of freedom of the student distribution. ~ A positive number, the smaller are the degrees of freedom, ~ the more probability lies in the symmetric tails of the ~ student density.) ~ (:arg location 0.0 The location of the student density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))~ (:references Based on the CACM algorithm 396 by G.W. Hill, 1970 and ~ a one step update as recommended by Kennedy and Gentle's 1980 book ~ Statistical Computing.)" (declare (special *student*)) (if (and df (> df 0)) (let ((saved-l (location-of *student*)) (saved-s (scale-of *student*)) (saved-df (df-of *student*)) result) (setf (location-of *student*) location) (setf (scale-of *student*) scale) (setf (df-of *student*) df) (setf result (quantile-at *student* p)) (setf (location-of *student*) saved-l) (setf (scale-of *student*) saved-s) (setf (df-of *student*) saved-df) result) (quail-error "Degrees of freedom cannot be ~s for a student distribution!" df)) ) (defun random-student (&key (df 3) (n 1) (location 0.0) (scale 1.0)) "Returns n pseudo-random values from the location scale student on df degrees ~ of freedom. ~ Location 0 and scale 1 define the standard student distribution. ~ (:key ~ (:arg df 3 The degrees of freedom of the student distribution. ~ A positive number, the smaller are the degrees of freedom, ~ the more probability lies in the symmetric tails of the ~ student density.) ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg location 0.0 The location of the student density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *student*)) (if (and df (> df 0)) (let ((saved-l (location-of *student*)) (saved-s (scale-of *student*)) (saved-df (df-of *student*)) result) (setf (location-of *student*) location) (setf (scale-of *student*) scale) (setf (df-of *student*) df) (setf result (random-value *student* n)) (setf (location-of *student*) saved-l) (setf (scale-of *student*) saved-s) (setf (df-of *student*) saved-df) result) (quail-error "Degrees of freedom cannot be ~s for a student distribution!" df)) ) (defun dist-student (x &key (df 3) (location 0.0) (scale 1.0)) "Calculates and returns the value of the distribution function at x ~ for a student on df degrees of freedom distribution. ~ (i.e. prob(X <= x) .) ~ Location 0 and scale 1 define the standard student distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.) ~ ) ~ (:key ~ (:arg df 3 The degrees of freedom of the student distribution. ~ A positive number, the smaller are the degrees of freedom, ~ the more probability lies in the symmetric tails of the ~ student density.) ~ (:arg location 0.0 The location of the student density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) " (declare (special *student*)) (if (> df 0) (let ((saved-l (location-of *student*)) (saved-s (scale-of *student*)) (saved-df (df-of *student*)) result) (setf (location-of *student*) location) (setf (scale-of *student*) scale) (setf (df-of *student*) df) (setf result (cdf-at *student* x)) (setf (location-of *student*) saved-l) (setf (scale-of *student*) saved-s) (setf (df-of *student*) saved-df) result) (quail-error "Degrees of freedom cannot be ~s for a student distribution!" df)) )
13,359
Common Lisp
.l
341
27.190616
134
0.462458
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
85b47467d323fdb08e1ddf3f621f4a565f3397f050fae83fe434d6f9b00b6428
33,792
[ -1 ]
33,793
qqplot.lsp
rwoldford_Quail/source/probability/distributions/qqplot.lsp
(defgeneric qqplot (dist1 dist2 &optional n) (:documentation "Produce a quantile-quantile plot.")) (defmethod-multi qqplot ((dist1 (sequence array dimensioned-ref-object)) (dist2 T) &optional (n NIL)) (let (p) (cond ((numberp n) (setf p (seq 0.0 1.0 (/ 1.0 n))) (lines-plot :x (quantile-at dist1 p) :y (quantile-at dist2 p) :title "Quantile-Quantile Plot")) (T (setf p (cdf-at dist1 dist1))
526
Common Lisp
.l
14
26.928571
73
0.533333
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
29c5aaafa79cc79542c8672211cc7b2f6a9d964d1389734e84c5c3f8822065ad
33,793
[ -1 ]
33,794
cauchy.lsp
rwoldford_Quail/source/probability/distributions/cauchy.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; cauchy.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Rupa and Rita and Dianne and Ward ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(cauchy-dist density-cauchy quantile-cauchy random-cauchy dist-cauchy))) (defclass cauchy-dist (student) ((df :initform 1 :reader df-of :allocation :class)) (:documentation "The Cauchy distribution.") ) ;;; All methods could be calculated directly. (defmethod cdf-at ((C cauchy-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (+ .5 (* (/ 1 pi) (atan (/ (- x (location-of C)) (scale-of C))))))) (defmethod pdf-at ((C cauchy-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (* (/ 1 pi) (/ 1 (+ 1 (expt (/ (- x (location-of C)) (scale-of C)) 2)))))) (defmethod random-value ((C cauchy-dist) &optional (n 1)) (+ (* (scale-of C) (tan (* pi (- (random-uniform :n n) .5)))) (location-of C))) (defmethod quantile-at ((C cauchy-dist) (p number) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (+ (* (scale-of C) (tan (* pi (- p .5)))) (location-of C)))) (defvar *cauchy* NIL "An instance of a cauchy-dist representing the location-scale ~ cauchy distribution. ~ This instance is used by the standard cauchy functions random-cauchy, ~ quantile-cauchy, etc.") (defun density-cauchy (x &key (location 0.0) (scale 1.0)) "Returns the value of a location scale cauchy density at x. ~ Location 0 and scale 1 define the standard cauchy distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg location 0.0 The location of the cauchy density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *cauchy*)) (let ((saved-l (location-of *cauchy*)) (saved-s (scale-of *cauchy*)) result) (setf (location-of *cauchy*) location) (setf (scale-of *cauchy*) scale) (setf result (pdf-at *cauchy* x)) (setf (location-of *cauchy*) saved-l) (setf (scale-of *cauchy*) saved-s) result ) ) (defun quantile-cauchy (p &key (location 0.0) (scale 1.0)) "Returns the quantile at p of a location scale cauchy. ~ Location 0 and scale 1 define the standard cauchy distribution. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg location 0.0 The location of the cauchy density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *cauchy*)) (let ((saved-l (location-of *cauchy*)) (saved-s (scale-of *cauchy*)) result) (setf (location-of *cauchy*) location) (setf (scale-of *cauchy*) scale) (setf result (quantile-at *cauchy* p)) (setf (location-of *cauchy*) saved-l) (setf (scale-of *cauchy*) saved-s) result) ) (defun random-cauchy (&key (n 1) (location 0.0) (scale 1.0)) "Returns n pseudo-random values from the location scale cauchy. ~ Location 0 and scale 1 define the standard cauchy distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg location 0.0 The location of the cauchy density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *cauchy*)) (let ((saved-l (location-of *cauchy*)) (saved-s (scale-of *cauchy*)) result) (setf (location-of *cauchy*) location) (setf (scale-of *cauchy*) scale) (setf result (random-value *cauchy* n)) (setf (location-of *cauchy*) saved-l) (setf (scale-of *cauchy*) saved-s) result) ) (defun dist-cauchy (x &key (location 0.0) (scale 1.0)) "Calculates and returns the value of the distribution function at x ~ for a location-scale cauchy. ~ (i.e. prob(X <= x) .) ~ Location 0 and scale 1 define the standard cauchy distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg location 0.0 The location of the cauchy density.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) " (declare (special *cauchy*)) (let ((saved-l (location-of *cauchy*)) (saved-s (scale-of *cauchy*)) result) (setf (location-of *cauchy*) location) (setf (scale-of *cauchy*) scale) (setf result (cdf-at *cauchy* x)) (setf (location-of *cauchy*) saved-l) (setf (scale-of *cauchy*) saved-s) result) )
5,598
Common Lisp
.l
139
34.352518
84
0.576221
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a92aaec0d4008d6069115f7b0fb5cd8f87488df8e7342446b9e33024df10f344
33,794
[ -1 ]
33,795
discrete-dist.lsp
rwoldford_Quail/source/probability/distributions/discrete-dist.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; discrete-dist.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993 ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(discrete-dist))) (defclass discrete-dist (prob-measure) () (:documentation "A generic discrete probability distribution.") ) ;;;---------------------------------------------------------------------------------- ; General Methods for Discrete Distributions ; ; 1) Parameter : p = the probability in finding quantile ; value = the given value of finding in cdf-at and pdf-at ; x = the variable in the given function ; ; 2) cdf-at : using the summation to find the cdf-at if the function given is a pdf. ; ; 3) pdf-at : f(x) = F(x) - F(x-1) ; ; 4) quantile-at : using the FIND-LIMITS to find the range of the quantile and ; then using the BISECTION to find out the quantile-at ; ;;;---------------------------------------------------------------------------------- (defmethod cdf-at ((disc discrete-dist) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (loop for i from 0 to (floor value) sum (pdf-at disc i))) ;; return pdf-at value (defmethod pdf-at ((disc discrete-dist) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (/ -) (- (cdf-at disc value) (cdf-at disc (- value 1))))) ;; return quantile-at value (defmethod quantile-at ((disc discrete-dist) p &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (multiple-value-bind (l u) (find-limits disc p) (bisection disc p :lower l :upper u)))
2,320
Common Lisp
.l
58
34.810345
88
0.479982
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d9be5e586b5354d28cc0093c7213817f7bd50f31c6720625349e0c3ac48c1137
33,795
[ -1 ]
33,796
poisson.lsp
rwoldford_Quail/source/probability/distributions/poisson.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; poisson.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Frankie and Joyce and Wai Hong ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(poisson-dist density-poisson quantile-poisson random-poisson dist-poisson mean))) (defclass poisson-dist (discrete-dist) ((lower-bound :reader lower-bound-of :initform 0 :allocation :class) (upper-bound :reader upper-bound-of :initform +infinity :allocation :class) (mean :accessor mean :initarg :mean :initform 1)) (:documentation "The poisson distribution with parameter mean") ) (defmethod (setf upper-bound-of) (new-value (dist poisson-dist)) (declare (ignorable dist)) ;(declare (ignore dist)) ; 31JUL2023 (unless (= new-value infinity) (quail-error "Upper bound of a Poisson must be +infinity. It cannot ~ be reset to ~s" new-value))) (defmethod (setf lower-bound-of) (new-value (dist poisson-dist)) (declare (ignorable dist)) ;(declare (ignore dist)) ; 31JUL2023 (unless (= new-value 0) (quail-error "Lower bound of a Poisson must be 0. It cannot ~ be reset to ~s" new-value))) ;;;----------------------------------------------------------------------------- ;;; ;;; PDF-AT (POISSON) ;;; ;;;----------------------------------------------------------------------------- (defmethod pdf-at ((dist poisson-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt exp) (let ((mean (eref (mean dist) 0))) (if (and (integerp x) (>= x 0)) (/ (expt mean x) (* (exp mean) (factorial x))) 0)))) ;;;------------------------------------------------------------------------------ ;;; ;;; CDF-AT (POISSON) using incomplete gamma complement function, Q, where ;;; P(X < k) = Q(k, mean) ;;; ;;;------------------------------------------------------------------------------ (defmethod cdf-at ((dist poisson-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ floor) (let ((mean (eref (mean dist) 0))) (multiple-value-bind (value1 value2) (incomplete-gamma-complement (+ 1 (floor x)) mean) value2 value1) ))) ;;;----------------------------------------------------------------------------- ;;; ;;; RANDOM-VALUE (POISSON) BASED ON POISSON PROCESS ;;; ;;;----------------------------------------------------------------------------- #| Inherit from discrete (defmethod random-value ((po poisson-dist) &optional (n 1)) (flet ((generate-one () (let ((u) (p 1) (rand 0) (c (/ 1 (exp (mean po))))) (loop (setf u (random-uniform)) (setf p (* p u)) (if (>= p c) (setf rand (+ rand 1)) (return rand)) )))) (if (= n 1) (generate-one) (array (loop for i from 1 to n collect (generate-one))) ) )) |# ;;;----------------------------------------------------------------------------- ;;; ;;; QUANTILE-AT (POISSON) ;;; ;;;----------------------------------------------------------------------------- (defmethod quantile-at ((dist poisson-dist) (prob number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (floor) (let ((m (floor (eref (mean dist) 0)))) (multiple-value-bind (l u) (find-limits dist prob :increment m) (bisection dist prob :lower l :upper u))))) (defvar *poisson* NIL "An instance of a poisson representing the poisson distribution. ~ This instance is used by the standard poisson functions random-poisson, ~ quantile-poisson, etc.") (defun density-poisson (x &key (mean 1)) "Returns the value of a poisson probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg mean 1 The mean of the poisson.))" (declare (special *poisson*)) (let ((saved-mean (mean *poisson*)) result) (setf (mean *poisson*) mean) (setf result (pdf-at *poisson* x)) (setf (mean *poisson*) saved-mean) result ) ) (defun quantile-poisson (prop &key (mean 1)) "Returns the value of the prop'th poisson quantile. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg mean 1 The mean of the poisson.))" (declare (special *poisson*)) (let ((saved-mean (mean *poisson*)) result) (setf (mean *poisson*) mean) (setf result (quantile-at *poisson* prop)) (setf (mean *poisson*) saved-mean) result)) (defun random-poisson (&key (n 1) (mean 1)) "Returns n pseudo-random values from the poisson. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg mean 1 The mean of the poisson.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *poisson*)) (let ((saved-mean (mean *poisson*)) result) (setf (mean *poisson*) mean) (setf result (random-value *poisson* n)) (setf (mean *poisson*) saved-mean) result) ) (defun dist-poisson (x &key (mean 1)) "Calculates and returns the value of the specified poisson distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg mean 1 The mean of the poisson.))" (declare (special *poisson*)) (let ((saved-mean (mean *poisson*)) result) (setf (mean *poisson*) mean) (setf result (cdf-at *poisson* x)) (setf (mean *poisson*) saved-mean) result))
6,603
Common Lisp
.l
174
31.224138
112
0.494732
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
779fba664a1164796ff48d010d5382a319f020d2c487279aaa674cbf6ccb5699
33,796
[ -1 ]
33,797
exponential.lsp
rwoldford_Quail/source/probability/distributions/exponential.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; exponential.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; R.W. Oldford 1993. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Colin and Dan ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(exponential-dist density-exponential quantile-exponential random-exponential dist-exponential))) (defclass exponential-dist (gamma-dist) ((shape :reader shape-of :allocation :class :initform 1.0 :documentation "The shape parameter of an exponential is 1.0") (upper-bound :reader upper-bound-of :allocation :class :initform +infinity) ) (:documentation "The location-scale exponential distribution.") ) (defmethod (setf shape-of) (new-value (who exponential-dist)) (declare (ignorable new-value who)) ;(declare (ignore new-value who)) ; 31JUL2023 (quail-error "Sorry, can't change the shape parameter for the exponential. ~ Instead, consider changing its class to gamma first.") ) ; EXPONENTIAL DISTRIBUTION ; This set of methods defines the probability density function (pdf), cumulative ; density function (cdf), the quantile function, and a random value for the ; exponential distribution. ;;; ;;; The mathematical form of the location scale exponential distribution with ;;; location u, scale s and shape parameter a is as follows: ;;; ;;; ;;; pdf at x: ;;; for x > u ;;; ;;; 1 - ((x - u) / s) ;;; --- * e ;;; s ;;; ;;; 0 otherwise ;;; ;;; ;;; cdf at x: ;;; for x > u ;;; - ((x - u) / s) ;;; 1 - e ;;; ;;; 0 otherwise ;;; ;;; random value : u - s * ln ( uniform ) ;;; ;;; quantile at p : u - s * ln ( 1 - p ) (defmethod pdf-at ((distribution exponential-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= <=) (let ((sigma (scale-of distribution))) (/ (exp (/ (- (location-of distribution) x) sigma)) sigma)))) ;************************* (defmethod cdf-at ((distribution exponential-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp) (- 1 (exp (/ (- (location-of distribution) x) (scale-of distribution)))))) ;*************************** (defmethod random-value ((distribution exponential-dist) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((loc (eref (location-of distribution) 0)) (s (eref (scale-of distribution) 0))) (if (= n 1) (with-CL-functions (+ * / - exp log) (- loc (* s (log (random-uniform)))) ) (array (loop for i from 1 to n collect (with-CL-functions (+ * / - exp log) (- loc (* s (log (random-uniform)))) ) ))))) ;*************************** (defmethod quantile-at ((distribution exponential-dist) (p number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((loc (eref (location-of distribution) 0)) (s (eref (scale-of distribution) 0))) (with-CL-functions (+ * / - exp log) (- loc (* s (log (- 1 p)))) ) )) (defvar *exponential-dist* NIL "An instance of a exponential-dist representing the exponential distribution. ~ This instance is used by the standard exponential functions random-exponential, ~ quantile-exponential, etc.") (defun density-exponential (x &key (location 0.0) (scale 1.0)) "Returns the value of a location scale exponential density at x. ~ Location 0 and scale 1 define the standard exponential distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg location 0.0 The location of the exponential density. The exponential has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *exponential-dist*)) (let ((saved-l (location-of *exponential-dist*)) (saved-s (scale-of *exponential-dist*)) result) (setf (location-of *exponential-dist*) location) (setf (scale-of *exponential-dist*) scale) (setf result (pdf-at *exponential-dist* x)) (setf (location-of *exponential-dist*) saved-l) (setf (scale-of *exponential-dist*) saved-s) result ) ) (defun quantile-exponential (p &key (location 0.0) (scale 1.0)) "Returns the value of a location scale exponential quantile at p. ~ Location 0 and scale 1 define the standard exponential distribution. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg location 0.0 The location of the exponential density. The exponential has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.))" (declare (special *exponential-dist*)) (let ((saved-l (location-of *exponential-dist*)) (saved-s (scale-of *exponential-dist*)) result) (setf (location-of *exponential-dist*) location) (setf (scale-of *exponential-dist*) scale) (setf result (quantile-at *exponential-dist* p)) (setf (location-of *exponential-dist*) saved-l) (setf (scale-of *exponential-dist*) saved-s) result) ) (defun random-exponential (&key (n 1) (location 0.0) (scale 1.0)) "Returns n pseudo-random values from the location scale exponential. ~ Location 0 and scale 1 define the standard exponential distribution. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg location 0.0 The location of the exponential density. The exponential has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *exponential-dist*)) (let ((saved-l (location-of *exponential-dist*)) (saved-s (scale-of *exponential-dist*)) result) (setf (location-of *exponential-dist*) location) (setf (scale-of *exponential-dist*) scale) (setf result (random-value *exponential-dist* n)) (setf (location-of *exponential-dist*) saved-l) (setf (scale-of *exponential-dist*) saved-s) result) ) (defun dist-exponential (x &key (location 0.0) (scale 1.0)) "Calculates and returns the value of the specified exponential distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ Location 0 and scale 1 define the standard exponential distribution. ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg location 0.0 The location of the exponential density. The exponential has ~ positive support from the location to +infinity.) ~ (:arg scale 1.0 A scale parameter to adjust the spread of the density.)) " (declare (special *exponential-dist*)) (let ((saved-l (location-of *exponential-dist*)) (saved-s (scale-of *exponential-dist*)) result) (setf (location-of *exponential-dist*) location) (setf (scale-of *exponential-dist*) scale) (setf result (cdf-at *exponential-dist* x)) (setf (location-of *exponential-dist*) saved-l) (setf (scale-of *exponential-dist*) saved-s) result) )
8,506
Common Lisp
.l
200
35.675
86
0.579754
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
666b13d8adfb9f67e04638518cfdf4c5dc3804a7b20fb206e2c9bd1ad461788a
33,797
[ -1 ]
33,798
pareto.lsp
rwoldford_Quail/source/probability/distributions/pareto.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; pareto.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pareto shape-of density-pareto dist-pareto random-pareto quantile-pareto))) (defclass pareto (continuous-dist) ((shape :initform 1.0 :initarg :shape :reader shape-of) (lower-bound :initform 0.0 :reader lower-bound-of) (upper-bound :initform infinity :reader upper-bound-of) ) (:documentation "The pareto distribution parameterized by a single shape parameter.")) (defmethod (setf shape-of) (new-value (dist pareto)) (if (> new-value 0) (setf (slot-value dist 'shape) new-value) (quail-error "~&The shape parameter must be positive. ~ Not ~s." new-value))) (defmethod pdf-at ((dist pareto) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt) (let ((shape (eref (shape-of dist) 0))) (* shape (expt (+ 1 value) (- (+ 1 shape))))))) (defmethod cdf-at ((dist pareto) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt) (let* ((shape (eref (shape-of dist) 0)) (power (expt (+ 1 value) shape))) (/ (- power 1.0 ) power)))) (defmethod quantile-at ((dist pareto) (value number) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt) (let* ((shape (eref (shape-of dist) 0))) (- (expt (- 1 value) (/ -1.0 shape)) 1.0)))) (defvar *pareto* NIL "An instance of a pareto representing the pareto distribution. ~ This instance is used by the standard pareto functions random-pareto, ~ quantile-pareto, etc.") (defun density-pareto (x &key (shape 1)) "Returns the value of a pareto probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *pareto*)) (let ((saved-shape (shape-of *pareto*)) result) (setf (shape-of *pareto*) shape) (setf result (pdf-at *pareto* x)) (setf (shape-of *pareto*) saved-shape) result ) ) (defun quantile-pareto (prop &key (shape 1)) "Returns the value of the prop'th pareto quantile. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *pareto*)) (let ((saved-shape (shape-of *pareto*)) result) (setf (shape-of *pareto*) shape) (setf result (quantile-at *pareto* prop)) (setf (shape-of *pareto*) saved-shape) result)) (defun random-pareto (&key (n 1) (shape 1)) "Returns n pseudo-random values from the pareto. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg shape 1 The shape parameter.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *pareto*)) (let ((saved-shape (shape-of *pareto*)) result) (setf (shape-of *pareto*) shape) (setf result (random-value *pareto* n)) (setf (shape-of *pareto*) saved-shape) result) ) (defun dist-pareto (x &key (shape 1)) "Calculates and returns the value of the specified pareto distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *pareto*)) (let ((saved-shape (shape-of *pareto*)) result) (setf (shape-of *pareto*) shape) (setf result (cdf-at *pareto* x)) (setf (shape-of *pareto*) saved-shape) result))
4,404
Common Lisp
.l
114
32.605263
122
0.566964
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3ca257c4c9040ed8bd3c627e3099821a5dd60b12e014041f92aed803566e7d08
33,798
[ -1 ]
33,799
location-scale.lsp
rwoldford_Quail/source/probability/distributions/location-scale.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; location-scale.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; *** NB There is no protection against negative scale. ;;; Should divides-object and minus-object be handled? ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(location-scale-dist location-of scale-of))) (defclass location-scale-dist (prob-measure) ((location :initarg :location :accessor location-of :initform 0) (scale :initarg :scale :accessor scale-of :initform 1) (standard-dist :accessor standard-dist-of :initarg :standard-dist :initform NIL)) (:documentation "A location-scale transformation of an arbitrary distribution. ~ The distribution is stored here as the standard distribution. ~ The location must be a finite number and the scale a positive ~ number.")) (defmethod plus-object ((a number) (b prob-measure)) (make-instance 'location-scale-dist :location a :standard-dist b)) (defmethod plus-object ((a prob-measure) (b number)) (plus-object b a)) (defmethod plus-object ((a number) (b location-scale-dist)) (make-instance 'location-scale-dist :location (+ a (location-of b)) :scale (scale-of b) :standard-dist (standard-dist-of b))) (defmethod plus-object ((a location-scale-dist) (b number)) (plus-object b a)) (defmethod times-object ((a number) (b prob-measure)) (make-instance 'location-scale-dist :scale a :standard-dist b)) (defmethod times-object ((a prob-measure) (b number)) (times-object b a)) (defmethod times-object ((a number) (b location-scale-dist)) (make-instance 'location-scale-dist :location (* a (location-of b)) :scale (* a (scale-of b)) :standard-dist (standard-dist-of b))) (defmethod times-object ((a location-scale-dist) (b number)) (times-object b a)) (defmethod pdf-at ((dist location-scale-dist) (x number)) (let ((location (location-of dist)) (scale (scale-of dist))) (/ (pdf-at (standard-dist-of dist) (/ (- x location) scale)) scale))) (defmethod cdf-at ((dist location-scale-dist) (x number)) (let ((location (location-of dist)) (scale (scale-of dist))) (cdf-at (standard-dist-of dist) (/ (- x location) scale)))) (defmethod quantile-at ((dist location-scale-dist) (x number) &key start) (declare (ignore start)) (let ((location (location-of dist)) (scale (scale-of dist))) (+ location (* scale (quantile-at (standard-dist-of dist) x))))) (defmethod random-value ((dist location-scale-dist) &optional (n 1)) (let ((location (eref (location-of dist) 0)) (scale (eref (scale-of dist) 0))) (if (> n 1) (array (loop for i from 1 to n collect (with-CL-functions (+ *) (+ location (* scale (random-value (standard-dist-of dist)))))) ) (with-CL-functions (+ *) (+ location (* scale (random-value (standard-dist-of dist))))) ))) (defmethod lower-bound-of ((dist location-scale-dist)) (+ (location-of dist) (lower-bound-of (standard-dist-of dist)))) (defmethod upper-bound-of ((dist location-scale-dist)) (+ (location-of dist) (upper-bound-of (standard-dist-of dist)))) (defmethod (setf lower-bound-of) (new-value (dist location-scale-dist)) (declare (ignorable new-value dist)) ;(declare (ignore new-value dist)) ; 31JUL2023 (quail-error "Cannot reset the lower bound of a location-scale-dist")) (defmethod (setf upper-bound-of) (new-value (dist location-scale-dist)) (declare (ignorable new-value dist)) ;(declare (ignore new-value dist)) ; 31JUL2023 (quail-error "Cannot reset the upper bound of a location-scale-dist")) (defmethod initialize-instance :after ((dist location-scale-dist) &rest initargs) (declare (ignore initargs)) (if (<= (scale-of dist) 0) (quail-error "Cannot initialize the scale to be non-positive! ~&~ Here scale = ~s ." (scale-of dist))) (if (or (< (location-of dist) (lower-bound-of dist)) (> (location-of dist) (upper-bound-of dist))) (quail-error "~&Cannot initialize the location (~s) to be ~ outside the bounds of the support of the probability distribution! ~&~ lower-bound = ~s ~&~ upper-bound = ~s ." (location-of dist) (lower-bound-of dist) (upper-bound-of dist))) dist) #| (defmethod (setf location-of) :around (new-value (self location-scale-dist)) (setf (lower-bound-of self) (+ (lower-bound-of self) (- new-value (location-of self)))) (setf (upper-bound-of self) (+ (upper-bound-of self) (- new-value (location-of self)))) (call-next-method)) (defmethod (setf scale-of) :around (new-value (self location-scale-dist)) (cond ((or (not (numberp new-value)) (<= new-value 0)) (quail-error "Scale must be a positive real number! ~&~ ~s is not." (scale-of self))) (T (setf (lower-bound-of self) (* (lower-bound-of self) new-value)) (setf (upper-bound-of self) (* (upper-bound-of self) new-value)) (call-next-method)))) |#
5,885
Common Lisp
.l
147
32.503401
109
0.581224
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
14c2afba17e04c358e1eca1fb8fb7d3184cca6efc132e0108029a4fc5fda20d2
33,799
[ -1 ]
33,800
binomial.lsp
rwoldford_Quail/source/probability/distributions/binomial.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; binomial.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Frankie and Joyce and Wai Hong ;;; R.W. Oldford 1995 ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(binomial-dist number-of-trials prob-success density-binomial quantile-binomial random-binomial dist-binomial))) (defclass binomial-dist (discrete-dist) ((lower-bound :accessor lower-bound-of :initform 0 :allocation :class) (upper-bound :accessor upper-bound-of :initarg :upper-bound) (p :accessor p-of :initarg :p)) (:documentation "The binomial distribution with parameters number-of-trials-of ~ being :upper-bound~ and the prob-success being :p.") ) (defmethod initialize-instance :after ((self binomial-dist) &rest initargs &key (n NIL)) (declare (ignore initargs)) (if (and n (numberp n) (> n 0)) (setf (number-of-trials self) n)) ) (defmethod number-of-trials ((dist binomial-dist)) (upper-bound-of dist)) (defmethod (setf number-of-trials) (new-value (dist binomial-dist)) (if (and (integerp new-value) (> new-value 0)) (setf (upper-bound-of dist) new-value) (quail-error "Total number of trials must be an integer greater than zero, ~ not ~s ." new-value))) (defmethod prob-success ((dist binomial-dist)) (p-of dist)) (defmethod (setf prob-success) (new-value (dist binomial-dist)) (if (and (<= new-value 1.0) (>= new-value 0.0)) (setf (p-of dist) new-value) (quail-error "Probability of success must be a number between 0.0 ~ and 1.0 inclusive, ~ not ~s ." new-value))) (defmethod (setf lower-bound-of) (new-value (dist binomial-dist)) (unless (= new-value 0) (quail-error "LOWER-BOUND-OF for class ~s must be 0." (class-name (class-of dist))))) ;;;----------------------------------------------------------------------------- ;;; ;;; PDF-AT (binomial-dist) ;;; ;;;----------------------------------------------------------------------------- (defmethod pdf-at ((bi binomial-dist) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline choose)) (multiple-value-bind (integer-x frac-x) (truncate x) (if (zerop frac-x) (with-CL-functions (+ * / - exp expt sqrt > < = /=) (let ((n (upper-bound-of bi)) (p (p-of bi))) (* (choose n integer-x) (expt p integer-x) (expt (- 1 p) (- n integer-x))))) 0))) ;;;----------------------------------------------------------------------------- ;;; ;;; CDF-AT (binomial-dist) using incomplete beta function, I, where ;;; P(X >= k) = I(k, n-k+1, p) ;;; ;;;----------------------------------------------------------------------------- (defmethod cdf-at ((bi binomial-dist) x) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let (intx) (cond ((not (numberp x)) (quail-error "~s is not a number!" x)) ((minusp x) 0) ((>= x (upper-bound-of bi)) 1) (T (setf intx (floor x)) (- 1 (incomplete-beta (+ 1 intx) (- (upper-bound-of bi) intx) (p-of bi)) )) ))) ;;;----------------------------------------------------------------------------- ;;; ;;; RANDOM-VALUE (binomial-dist) USING SUM OF BERNOULLI R.V.'S METHOD ;;; ;;;----------------------------------------------------------------------------- (defmethod random-value ((bi binomial-dist) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((rand 0) (p (p-of bi))) ; (loop for i from 1 to (upper-bound-of bi) do (do ((i 1 (incf i))) ((> i (upper-bound-of bi))) (setf rand (+ rand (random-bernoulli :p p :n n)))) rand )) ;;;----------------------------------------------------------------------------- ;;; ;;; QUANTILE-AT (binomial-dist) ;;; ;;;----------------------------------------------------------------------------- (defmethod quantile-at ((bi binomial-dist) (prob number) &key (start 0)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (bisection bi prob)) (defvar *binomial* NIL "An instance of a binomial representing the binomial distribution. ~ This instance is used by the standard binomial functions random-binomial, ~ quantile-binomial, etc.") (defun density-binomial (x &key (total 1) (p 0.5)) "Returns the value of a binomial probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg total 1 The total number of trials for the binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *binomial*)) (let ((saved-n (number-of-trials *binomial*)) (saved-p (prob-success *binomial*)) result) (setf (number-of-trials *binomial*) total) (setf (prob-success *binomial*) p) (setf result (pdf-at *binomial* x)) (setf (number-of-trials *binomial*) saved-n) (setf (prob-success *binomial*) saved-p) result ) ) (defun quantile-binomial (prop &key (total 1) (p 0.5)) "Returns the value of the prop'th binomial quantiles. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg total 1 The total number of trials for the binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *binomial*)) (let ((saved-n (number-of-trials *binomial*)) (saved-p (prob-success *binomial*)) result) (setf (number-of-trials *binomial*) total) (setf (prob-success *binomial*) p) (setf result (quantile-at *binomial* prop)) (setf (number-of-trials *binomial*) saved-n) (setf (prob-success *binomial*) saved-p) result)) (defun random-binomial (&key (n 1) (total 1) (p 0.5)) "Returns n pseudo-random values from the binomial. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg total 1 The total number of trials for the binomial.) ~ (:arg p 0.5 The probability of success at each trial.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *binomial*)) (let ((saved-n (number-of-trials *binomial*)) (saved-p (prob-success *binomial*)) result) (setf (number-of-trials *binomial*) total) (setf (prob-success *binomial*) p) (setf result (random-value *binomial* n)) (setf (number-of-trials *binomial*) saved-n) (setf (prob-success *binomial*) saved-p) result) ) (defun dist-binomial (x &key (total 1) (p 0.5)) "Calculates and returns the value of the specified binomial distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg total 1 The total number of trials for the binomial.) ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *binomial*)) (let ((saved-n (number-of-trials *binomial*)) (saved-p (prob-success *binomial*)) result) (setf (number-of-trials *binomial*) total) (setf (prob-success *binomial*) p) (setf result (cdf-at *binomial* x)) (setf (number-of-trials *binomial*) saved-n) (setf (prob-success *binomial*) saved-p) result))
8,409
Common Lisp
.l
208
33.346154
84
0.519759
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1ed1367fe52921517fd30d9007405003ee87f8e924ee7c259da8e0fdd4735aa8
33,800
[ -1 ]
33,801
weibull.lsp
rwoldford_Quail/source/probability/distributions/weibull.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; weibull.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(weibull shape-of density-weibull dist-weibull random-weibull quantile-weibull))) (defclass weibull (continuous-dist) ((shape :initform 1.0 :initarg :shape :reader shape-of) (lower-bound :initform 0.0 :reader lower-bound-of) (upper-bound :initform infinity :reader upper-bound-of) ) (:documentation "The weibull distribution with a shape parameter.")) (defmethod (setf shape-of) (new-value (dist weibull)) (if (> new-value 0) (setf (slot-value dist 'shape) new-value) (quail-error "~&The shape parameter must be positive. ~ Not ~s." new-value))) (defmethod pdf-at ((dist weibull) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions ( = - exp * expt) (if (= value 0.0) 0.0 (let ((shape (eref (shape-of dist) 0))) (* shape (expt value (- shape 1.0)) (exp (* -1.0 (expt value shape)))))))) (defmethod cdf-at ((dist weibull) (value number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions ( = - exp * expt) (- 1.0 (exp (- (expt value (eref (shape-of dist) 0))))))) (defmethod quantile-at ((dist weibull) (value number) &key start) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions ( = - exp * expt) (let ((shape (eref (shape-of dist) 0))) (expt (- (log (- 1.0 value))) (/ 1.0 shape))))) (defvar *weibull* NIL "An instance of a weibull representing the weibull distribution. ~ This instance is used by the standard weibull functions random-weibull, ~ quantile-weibull, etc.") (defun density-weibull (x &key (shape 1)) "Returns the value of a weibull probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *weibull*)) (let ((saved-shape (shape-of *weibull*)) result) (setf (shape-of *weibull*) shape) (setf result (pdf-at *weibull* x)) (setf (shape-of *weibull*) saved-shape) result ) ) (defun quantile-weibull (prop &key (shape 1)) "Returns the value of the prop'th weibull quantile. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *weibull*)) (let ((saved-shape (shape-of *weibull*)) result) (setf (shape-of *weibull*) shape) (setf result (quantile-at *weibull* prop)) (setf (shape-of *weibull*) saved-shape) result)) (defun random-weibull (&key (n 1) (shape 1)) "Returns n pseudo-random values from the weibull. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg shape 1 The shape parameter.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *weibull*)) (let ((saved-shape (shape-of *weibull*)) result) (setf (shape-of *weibull*) shape) (setf result (random-value *weibull* n)) (setf (shape-of *weibull*) saved-shape) result) ) (defun dist-weibull (x &key (shape 1)) "Calculates and returns the value of the specified weibull distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg shape 1 The shape parameter.))" (declare (special *weibull*)) (let ((saved-shape (shape-of *weibull*)) result) (setf (shape-of *weibull*) shape) (setf result (cdf-at *weibull* x)) (setf (shape-of *weibull*) saved-shape) result))
4,493
Common Lisp
.l
118
31.830508
126
0.565478
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f2b648f6d9fa64e96ee3fe6bdd548032443f3a398d5301f8334c8d1e7f44439b
33,801
[ -1 ]
33,802
bisection.lsp
rwoldford_Quail/source/probability/distributions/bisection.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; bisection.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Wai Hong Choi ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;;----------------------------------------------------------------------------- ;;; ;;; BISECTION: Given prob, lower and upper, bisection gives F-inverse(prob) ;;; which should be an element of [lower upper]. ;;; ;;; ;;;----------------------------------------------------------------------------- (defmethod bisection ((distn prob-measure) prob &key (lower nil) (upper nil) (epsilon 1.0d-10) (max-it 500)) "Return one value. the value, inverse cdf at prob, is found using bisection method." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline same)) (with-CL-functions (+ * / - exp expt sqrt > < =) (let ((m) (it 0)) (if (equal lower nil) (setf lower (lower-bound-of distn))) (if (equal upper nil) (setf upper (upper-bound-of distn))) (cond ((same distn lower prob :epsilon epsilon) lower) ((same distn upper prob :epsilon epsilon) upper) (T (loop (if (< it max-it) (setf it (+ 1 it)) (return "does not converge!")) (setf m (/ (+ upper lower) 2)) (cond ((same distn m prob :epsilon epsilon) (return (float m))) ((<= prob (cdf-at distn m)) (setf upper m) ) (T (setf lower m) )) )) )))) (defmethod same ((distn prob-measure) x prob &key (epsilon 1.0d-10)) "Return t if prob is in interval (cdf(x-epsilon),cdf(x)]" (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (+ * / - exp expt sqrt > < =) (cond ((and (> prob (cdf-at distn (- x epsilon))) (<= prob (cdf-at distn x))) T) (T nil)) )) ;;;------------------------------------------------------------------------------------ ;;; ;;; BISECTION FOR DISCRETE RANDOM VARIABLE X WHICH TAKES ON INTEGERS ONLY ;;; ;;;------------------------------------------------------------------------------------ (defmethod bisection ((distn discrete-dist) prob &key (lower nil) (upper nil) (epsilon 1.0d-10) (max-it 500)) "Return an integer which is inverse (discrete) cdf at prob" (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) (inline incomplete-gamma)) (with-CL-functions (+ * / - exp expt sqrt > < => <=) (let ((m) (it 0)) (if (not (numberp lower)) (setf lower (lower-bound-of distn)) (setf lower (floor lower))) (if (not (numberp upper)) (setf upper (upper-bound-of distn)) (setf upper (ceiling upper))) (cond ((same distn lower prob :epsilon epsilon) lower) ((same distn upper prob :epsilon epsilon) upper) (T (loop (if (< it max-it) (setf it (+ 1 it)) (return "error")) (setf m (floor (/ (+ upper lower) 2))) (cond ((same distn m prob :epsilon epsilon) (return m)) ((<= prob (cdf-at distn m)) (setf upper m) ) (T (setf lower m) ) ))) )))) (defmethod same ((distn discrete-dist) x prob &key (epsilon 1.0d-10)) "Return t if prob in interval (cdf(x-1),cdf(x)]" (declare (ignore epsilon)) (and (> prob (cdf-at distn (- x 1))) (<= prob (cdf-at distn x))) )
4,322
Common Lisp
.l
110
30.190909
88
0.43295
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6b57ffd74e2d6c140ce6778fc222ef9cb41fa4c3f348105433ec7c50c9c5b3e7
33,802
[ -1 ]
33,803
findlimits.lsp
rwoldford_Quail/source/probability/distributions/findlimits.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; findlimits-lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Wai Hong Choi 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Fall 1992 ;;; written by Wai Hong Choi ;;; for R. W. Oldford (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;;----------------------------------------------------------------------------- ;;; ;;; FIND-LIMITS : Given prob which is an element of (0,1), find-limits gives a ;;; and b such that F-inverse(prob) is an element of [a.b]. ;;; ;;;----------------------------------------------------------------------------- (defmethod find-limits ((distn prob-measure) prob &key (start 0) (increment 5) (max-it 200)) "Returns two values. the first is the lower limit and the second i~ s the upper limit of an interval which contains inverse cdf at prob" (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (let ((l) (u) (it 0)) (if (minusp increment) (setf increment (abs increment))) (cond ((= increment 0) (quail-error "~s (increment) is not postive!" increment)) ((and (numberp (lower-bound-of distn)) (numberp (upper-bound-of distn))) (setf l (lower-bound-of distn)) (setf u (upper-bound-of distn)) (values l u)) ((numberp (lower-bound-of distn)) (find-upper-limit distn prob increment)) ((numberp (upper-bound-of distn)) (find-lower-limit distn prob increment)) (T (setf l (- start increment)) (setf u (+ start increment)) (loop (if (< it max-it) (setf it (+ 1 it)) (return "Please increase value of increment!")) (cond ((and (> prob (cdf-at distn l)) (<= prob (cdf-at distn u))) (return (values l u))) ((= prob (cdf-at distn l)) (setf u l) (setf l (- l increment))) ((< prob (cdf-at distn l)) (return (find-lower-limit distn prob increment :upper l))) (T (return (find-upper-limit distn prob increment :lower u))) )))) ))) ;;;----------------------------------------------------------------------------- ;;; ;;; FIND-UPPER-LIMIT ;;; ;;; ;;;----------------------------------------------------------------------------- (defmethod find-upper-limit((distn prob-measure) prob increment &key (lower nil) (max-it 200)) "Return a value: an upper limit of an interval containing inverse cdf at ~ prob where a lower limit is given." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (let ((upper) (it 0)) (if (not lower) (setf lower (lower-bound-of distn))) (setf upper (+ lower increment)) (loop (if (< it max-it) (setf it (+ 1 it)) (quail-error "Please increase value of increment!")) (cond ((<= prob (cdf-at distn upper)) (return (values lower upper))) (T (setf lower upper) (setf upper (+ upper increment)))) )))) ;;;----------------------------------------------------------------------------- ;;; ;;; FIND-LOWER-LIMIT ;;; ;;; ;;;----------------------------------------------------------------------------- (defmethod find-lower-limit((distn prob-measure) prob increment &key (upper nil) (max-it 200)) "Return a value: a lower limit of an interval containing inverse cdf ~ at prob where an upper limit is given." (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - exp expt sqrt > < = /= ) (let ((lower) (it 0)) (if (not upper) (setf upper (upper-bound-of distn))) (setf lower (- upper increment)) (loop (if (< it max-it) (setf it (+ 1 it)) (quail-error "Please increase value of increment!")) (cond ((> prob (cdf-at distn lower)) (return (values lower upper))) (T (setf upper lower) (setf lower (- lower increment)))) ))))
4,802
Common Lisp
.l
116
33.086207
84
0.447652
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e4b140d6eee14c7802026b16fa6d55f1f46b4942a82780898586893b024f6fbb
33,803
[ -1 ]
33,804
uniform.lsp
rwoldford_Quail/source/probability/distributions/uniform.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; uniform.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; Stat 440/840: ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(uniform density-uniform quantile-uniform random-uniform dist-uniform))) (defclass uniform (beta-dist) ((shape1 :reader shape1-of :initform 1 :allocation :class) (shape2 :reader shape2-of :initform 1 :allocation :class) ;;(scale :reader scale-of ;; :initform 1 ;; :allocation :class) (generator :accessor generator-of :initform *default-random-number-generator* :initarg :generator) ) (:documentation "The Uniform distribution.")) (defmethod (setf lower-bound-of) (new-value (self uniform)) "Resetting the lower bound is not allowed." (if (< new-value (upper-bound-of self)) (setf (slot-value self 'lower-bound) new-value) (quail-error "Error: lower-bound-of a uniform distribution must be less ~ than its upper-bound -- New-value = ~s, ~ current upper-bound = ~s." new-value (upper-bound-of self)) ) ) (defmethod (setf upper-bound-of) (new-value (self uniform)) "Resetting the lower bound is not allowed." (if (> new-value (lower-bound-of self)) (setf (slot-value self 'upper-bound) new-value) (quail-error "Error: upper-bound-of a uniform distribution must be greater ~ than its lower-bound -- New-value = ~s, ~ current lower-bound = ~s." new-value (lower-bound-of self)) ) ) (defmethod cdf-at ((distribution uniform) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (> < / - ) (let ((lower (eref (lower-bound-of distribution) 0)) (upper (eref (upper-bound-of distribution) 0))) (cond (( < x (lower-bound-of distribution)) 0) (( > x upper) 1) ((/ (- x lower) (- upper lower))) ) ))) (defmethod pdf-at ((distribution uniform) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (> < / - ) (let ((lower (eref (lower-bound-of distribution) 0)) (upper (eref (upper-bound-of distribution) 0))) (if (and ( > x lower) ( < x upper)) (/ 1 (- upper lower)) 0)))) (defmethod random-value ((distribution uniform) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (let ((lower (eref (lower-bound-of distribution) 0)) (upper (eref (upper-bound-of distribution) 0))) (float (+ lower (* (- upper lower) (/ (rand (generator-of distribution) n) (max-pseudo-rand-of (generator-of distribution)))))))) (defmethod quantile-at ((distribution uniform) (p number) &key (start NIL)) (declare (ignore start)(optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)) ) (with-CL-functions (> < / - + *) (let ((lower (eref (lower-bound-of distribution) 0)) (upper (eref (upper-bound-of distribution) 0))) (let ((a lower) (b upper)) (+ a (* p (- b a))))))) (defvar *uniform* NIL "An instance of a uniform representing the continuous uniform distribution. ~ This instance is used by the standard uniform functions random-uniform, ~ quantile-uniform, etc.") (defun density-uniform (x &key (from 0.0) (to 1.0)) "Returns the value of a location scale uniform density at x. ~ Location 0 and scale 1 define the standard uniform distribution. ~ (:required ~ (:arg x The point at which to evaluate the density.)) ~ (:key ~ (:arg from 0.0 The lower bound of the uniform density.) ~ (:arg to 1.0 The upper bound of the uniform density.))" (declare (special *uniform*)) (if (> to from) (let ((saved-l (lower-bound-of *uniform*)) (saved-u (upper-bound-of *uniform*)) result) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) from) (setf (upper-bound-of *uniform*) to) (setf result (pdf-at *uniform* x)) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) saved-l) (setf (upper-bound-of *uniform*) saved-u) result ) (quail-error "DENSITY-UNIFORM: from = ~s must be less than to = ~s" from to) ) ) (defun quantile-uniform (p &key (from 0.0) (to 1.0)) "Returns the value of a uniform quantile at p. ~ (:required ~ (:arg p The probability at which to evaluate the quantile.)) ~ (:key ~ (:arg from 0.0 The lower bound of the uniform density.) ~ (:arg to 1.0 The upper bound of the uniform density.))" (declare (special *uniform*)) (if (> to from) (let ((saved-l (lower-bound-of *uniform*)) (saved-u (upper-bound-of *uniform*)) result) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) from) (setf (upper-bound-of *uniform*) to) (setf result (quantile-at *uniform* p)) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) saved-l) (setf (upper-bound-of *uniform*) saved-u) result) (quail-error "QUANTILE-UNIFORM: from = ~s must be less than to = ~s" from to) ) ) (defun random-uniform (&key (n 1) (from 0.0) (to 1.0)) "Returns n pseudo-random values from the uniform. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg from 0.0 The lower bound of the uniform density.) ~ (:arg to 1.0 The upper bound of the uniform density.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *uniform*)) (if (> to from) (let ((saved-l (lower-bound-of *uniform*)) (saved-u (upper-bound-of *uniform*)) result) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) from) (setf (upper-bound-of *uniform*) to) (setf result (random-value *uniform* n)) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) saved-l) (setf (upper-bound-of *uniform*) saved-u) result ) (quail-error "DENSITY-UNIFORM: from = ~s must be less than to = ~s" from to) ) ) (defun dist-uniform (x &key (from 0.0) (to 1.0)) "Calculates and returns the value of the specified uniform distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg from 0.0 The lower bound of the uniform density.) ~ (:arg to 1.0 The upper bound of the uniform density.))" (declare (special *uniform*)) (if (> to from) (let ((saved-l (lower-bound-of *uniform*)) (saved-u (upper-bound-of *uniform*)) result) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) from) (setf (upper-bound-of *uniform*) to) (setf result (cdf-at *uniform* x)) (setf (lower-bound-of *uniform*) -infinity) (setf (upper-bound-of *uniform*) +infinity) (setf (lower-bound-of *uniform*) saved-l) (setf (upper-bound-of *uniform*) saved-u) result ) (quail-error "DIST-UNIFORM: from = ~s must be less than to = ~s" from to) ) )
8,660
Common Lisp
.l
217
31.949309
107
0.558029
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
988c5d9b5066484c663e8ac4d35391a34a9a061ced274f6fbe24a063ba3cd360
33,804
[ -1 ]
33,805
geometric.lsp
rwoldford_Quail/source/probability/distributions/geometric.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; geometric.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; Ward Quinlan ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(geometric density-geometric quantile-geometric random-geometric dist-geometric))) (defclass geometric (negative-binomial) ((lower :accessor lower-of :initarg :lower :initform 1 :allocation :class)) (:documentation "The geometric distribution") ) ;;------------------------------------------------------------------ ;; Geometric Distribution (Geometric (p)) ;; ;; 1. Parameter: p = probability of success. ;; 2. Range: x - integer ;; 3. pdf: f(x) = p * (1 - p)^(x - 1) ;; 4. cdf: F(x) = 1 - (1 - p)^x ;; 5. r.v.: rv = ceil( ln u / ln (1 - p) ) where u ~ Unif[0,1] ;; 6. quantile: F(x) = q ;; x = ceil( ln q / ln (1 - p)) ;;----------------------------------------------------------------- (defmethod pdf-at ((distribution geometric) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (if (integerp x) (if (> x 0) (* (prob-success distribution) (expt (- 1 (prob-success distribution)) (- x 1))) 0) 0)) (defmethod (setf number-of-successes) (new-value (dist geometric)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (if (= new-value 1) (setf (lower-bound-of dist) new-value) (quail-error "Total number of successes for a geometric must be 1, ~ not ~s ." new-value))) (defmethod cdf-at ((distribution geometric) (x number)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - expt floor >) (let ((p (eref (prob-success distribution) 0)) (integer-x (floor x))) (if (> integer-x 0) (- 1 (expt (- 1 p) integer-x)) 0)))) (defmethod random-value ((distribution geometric) &optional (n 1)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (let ((result (ceiling (/ (log (random-uniform :n n)) (log (- 1 (prob-success distribution))))))) result)) (defmethod quantile-at ((distribution geometric) (q number) &key (start NIL)) (declare (ignore start) (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-CL-functions (+ * / - log ceiling <) (let ((p (eref (prob-success distribution) 0)) result) (if (< q p) (setf result 1) (setf result (ceiling (/ (log (- 1 q)) (log (- 1 p)))))) result))) (defvar *geometric* NIL "An instance of geometric representing the geometric ~ distribution. ~ This instance is used by the standard functions random-geometric, ~ quantile-geometric, etc.") (defun density-geometric (x &key (p 0.5)) "Returns the value of a geometric probability at x. ~ (:required ~ (:arg x The point at which to evaluate the density, or probability.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *geometric*)) (let ((saved-p (prob-success *geometric*)) result) (setf (prob-success *geometric*) p) (setf result (pdf-at *geometric* x)) (setf (prob-success *geometric*) saved-p) result ) ) (defun quantile-geometric (prop &key (p 0.5)) "Returns the value of the prop'th geometric quantilep. ~ (:required ~ (:arg prop The cumulative proportion at which to evaluate the quantile.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *geometric*)) (let ((saved-p (prob-success *geometric*)) result) (setf (prob-success *geometric*) p) (setf result (quantile-at *geometric* prop)) (setf (prob-success *geometric*) saved-p) result)) (defun random-geometric (&key (n 1) (p 0.5)) "Returns n pseudo-random values from the geometric. ~ (:key ~ (:arg n 1 The number of pseudo-random values to return.) ~ (:arg p 0.5 The probability of success at each trial.)) ~ (:returns A vector of n pseudo-random values.)" (declare (special *geometric*)) (let ((saved-p (prob-success *geometric*)) result) (setf (prob-success *geometric*) p) (setf result (random-value *geometric* n)) (setf (prob-success *geometric*) saved-p) result) ) (defun dist-geometric (x &key (p 0.5)) "Calculates and returns the value of the specified geometric distribution ~ function at x. ~ (i.e. prob(X <= x) .) ~ (:required ~ (:arg x Where to evaluate the cumulative distribution function.)) ~ (:key ~ (:arg p 0.5 The probability of success at each trial.))" (declare (special *geometric*)) (let ((saved-p (prob-success *geometric*)) result) (setf (prob-success *geometric*) p) (setf result (cdf-at *geometric* x)) (setf (prob-success *geometric*) saved-p) result))
5,795
Common Lisp
.l
150
31.366667
84
0.53149
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
25c7a42482579bc6d15d372b2e699117972059b2d889a5ce2d50f5d10ad93b1b
33,805
[ -1 ]
33,806
prob-methods.lsp
rwoldford_Quail/source/probability/distributions/prob-methods.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prob-methods.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1993 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Stat 440/840 students 1992. ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail) ;;; ;;; Methods ;;; (defmethod (setf scale-of) :around (new-value (dist T)) (if (<= new-value 0.0) (quail-error "~&(SETF SCALE-OF): Scale must be a positive number! Not: ~s." new-value) (call-next-method))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; pdf-at ;;; (defmethod pdf-at ((p-m T) x) (missing-method 'pdf-at p-m x)) (defmethod pdf-at :around ((distribution T) (value number)) (let ((l (lower-bound-of distribution)) (u (upper-bound-of distribution))) (cond ((or (< value l) (> value u)) 0) ((= l u value) 1) (T (call-next-method)))) ) (defmethod pdf-at :around ((distribution T) (value (eql NaN))) NaN) (defmethod pdf-at :around ((distribution T) (value (eql +infinity))) (let ((l (lower-bound-of distribution)) (u (upper-bound-of distribution))) (cond ((> value u) 0) ((= l u value) 1) (T (call-next-method))))) (defmethod pdf-at :around ((distribution T) (value (eql -infinity))) (let ((l (lower-bound-of distribution)) (u (upper-bound-of distribution))) (cond ((< value l) 0) ((= l u value) 1) (T (call-next-method))))) (defmethod-multi pdf-at :around ((distribution prob-measure) (value (sequence array dimensioned-ref-object))) "This method captures the behaviour of pdf-at for any ~ distribution when the values asked for are in a dimensioned-ref-object." (let ((result (make-dimensioned-result (dimensions-of value) value)) (n (number-of-elements value))) ; (loop for i from 0 to (- n 1) do (do ((i 0 (incf i))) ((= i n)) (setf (column-major-eref result i) (pdf-at distribution (column-major-eref value i)))) result)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; cdf-at ;;; (defmethod cdf-at ((p-m T) x) (missing-method 'cdf-at p-m x)) (defmethod cdf-at :around ((distribution T) (value number)) (let ((l (lower-bound-of distribution)) (u (upper-bound-of distribution))) (cond ((< value l) 0 ) ((>= value u) 1 ) (T (call-next-method) )))) (defmethod cdf-at :around ((distribution T) (value (eql NaN))) NaN) (defmethod cdf-at :around ((distribution T) (value (eql +infinity))) (declare (ignorable distribution value)) ;(declare (ignore distribution value)) ; 31JUL2023 1) (defmethod cdf-at :around ((distribution T) (value (eql -infinity))) (let ((l (lower-bound-of distribution)) (u (upper-bound-of distribution))) (cond ((< value l) 0 ) ((= value l u) 1 ) (T (call-next-method) )))) (defmethod-multi cdf-at :around ((distribution prob-measure) (value (sequence array dimensioned-ref-object))) "This method captures the behaviour of cdf-at for any ~ distribution when the values asked for are in a dimensioned-ref-object." (let ((result (make-dimensioned-result (dimensions-of value) value)) (n (number-of-elements value))) ; (loop for i from 0 to (- n 1) do (do ((i 0 (incf i))) ((= i n)) (setf (column-major-eref result i) (cdf-at distribution (column-major-eref value i)))) result)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quantile-at ;;; (defmethod quantile-at :around ((distribution T) (value number) &key (start NIL)) "Error checking on value being a probability." (declare (ignore start)) (cond ((or (< value 0) (> value 1)) (quail-error "~s is not a probability!" value)) ((= value 0) (lower-bound-of distribution)) ((= value 1) (upper-bound-of distribution)) (T (call-next-method)))) (defmethod quantile-at :around ((distribution T) (value (eql NaN)) &key (start NIL)) "Error checking on value being a probability." (declare (ignore start)) NaN) (defmethod quantile-at :around ((distribution T) (value (eql +infinity)) &key (start NIL)) "Error checking on value being a probability." (declare (ignore start)) (quail-error "Not a probability! ~s " value)) (defmethod quantile-at :around ((distribution T) (value (eql -infinity)) &key (start NIL)) "Error checking on value being a probability." (declare (ignore start)) (quail-error "Not a probability! ~s " value)) (defmethod-multi quantile-at :around ((distribution prob-measure) (value (sequence array dimensioned-ref-object)) &key start) "This method captures the behaviour of quantile-at for any ~ distribution when the values asked for are in a dimensioned-ref-object." (let ((result (make-dimensioned-result (dimensions-of value) value)) (n (number-of-elements value))) (if start (setf (column-major-eref result 0) (quantile-at distribution (column-major-eref value 0) :start start)) (setf (column-major-eref result 0) (quantile-at distribution (column-major-eref value 0)))) (if (> n 1) ; (loop for i from 1 to (- n 1) do (do ((i 1 (incf i))) ((= i n)) (setf (column-major-eref result i) (quantile-at distribution (column-major-eref value i) :start (column-major-eref result (- i 1)))))) result)) (defmethod quantile-at ((p-m t) (p t) &key (start NIL)) (declare (ignore start)) (missing-method 'quantile-at p-m p) ) ;; General random-value: return quantile-at (defmethod random-value ((p-m t) &optional (n 1)) "Uses a generalized probability integral transform from a uniform (0,1).~ Depends on quantile-at returning a sensible value." (quantile-at p-m (random-uniform :n n)) ) (defmethod probability ((distribution t) set) (missing-method 'probability distribution set)) (defmethod expectation ((p-m t) &optional g) (missing-method 'expectation p-m g))
6,973
Common Lisp
.l
173
33.433526
94
0.535153
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
58b725ae2eeb709f405b6e313543cd634be46cda8a872ab94740bc094200fb11
33,806
[ -1 ]
33,807
illinois.test
rwoldford_Quail/source/probability/distributions/Testing/illinois.test
;************************************************************* ; The following are test cases for the illinois method. ; I have used a standard function but have shown all the cases ; that will arise. ;************************************************************* (defun s1 (x) (+ (expt x 3) 4)) (illinois #'s1 -3 0) -1.5873982206072585 ;************************************************************ (defun s2 (x) (+ (expt x 3) 4)) (illinois #'s2 -3 -2) "you have given an unacceptable set of points" ;*********************************************************** (defun s3 (x) (+ (expt x 3) 4)) (illinois #'s3 -3 0 :tol .00000000000000001) -1.5874010519681991 ; -notice the increased accuracy ;********************************************************** (defun s4 (x) (+ (expt x 3) 4)) (illinois #'s4 -3 0 :tol .000000000000000001 :max-it 5) NIL ; -since it did not reach an answer with in 5 iterations ;*********************************************************
1,065
Common Lisp
.l
27
35.62963
66
0.400396
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
84e2f006f3e377dab5041e9c8aee6591868da87b1b5a5626b65161975dfe24a4
33,807
[ -1 ]
33,808
normal.test
rwoldford_Quail/source/probability/distributions/Testing/normal.test
;;test file for normal distribution (setf norm (make-instance 'normal)) ;standard normal (setf n (make-instance 'normal :location 5 :scale 2)) ;normal (5,4) ;so if x is from n, (x-5)/2 is a standard normal variate ;therefore, (pdf-at n x) should equal (1/2)*(pdf-at n ((x-5)/2)) (pdf-at n most-negative-fixnum) (* (/ 1 2) (pdf-at norm (/ (- most-negative-fixnum 5) 2))) (pdf-at n -10) (* (/ 1 2) (pdf-at norm (/ (- -10 5) 2))) (pdf-at n 0) (* (/ 1 2) (pdf-at norm (/ (- 0 5) 2))) (pdf-at n 5) (* (/ 1 2) (pdf-at norm (/ (- 5 5) 2))) (pdf-at n 7) (* (/ 1 2) (pdf-at norm (/ (- 7 5) 2))) (pdf-at n most-positive-fixnum) (* (/ 1 2) (pdf-at norm (/ (- most-positive-fixnum 5) 2))) ;(cdf-at n x) should equal (cdf-at norm ((x-5)/2)) (cdf-at n -5) (cdf-at norm (/ (- -5 5) 2)) (cdf-at n 1.71) (cdf-at norm (/ (- 1.71 5) 2)) (cdf-at n 8.92) (cdf-at norm (/ (- 8.92 5) 2)) (cdf-at n -11.5) (cdf-at norm (/ (- -11.5 5) 2)) (cdf-at n -12) (cdf-at norm (/ (- -12 5) 2)) ;(quantile-at n p) should equal ((quantile-at norm p)*2)+5 (quantile-at n .5) (setf x (quantile-at norm .5)) (+ (* x 2) 5) (quantile-at n .6) (setf x (quantile-at norm .6)) (+ (* x 2) 5) (quantile-at n .1) (setf x (quantile-at norm .1)) (+ (* x 2) 5) ;random values: (loop for i from 1 to 20 do (print (random-value n))) (loop for i from 1 to 20 do (print (random-value norm)))
1,496
Common Lisp
.l
47
27.468085
65
0.543307
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cb0de3a3bbd8bae2d0febb46fa55878f2e77d58562c22f94339ffe64c8138ed8
33,808
[ -1 ]
33,809
incomplete-gamma.test
rwoldford_Quail/source/probability/distributions/Testing/incomplete-gamma.test
******************************** TESTING FOR INCOMPLETE-GAMMA FUNCTION ********************************* ? (incomplete-gamma 1 1) 0.6321205580579482 ? (incomplete-gamma 1 3) 0.9502129316304365 ? (incomplete-gamma 1 8) 0.999664537372086 ? (incomplete-gamma 8 1) 1.0249196376664226E-5 ? (incomplete-gamma 8 7) 0.401286136021329 ? (incomplete-gamma 8 15) 0.9819978068761992 ? (incomplete-gamma 8 -1) 0.0 ? (incomplete-gamma 1 0) 0.0 ?
455
Common Lisp
.l
20
20.6
38
0.638889
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2d0e71687231594f9059f5334ef475149c2b93c7bd9d664c21ed437ec96fc9bf
33,809
[ -1 ]
33,810
test.lsp
rwoldford_Quail/source/probability/distributions/Testing/test.lsp
(load "common:start.lisp") ;; A quick and dirty test of most of the distributions. ;; for more detailed tests, see the 'distribution-name.test' files. ;; continuous: Ward ;; Discrete, FM: Joe ;; *********** Continuous Distribution ************************* (setf test-student (make-instance 'student :degrees 10)) (pdf-at test-student .5) (cdf-at test-student .5) ;;; both pts passed to illinois have fcn vals > or <(quantile-at test-student .7) (random-value test-student) (setf test-normal (make-instance 'normal)) (pdf-at test-normal .5) (cdf-at test-normal .5) ;; ERROR (quantile-at test-normal .5) (random-value test-normal) (setf test-cauchy (make-instance 'cauchy)) (pdf-at test-cauchy .5) (cdf-at test-cauchy .5) (quantile-at test-cauchy .5) (random-value test-cauchy) (setf test-gamma (make-instance 'gamma :alpha 1)) (pdf-at test-gamma .5) (cdf-at test-gamma .693148) (quantile-at test-gamma .5) (random-value test-gamma) (setf test-gamma (make-instance 'gamma :alpha .5)) (pdf-at test-gamma .5) (cdf-at test-gamma .22747) (quantile-at test-gamma .5) (random-value test-gamma) (setf test-chi-squared (make-instance 'chi-squared :degrees 10)) (pdf-at test-chi-squared .5) (cdf-at test-chi-squared .5) ;; returns two vals?? (quantile-at test-chi-squared .5) (random-value test-chi-squared) (setf test-exponential (make-instance 'exponential)) (pdf-at test-exponential .5) (cdf-at test-exponential .5) (quantile-at test-exponential .5) (random-value test-exponential) (setf test-uniform (make-instance 'uniform :upper-bound 10)) (pdf-at test-uniform .5) (cdf-at test-uniform .5) (quantile-at test-uniform .5) (random-value test-uniform) (setf test-beta (make-instance 'beta :shape1 1 :shape2 1)) (pdf-at test-beta .5) (cdf-at test-beta .5) (quantile-at test-beta .5) (random-value test-beta) (defclass gen (continuous) () ) (defmethod pdf-at ((distribution gen) x) (let ((N (make-instance 'normal))) (pdf-at N x))) (<- test-gen (make-instance 'gen )) (pdf-at test-gen .25) (cdf-at test-gen 0) (quantile-at test-gen .25) (random-value test-gen) (defclass gen2 (continuous) () ) (defmethod cdf-at ((distribution gen2) x) (let ((N (make-instance 'normal))) (cdf-at N x))) (<- test-gen2 (make-instance 'gen2 :lower-bound 0 :upper-bound .5)) (pdf-at test-gen2 4) (cdf-at test-gen2 4) (quantile-at test-gen2 .25) (random-value test-gen2) (diff-cdf test-beta .2 .8) ;; *********** Discrete Distributions************************* ;; ;;************************************************************ ;;;------------Discrete General Method----------------------------------------- (defclass gen1 (discrete) () ) (defmethod pdf-at ((distribution gen1) x) (/ (expt 0.5 x) (* (exp 0.5) (factorial x))) ) (<- test-gen1 (make-instance 'gen1 :lower-bound 0 :upper-bound 5)) (pdf-at test-gen1 3) (cdf-at test-gen1 1) (quantile-at test-gen1 0.3) (random-value test-gen1) (defclass gen2 (discrete) () ) (defmethod cdf-at ((distribution gen2) x) (cond ((< x 0) 0) ((= x 0) 0.1) ((= x 1) 0.4) ((= x 2) 0.5) ((= x 3) 0.75) ((= x 4) 0.8) ((>= x 5) 1)) ) (<- test-gen2 (make-instance 'gen2 :lower-bound 0 :upper-bound 5)) (pdf-at test-gen2 3) (cdf-at test-gen2 3) (quantile-at test-gen2 0.3) (random-value test-gen2) ;;;------------Binomial Distribution------------------------------------------- (setf test-binomial (make-instance 'binomial :upper-bound 10 :p .4)) ;Testing (pdf-at test-binomial 10) (cdf-at test-binomial 7) (quantile-at test-binomial .5) (random-value test-binomial) ;;;-------------------Bernoulli Distribution------------------ (setf distribution (make-instance 'bernoulli :p 0.5)) ;Testing (pdf-at distribution 0) (pdf-at distribution 1) (cdf-at distribution 0) (quantile-at distribution 0.7) (quantile-at distribution 0.3) (quantile-at distribution 0.5) (random-value distribution) ;;;------------Poisson Distribution--------------------------- (setf test-poisson (make-instance 'poisson :mean 5)) ;Testing (pdf-at test-poisson 7) (cdf-at test-poisson 7) (quantile-at test-poisson .5) (random-value test-poisson) ;;;-------------------Hypergeometric Distribution------------- (setf test-hyper (make-instance 'hypergeometric :N1 10 :N2 10 :n 10 :upper-bound 10)) ;Testing (pdf-at test-hyper 5) (cdf-at test-hyper 10) (quantile-at test-hyper 0.4) (random-value test-hyper) ;;;-------------------Finite-Discrete-Uniform----------------- (setf test-UD (make-instance 'finite-discrete-uniform :lower-bound 0 :upper-bound 10)) ;Testing (pdf-at test-UD 5) (cdf-at test-UD 4) (quantile-at test-UD 0.5) (random-value test-UD) ;;;------------------Negative-Binomial Distribution----------- (setf random-variable (make-instance 'negative-binomial :x 5 :p 0.5)) ;Testing (pdf-at random-variable 6) (cdf-at random-variable 6) (quantile-at random-variable 0.4) (random-value random-variable) ;;;-------------------Geometric Distribution------------------ (setf distribution (make-instance 'geometric :p 0.5)) ;Testing (pdf-at distribution 5) (cdf-at distribution 5) (quantile-at distribution 0.9) (random-value distribution) ;; *********** Finite Discrete Mixture************************ ;; ;;************************************************************ ; An instance for discrete variates (setf F1 (make-instance 'finite-discrete-uniform :lower-bound 0 :upper-bound 10)) (setf F2 (make-instance 'binomial :p 0.5)) ; An instance for continuous variates (setf F1 (make-instance 'chi-squared :degrees 5)) (setf F2 (make-instance 'exponential :mean 5)) (setf F3 (make-instance 'discrete-mixture :mixing-probs (list 0.3 0.7) :distributions (list F1 F2) :num 2)) ;Testing (pdf-at F3 1) (cdf-at F3 9) (Dquantile-at F3 0.5) (Cquantile-at F3 0.5) (random-value F3)
6,612
Common Lisp
.l
192
28.46875
82
0.578001
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
90830d7a418ec540fe4d2a676bc5e429387a4153b655a12658331eb348332042
33,810
[ -1 ]
33,811
exponential.test
rwoldford_Quail/source/probability/distributions/Testing/exponential.test
; **************************************** ; TEST DATA FOR THE EXPONENTIAL DISTRIBUTION ; **************************************** 7 > (setf C (make-instance 'Exponential :mean 2)) #<EXPONENTIAL #x1100211> 7 > (pdf-at C -1) 0 7 > (pdf-at C 0) 0.5 7 > (pdf-at C .5) 0.38940039153570244 7 > (pdf-at C .9) 0.31881407581088667 7 > (pdf-at C 100) 9.643749239819589E-23 7 > (cdf-at C -1) 0 7 > (cdf-at C 0) 0.0 7 > (cdf-at C .5) 0.22119921692859512 7 > (cdf-at C 1) 0.3934693402873666 7 > (cdf-at C 100) 1.0 8 > (quantile-at C .221199) 0.4999994429164182 8 > (quantile-at C .393469) 0.9999988779222762 8 > (quantile-at C -1) > Error: p must be between 0 and 1 > While executing: #<STANDARD-METHOD QUANTILE-AT (EXPONENTIAL T)> > Type Command-. to abort. See the RestartsÉ menu item for further choices. 9 > (quantile-at C 1) > Error: p must be between 0 and 1 > While executing: #<STANDARD-METHOD QUANTILE-AT (EXPONENTIAL T)> > Type Command-. to abort. See the RestartsÉ menu item for further choices. 11 > (let ((tot 0) (C)) (setf C (make-instance 'exponential :mean 2)) (loop for i from 1 to 100 by 1 do (setf tot (+ tot (random-value C)))) (/ tot 100)) 1.8852338212031738 11 > (let ((tot 0) (C)) (setf C (make-instance 'exponential :mean 10)) (loop for i from 1 to 100 by 1 do (setf tot (+ tot (random-value C)))) (/ tot 100)) 9.313751690058966
1,485
Common Lisp
.l
52
24.846154
66
0.598458
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0dd3f1294f62f6d42c1a75b890ef0f6079741f87beab9f6f6021fd913ae493fc
33,811
[ -1 ]
33,812
find-where-mixin.lsp
rwoldford_Quail/source/display-network/find-where-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; find-where-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(find-where-mixin ))) (defclass find-where-mixin () nil)
656
Common Lisp
.l
19
30.052632
87
0.321712
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9861473d0c9c85a3edbbac91d73ddbb625f6c12fa3022914d6999e947fb078de
33,812
[ -1 ]
33,814
linked-object.lsp
rwoldford_Quail/source/display-network/linked-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; linked-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(linked-object analysis-links-of back-analysis-links-of causal-links-of back-causal-links-of ))) (defclass linked-object () ((analysis-links :initform nil :accessor analysis-links-of :documentation "Forward pointer list for the analysis links.") (back-analysis-links :initform nil :accessor back-analysis-links-of :documentation "Backward pointer list for the analysis links.") (causal-links :initform nil :reader causal-links-of :documentation "Forward pointer list for the causal links.") (back-causal-links :initform nil :reader back-causal-links-of :documentation "Backward pointer list for the causal links.") (back-data-links :initform nil :reader back-data-links-of :documentation "Backward pointer list for Data links -- Not implemented yet.") (list-of-path-elements :initform nil :accessor list-of-path-elements-of :documentation "The path-elements associated with this object because the ~ object has been created by this path-element or the path ~ element has been created by this object.")) (:documentation "An object having several kinds of links.")) (defmethod remove-back-analysis-link ((self linked-object) linkee) "Removes Linkee from Back Analysis links of self." (setf (slot-value self 'back-analysis-links) (remove linkee (slot-value self 'back-analysis-links)))) (defmethod remove-forward-analysis-link ((self linked-object) linkee) "Removes Linkee from Analysis links of self." (setf (slot-value self 'analysis-links) (remove linkee (slot-value self 'analysis-links)))) (defmethod analysis-unlink ((self linked-object) linkee) "Break an existing analysis link between two linked-objects both directions." (remove-forward-analysis-link self linkee) (remove-back-analysis-link self linkee) (remove-forward-analysis-link linkee self) (remove-back-analysis-link linkee self)) (defmethod analysis-link ((self linked-object) linkee) "Establish an Analysis Link between two linked-objects." (add-forward-analysis-link self linkee) (add-back-analysis-link linkee self) linkee) (defmethod causal-link ((self linked-object) linkee) "Establish a Causal Link between two linked-Objects." (add-forward-causal-link self linkee) (add-back-causal-link linkee self) linkee) (defmethod add-forward-analysis-link ((self linked-object) linkee) "Adds linkee to Analysis-Links of self." (if (not (member linkee (slot-value self 'analysis-links) :test #'eq)) (push linkee (slot-value self 'analysis-links)))) (defmethod add-forward-causal-link ((self linked-object) linkee) "Adds linkee to Causal-Links of self." (if (not (member linkee (slot-value self 'causal-links) :test #'eq)) (push linkee (slot-value self 'causal-links)))) (defmethod add-back-analysis-link ((self linked-object) linkee) "Adds linkee to Back-Analysis-Links of self." (if (not (member linkee (slot-value self 'back-analysis-links) :test #'eq)) (push linkee (slot-value self 'back-analysis-links)))) (defmethod add-back-causal-link ((self linked-object) linkee) "Adds linkee to Back-Causal-Links of self." (if (not (member linkee (slot-value self 'back-causal-links) :test #'eq)) (push linkee (slot-value self 'back-causal-links))))
4,217
Common Lisp
.l
95
37.263158
120
0.630811
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1a4445aa1357f2ab9285c0d72415e83d0fdbbfc6d586dc3b51ec5c807ee94b74
33,814
[ -1 ]
33,815
example-extensions.lsp
rwoldford_Quail/source/display-network/example-extensions.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; example-extensions.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; this file is only an example to show how we can deal with more complex data ;;; ;;; class definition ;;; (defclass junk-extract (quail-object) ((a :initform (required-init ($! (quail-prompt-read "Initialization for A : "))) :initarg :a) (b :initform (required-init ($! (quail-prompt-read "Initialization for B : "))) :initarg :b) (sum :initform nil) (product :initform nil))) ;;; ;;; method definitions ;;; (defmethod after-init ((self junk-extract)) ;;; ;;; Specialization : Computes IVs of SELF ;;; (call-next-method) (setf (slot-value self 'sum) (+ (slot-value self 'a) (slot-value self 'b))) (setf (slot-value self 'product) (* (slot-value self 'a) (slot-value self 'b)))) (defmethod list-subs ((self junk-extract) &optional dont-signal-error) ;;; ;;; Returns the subs of SELF ;;; (let (quail-object-ivs result) (dolist (iv (class-slots (find-class 'quail-object))) (push (slot-value iv 'name) quail-object-ivs)) (dolist (iv (class-slots (class-of self))) (unless (member (setq iv (slot-value iv 'name)) quail-object-ivs) (push (cons (slot-value self iv) iv) result))) result))
2,215
Common Lisp
.l
60
25.783333
86
0.417577
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d15b9ab75a8efbcbe6c36bb5fd1149796e0dec3ff0b2192c8284b9d259e79b02
33,815
[ -1 ]
33,818
dated-object.lsp
rwoldford_Quail/source/display-network/dated-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; dated-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(dated-object creation-time-of creator-of))) (defclass dated-object () ((created :initform (get-universal-time) :reader creation-time-of :documentation "Internal format time of creation of object.") (creator :initform (user-name) :reader creator-of :documentation "Username of creator of object.") ) (:documentation "A useful mixin to record the date that the object was created and ~ the name of the user who created it."))
1,084
Common Lisp
.l
28
33.071429
109
0.460952
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2453860579eb4240b7d9634a4961af8c51497a2c57e353bb07288f7941f5bf9c
33,818
[ -1 ]
33,819
initable-object.lsp
rwoldford_Quail/source/display-network/initable-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; initable-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(initable-object spawning-expression-of ))) (defclass initable-object () ((spawning-expression :initform nil :accessor spawning-expression-of :documentation "The expression used to create this object.")) (:documentation "A useful mixin to record that permits various controls at ~ initialization time.")) (defmethod initialize-instance :after ((object initable-object) &key) "Examines a new instance making certain that all IV's which require ~ initialization are initialized then invoke the AfterInit ~ method." (init-ivs object) (after-init object) (set-anonymous-object object) (after-building object) object) (defmethod init-ivs ((self initable-object)) "Initialize all IVs for this new instance whose have a Required Init. ~ We recognize a Required init because the INITFORM has the value ~ (REQUIRED-INIT XXX) ~ If XXX is T then the method simply checks that an initial value was ~ supplied to the IV (via New-With-Values). If the value of the required ~ Init is a form or can be applied then EVAL the form or APPLY the function ~ to determine an initial value for the IV." (dolist (iv (list-required-inits (class-of self))) (if (eq (slot-value self (slot-value iv 'name)) (eval (slot-initform iv))) (let ((initializer (second (slot-initform iv)))) (setf (slot-value self (slot-value iv 'name)) (if (eq initializer t) (quail-error "Required Initialization missing for ~S" (slot-value iv 'name)) (if (listp initializer) (eval initializer) (if (functionp initializer) (funcall initializer self (slot-value iv 'name)) (quail-error "Can't initialize ~S with ~S" (slot-value iv 'name) initializer))))))))) (defmethod after-init ((self initable-object)) "A method which is invoked just after creation of a new instance. This ~ method only update Spawning Expression and return self. Specializations ~ however should call-next-method, do some work then return Self." (declare (special *quail-expression*)) ;; ;; The *quail-EXPRESSION* is updated in method CALL-METHOD-AND-LINK ;; if the new node is built using the menus of the browser. Otherwise, ;; it means that a command has been entered using the listener and the ;; *quail-EXPRESSION* can be obtained by consulting the last item of ;; the History list ;; (unless (and (boundp '*quail-expression*) (listp *quail-expression*)) (setq *quail-expression* (get-last-typed-command)) (or (listp *quail-expression*) (setq *quail-expression* (list *expression* nil)))) (setf (slot-value self 'spawning-expression) *quail-expression*) ;; we then reset *quail-EXPRESSION* for other uses (makunbound '*quail-expression*) self) (defmethod after-building ((self initable-object)) "This method updates the spawning-Expression and causal-links of objects ~ generated simultaneously with a main object." (let (link) (dolist (instance-variable (set-difference (class-slots (class-of self)) (list-required-inits (class-of self)))) (when (typep (setq link (slot-value self (slot-value instance-variable 'name))) 'linked-object) (causal-link self link) (setf (slot-value link 'spawning-expression) (slot-value self 'spawning-expression))))))
4,888
Common Lisp
.l
96
36.59375
104
0.526795
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3077f1c744949ee13142e4bc8aafaa8a1fc1906f1ddb130b0c9b6b14d3f672ea
33,819
[ -1 ]
33,820
network-view.lsp
rwoldford_Quail/source/display-network/network-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; network-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; class definition ;;; (defclass network-view (documented-object editable-object indexed-object quail-browser) ((left-button-items :initform '(("A short summary" #'short-summary "A short description of the kind of item selected.") ("Zoom" #'zoom "View this item in greater detail.")) :allocation :class :documentation "Menu items for Left Button selection. Value sent as message to ~ object or view." ) (left-title-items :initform '(("How this works" #'how-this-works "A Brief explanation as to how this kind of View works.") ("Buttoning Behavior" #'buttoning-behavior "How the mouse buttons work in this kind of View.") ("Manipulating the View" #'describe-contents "How to manipulate the items in this display.") ("Name this View" #'name-this-item "Give a unique name to this View.")) :allocation :class :documentation "Menu items that describe of this kind of View, and how to interact ~ with its display." ) (middle-title-items :initform '(("Widen" #'widen-view "Widen the View." :sub-items (("Widen the View" #'widen-view "Widen the view by including existing objects.") ("Add result of a evaluation" #'add-root "Prompt for a form to be evaluated; the result is added to this Map."))) ("Narrow" #'narrow-view "Narrow the view." :sub-items (("Narrow the View" #'narrow-view "Narrow the view by excluding the selected Objects.") ("Create a View" #'create-view "Compress part of the ~ current view into a smaller view."))) ("Nesting" nil "" :sub-items (("Explode a nested View" #'explode-a-nested-view "Explode a View nested in this display.") ("Return an exploded View" #'return-an-exploded-view "Return to the display a view that was exploded."))) ("Recompute" #'recompute "Recompute." :sub-items (("Recompute" #'recompute "Recompute the graph.") ("Recompute labels" #'recompute-labels "Recompute the labels.") ("In Place" #'recompute-in-place "Recompute keeping current ~ display in window.") ("Shape to hold" #'shape-to-hold "Make window large or ~ small enough to just hold graph.") ("Lattice/Tree" #'change-format "lattice/tree"))) ) :allocation :class) ;; ;; Controls format for laying out graph for GRAPHER (graph-format :initform *vertical-lattice*) ;; ;; A List of the views that contain this one (enveloping-views :initform nil) ;; ;; A list of views that are enveloped in by one (enveloped-views :initform nil) ;; ;; A list of the views that are exploded within this one (exploded-views :initform nil) ;; ;; Title passed to the GRAPHER and displayed in the Icons (title :initform "Network"))) ;;; ;;; method definitions ;;; (defmethod envelop-by ((self network-view) the-larger-view) "Records that the present view is nested within the-larger-view." (if (eq (class-of self) (class-of the-larger-view)) (progn (unless (member the-larger-view (slot-value self 'enveloping-views) :test #'eq) (push the-larger-view (slot-value self 'enveloping-views) )) (unless (member self (slot-value the-larger-view 'enveloped-views) :test #'eq) (push self (slot-value the-larger-view 'enveloped-views))) ) (quail-error "~S cannot envelop ~S" the-larger-view self))) (defmethod widen-view ((self network-view) &optional new-member dont-recompute-flg) "Add existing Objects to this View." (if new-member (progn (unless (member new-member (slot-value self 'starting-list) :test #'eq) (push new-member (slot-value self 'starting-list))) (if (typep new-member (class-name (class-of self))) (envelop-by new-member self)) (unless dont-recompute-flg (recompute self))) (do nil ((not (setq new-member ($! (prompt-read self "The new member : " ))))) (widen-view self new-member dont-recompute-flg)))) (defmethod error-cant-deduce-links-for ((self network-view) linked-object) ;;; (quail-error "Can't deduce the links for : ~S" linked-object)) (defmethod error-self-nested ((self network-view) nesting-view) "An error message to indicate that self is nested within Nesting-View." (quail-error "~S is already nested inside ~S" self nesting-view)) (defmethod zoom ((self network-view)) "Zooms in on the current the view displaying it in a new window." (browse self (starting-list-of self))) (defmethod the-view ((self network-view)) "Returns what can be seen in this view." (slot-value self 'starting-list)) (defmethod forward-links ((self network-view) linked-object) "This method must be specialized forspecializations of Network-View." (sub-class-responsibility self 'forward-links)) (defmethod backward-links ((self network-view) linked-object) "This method must be specialized for specializations of Network-View." (sub-class-responsibility self 'backward-links)) (defmethod narrow-view ((self network-view) &optional old-member dont-add-to-enveloping-views-flag dont-recompute-flag) "Remove old-member from this view. If dont-add-to-enveloping-views-flag is T ~ then do not add old-member to those views which envelop this one." (if old-member (progn (setf (slot-value self 'starting-list) (remove old-member (slot-value self 'starting-list))) ;; ;; Remove from this view. If ;; Dont-Add-To-Enveloping-Views-Flag is NIL the OLD-MEMBER ;; need to go in all views that enveloped this one. If ;; OLD-MEMBER is a view, some care must be taken to sort out ;; this envelopingViews as well ;; (if (typep old-member (class-name (class-of self))) (unenvelop-by old-member self)) (unless dont-add-to-enveloping-views-flag (dolist (bigger-view (slot-value self 'enveloping-views)) (widen-view bigger-view old-member))) (unless dont-recompute-flag (recompute self))) (do nil ((not (setq old-member ($! (prompt-read self "The member to be removed from this view : " ))))) (narrow-view self old-member dont-add-to-enveloping-views-flag dont-recompute-flag)))) (defmethod create-view ((self network-view)) "Creates a new view . Prompting for elements as necessary." (let ((the-new-view (make-instance (class-of self))) new-member) ;; ;; add the new view in SELF ;; (widen-view self the-new-view) (zoom the-new-view) ;; ;; Add members to the new view and delete them from SELF. The user ;; is prompt for New-member in the promptWindow ;; (do nil ((not (setq new-member ($! (prompt-read self "The new member : "))))) (widen-view the-new-view new-member t) (narrow-view self new-member t)) (recompute the-new-view))) (defmethod set-name ((self network-view) &optional name) ;;; ;;; Specialization : The Label must be removed from the Cache-label-list of ;;; every view SELF is represented in so that they are recompute next time ;;; those views are recompute ;;; (call-next-method) (dolist (super-view (slot-value self 'enveloping-views)) (let ((cached-label (assoc self (slot-value super-view 'label-cache) ))) (setf (slot-value super-view 'label-cache) (remove cached-label (slot-value super-view 'label-cache) ))))) (defmethod path-to ((self network-view) a-member) "Find all possible paths to A-Member of this view." (let ((result nil)) (if (typep a-member 'network-view) (dolist (item (the-view a-member)) (setq result (append result (path-to a-member item)))) (dolist (item (backward-links self a-member)) (push item result))) result)) (defmethod path-from ((self network-view) a-member) "Find all possible paths from A-Member of this view." (let ((result nil)) (if (typep a-member 'network-view) (dolist (item (the-view a-member)) (setq result (append result (path-from a-member item)))) (dolist (item (forward-links self a-member)) (push item result))) result)) (defmethod return-an-exploded-view ((self network-view) &optional the-exploded-view dont-recompute-flag) "Removes THE-EXPLODED-VIEW from Exploded-views list of self and adds it to ~ the view of self. The internals of THE-EXPLODED-VIEW are then removed from ~ the view of self." (if (slot-value self 'exploded-views) (progn (unless the-exploded-view (setq the-exploded-view ($! (select-in-menu (make-menu :items (let (result item) (dolist (view (slot-value self 'exploded-views)) (setq item (or (get-name view) view)) (unless (stringp item) (setq item (format nil "~a" item))) (push (list item view "") result)) result) :title "Exploded Views"))))) (if the-exploded-view (progn (dolist (item (the-view the-exploded-view)) (narrow-view self item t t)) (widen-view self the-exploded-view t) (setf (slot-value self 'exploded-views) (remove the-exploded-view (slot-value self 'exploded-views))) (unless dont-recompute-flag (recompute self))) (prompt-print self "Nothing selected."))) (prompt-print self "No Exploded views.")) the-exploded-view) (defmethod explode-a-nested-view ((self network-view) &optional the-selected-view dont-recompute-flag) "Removes the-selected-view from the view of self and adds the internals of ~ the-selected-view to the view of self . The-selected-view is kept on an ~ exploded-views list and can be returned to the view of self so that ~ explode-a-nested-view can be undone." (unless the-selected-view (setq the-selected-view ($! (prompt-read self "The view to be exploded : ")))) (if the-selected-view (if (typep the-selected-view 'network-view) (progn (narrow-view self the-selected-view t) (dolist (item (the-view the-selected-view)) (widen-view self item t)) (push the-selected-view (slot-value self 'exploded-views) ) (unless dont-recompute-flag (recompute self)) the-selected-view) (prompt-print self "Sorry, can't explode that kind of node.")))) (defmethod enveloped-by! ((self network-view) some-view) "Determines whether self is either contained in the view (!) of some-view ~ or in the view (!) of any view that envelops Some-view (at any level)." (if (in-view! some-view self) t (let ((answer nil)) (dolist (each-view (slot-value some-view 'enveloping-views)) (if answer (return answer) (setq answer (enveloped-by! self each-view)))) answer))) (defmethod in-view! ((self network-view) &optional the-object) "Determines whether the-object is in the-view of the immediate view or any ~ of the views that are contained in it at any level ~ If the-object is missing, it is assumed that this method is fired by menu ~ selection from within some enveloping view." (if the-object (if (in-view self the-object) t (let ((result nil)) (dolist (sub-views (slot-value self 'enveloped-views)) (when (and (null result) (in-view! sub-views the-object)) (return (setq result t)))) result)) (progn (setq the-object ($! (prompt-read self "Give the object to be found : ") )) (prompt-print self (if (in-view! self the-object) (format nil "Yes, ~S contains the ~S ~S." self (class-name (class-of the-object)) the-object) (format nil "No, ~S does not contain the ~S ~S." self (class-name (class-of the-object)) the-object)))))) (defmethod in-view ((self network-view) &optional the-object) "Determines whether the-object is in the-view of self. ~ If the-object is missing, it is assumed that this method is fired by menu ~ selection from within some enveloping view." (if the-object (if (member the-object (the-view self) :test #'eq) t nil) (progn (setq the-object ($! (prompt-read self "Give the object to be found : ") )) (prompt-print self (if (in-view self the-object) (format nil "Yes, ~S contains the ~S ~S." self (class-name (class-of the-object)) the-object) (format nil "No, ~S does not contain the ~S ~S." self (class-name (class-of the-object)) the-object)))))) (defmethod unenvelop-by ((self network-view) the-larger-view) "Records that the present view is no longer nested within the-larger-view." (setf (slot-value self 'enveloping-views) (remove the-larger-view (slot-value self 'enveloping-views))) (setf (slot-value the-larger-view 'enveloped-views) (remove self (slot-value the-larger-view 'enveloped-views)))) (defmethod get-links ((self network-view) object &key (reverse? nil)) "Returns a list of objects to which object should be linked in the display. ~ If reverse? is T then the direction is reversed, giving all the ~ objects which are forward linked to object." (let (the-subs) (if (typep object 'network-view) ;; ;; For a Sub-view, the subs is the union of the subs of the ;; items of the sub-view ;; (dolist (internal-object (the-view object)) (if reverse? (dolist (item (path-to self internal-object)) (when (in-view self item) (push item the-subs))) (dolist (item (path-from self internal-object)) (when (in-view self item) (push item the-subs))))) ;; ;; For a simple OBJECT (not a sub-view), the subs is the union ;; of the links (to or from) related to OBJECT and represented ;; in the view , and the sub-views which nodes have links (to ;; or from) with OBJECT. ;; (progn (if reverse? (dolist (item (path-to self object)) (when (in-view self item) (push item the-subs))) (dolist (item (path-from self object)) (when (in-view self item) (push item the-subs)))) (dolist (a-view (slot-value self 'enveloped-views)) (when (member object (get-links self a-view :reverse? (not reverse?))) (push a-view the-subs))))) the-subs)) (defmethod do-selected-command ((self network-view) command obj) "This specialization checks the result to see if it should be included in ~ this view." (let ((result (call-next-method))) (if (and result (typep result 'quail-object)) (widen-view self result))))
19,396
Common Lisp
.l
396
33.103535
93
0.514654
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5a4840eccb109617eb27fd332ba0567b2315679054b6429414b1849279218e45
33,820
[ -1 ]
33,821
body-menu.lsp
rwoldford_Quail/source/display-network/body-menu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; body-menu.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(body-menu middle-button-items-of generic-middle-menus-of))) (defclass body-menu () ((middle-button-items :initform nil :allocation :class :accessor middle-button-items-of :documentation "Items to be done if middle button is selected in Window. ~ All the methods concerning middle-button-items are in ~ body-menu.") (generic-middle-menus :initform nil :allocation :class :accessor generic-middle-menus-of :documentation "Offer up menus specific to the class of an item which has been ~ (middle) buttoned . A single class variable generic-middle-menus ~ caches as an association list the menus constructed for the various ~ classes." )) (:documentation "This mixin will replace the methods left-choice and ~ middle-choice of browser in quail-browser.")) (defmethod get-class-menu-items ((self body-menu) item-cv) "Build the list necessary to construct the middle menu of an object of the ~ body of the browser." (declare (special object)) (flet ((make-menu-list (list-methods &aux result) (do ((pair list-methods (cddr pair))) ((null pair)) (push (list (first pair) (first pair) "Slide over to see methods fitting this description." (append (list 'sub-items) (second pair))) result)) result)) (let ((local-methods (make-menu-list (classify-local-methods (class-of object)))) (inherited-methods (make-menu-list (classify-inherited-methods (class-of object) 'quail-object))) item-1 item-2) (setq item-1 (if local-methods (list "Class specific methods" nil "Slide over to see methods intended specifically for this class of object" (append (list 'sub-items) local-methods)) (list "Class specific methods" nil "Slide over to see methods intended specifically for this class of object"))) (setq item-2 (if inherited-methods (list "Other methods" nil "Slide over to see methods inherited by this object from more general classes" (append (list 'sub-items) inherited-methods)) (list "Other methods" nil "Slide over to see methods inherited by this object from more general classes"))) (list item-1 item-2)))) (defmethod build-middle-menu ((self body-menu) item-cv) "Method used to build a menu corresponding to a middle buttoning in the ~ body of the window. The difference with the standard CHOICE-MENU used for ~ the other menus is that the cached menu is sought in Generic-middle-menus ~ The menu is built by calling method GET-CLASS-MENU-ITEMS instead of ~ reading the class variable MIDDLE-BUTTON-ITEMS so that the menu is ~ automatically built according the methods defined for the class of the ~ selected node." (declare (special object)) (prog (items (menu (assoc (class-of object) (slot-value self 'generic-middle-menus)))) (if menu (setq menu (cdr menu))) ; if menu is not NIL it ; contains the cached menu (cond ((and (slot-value self 'cache-menu-p) (menu-p menu)) ; if we have a cached menu and ; want to use it (return menu)) ((not (listp (setq items ; if we don't use the cached ; menu and can't build a ; correct one NIL is returned (get-class-menu-items self item-cv)))) (return nil))) (setq menu ; otherwise we build a new menu (make-menu :items items :when-selected-fn #'browser-body-when-selected-fn :when-held-fn #'browser-when-held-fn :change-offset-fn t)) (and (slot-value self 'cache-menu-p) ; and cache it if necessary (let ((my-cached-menu (assoc (class-of object) (slot-value self 'generic-middle-menus)))) (if my-cached-menu (setf (cdr my-cached-menu) menu) (push (cons (class-of object) menu) (slot-value self 'generic-middle-menus))))) (return menu) ; we eventually display the new ; menu )) (defmethod middle-choice ((self body-menu)) "Make a selection from the menu build using Middle-Button-Items or ~ Shift-middle-Button-Items." (prog (menu) (setq menu (if (the-shift-key-p) (if (slot-value self 'shift-middle-button-items) (build-middle-menu self 'shift-middle-button-items) (if (understands self 'middle-shift-select) (prog nil (middle-shift-select self) (return nil)) (build-middle-menu self 'middle-button-items))) (build-middle-menu self 'middle-button-items))) (return (and menu (select-in-menu menu)))))
6,472
Common Lisp
.l
134
33.246269
106
0.507425
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
74823313480fe47612041f78f8c2ee24d1462db320ab110806589480f1ada7ee
33,821
[ -1 ]
33,822
memo.lsp
rwoldford_Quail/source/display-network/memo.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; memo.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (defclass memo (quail-object) nil) ;;; ;;; method definitions ;;; (defmethod zoom ((self memo)) "Specialized to edit notes." (read-notes self))
678
Common Lisp
.l
23
25.130435
80
0.320313
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
15275fc40db084c201c6e5cb6cb1e1de91350b75e892f95898b5a45ae2982d0f
33,822
[ -1 ]
33,823
tool-box-link.lsp
rwoldford_Quail/source/display-network/tool-box-link.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tool-box-link.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(tool-box-link-mixin ))) (defclass tool-box-link-mixin () ((link-list :initform nil)) (:documentation "Link manager of ToolBoxes.") ) (defmethod toolbox-link ((self tool-box-link-mixin) node linkee) "Establish a toolbox link between two quail-object-classes or toolboxes." (if (and (not (equal self node)) (not (equal linkee node)) (not (equal linkee self))) (progn (add-forward-toolbox-link self linkee node) (add-back-toolbox-link self node linkee)))) (defmethod toolbox-unlink ((self tool-box-link-mixin) node linkee) "Break an existing link between two quail-objectS or toolboxes - both ~ directions." (remove-forward-toolbox-link self node linkee) (remove-back-toolbox-link self node linkee) (remove-forward-toolbox-link self linkee node) (remove-back-toolbox-link self linkee node)) (defmethod remove-forward-toolbox-link ((self tool-box-link-mixin) node linkee) "Removes linkee from the forward toolbox links of node." (let ((links-of-node (find-link self node))) (if links-of-node (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (setq links-of-node (list (first links-of-node) (remove linkee (second links-of-node )) (third links-of-node))) (if (not (equal links-of-node (list node nil nil))) (push links-of-node (slot-value self 'link-list))))) )) (defmethod remove-back-toolbox-link ((self tool-box-link-mixin) node linkee) "Removes linkee from the back toolbox links of node." (let ((links-of-node (find-link self node))) (if links-of-node (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (setq links-of-node (list (first links-of-node) (second links-of-node) (remove linkee (third links-of-node )))) (if (not (equal links-of-node (list node nil nil))) (push links-of-node (slot-value self 'link-list))))) )) (defmethod make-link ((self tool-box-link-mixin)) "Add a new Toolbox link." (let ((node-1 (prompt-read self "Node to make link from : ")) (node-2 (prompt-read self "Node to make link to : "))) (setq node-1 (or ($! node-1 t) (find-class node-1))) (setq node-2 (or ($! node-2 t) (find-class node-2))) (if (and node-1 node-2) (progn (toolbox-link self node-2 node-1) (recompute self))))) (defmethod find-link ((self tool-box-link-mixin) node) "Return the element of link-list corresponding to node." (let (selection) (dolist (item (slot-value self 'link-list)) (if (eq (car item) node) (return (setq selection item)))) (if selection selection (list node nil nil)))) (defmethod break-link ((self tool-box-link-mixin)) "Break an existing Toolbox link." (let ((node-1 (prompt-read self "Node to break link from : ")) (node-2 (prompt-read self "Node to break link to : "))) (setq node-1 (or ($! node-1 t) (find-class node-1))) (setq node-2 (or ($! node-2 t) (find-class node-2))) (if (and node-1 node-2) (progn (toolbox-unlink self node-1 node-2) (recompute self))))) (defmethod add-forward-toolbox-link ((self tool-box-link-mixin) node linkee) "Adds Linkee to cadr of LinkList." (let ((links-of-node (find-link self node))) (if (not links-of-node) (push (list node nil (list linkee)) (slot-value self 'link-list)) (if (not (member linkee (second links-of-node))) (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (push linkee (second links-of-node)) (push links-of-node (slot-value self 'link-list))))) )) (defmethod add-back-toolbox-link ((self tool-box-link-mixin) node linkee) "Adds Linkee to CADDR of LinkList." (let ((links-of-node (find-link self node))) (if (not links-of-node) (push (list node nil (list linkee)) (slot-value self 'link-list)) (if (not (member linkee (third links-of-node))) (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (push linkee (third links-of-node)) (push links-of-node (slot-value self 'link-list))))) ))
6,305
Common Lisp
.l
129
32.860465
85
0.47422
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2999ba473e3302483edd237c09c8a68c85cb317406fc692db3d8541986b8ea7d
33,823
[ -1 ]
33,824
toolbox-network.lsp
rwoldford_Quail/source/display-network/toolbox-network.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; toolbox-network.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; class definition ;;; (defclass toolbox (find-where-mixin network-view tool-box-link-mixin) ((local-commands :initform '(#'sub-toolbox #'delete-from-browser #'name-this-item) :allocation :class) ;; ;; Definitions of the menus ;; (left-button-items :initform '(("Name a Sub toolbox" #'name-this-item "Give a name to this node (Only for Sub-toolboxes).") ("Summary" #'short-summary "A description of this kind of item and its use." :sub-items (("Short summary" #'short-summary "A short description of this kind of item and its use.") ("Long summary" #'long-summary "A longer description of this kind of item and its use."))) ("References" #'references "A list of references to sources in the literature on this item.") ("Internal Description" #'print-summary "The internal description of this item.") ("Zoom" #'zoom "View this item in greater detail.")) :accessor left-button-items-of :allocation :class) (middle-button-items :initform '(("Start Sub-Network from this node." #'sub-toolbox "Create another toolbox network display beginning at the selected node.")) :accessor middle-button-items-of :allocation :class) (left-title-items :initform '(("How this works" #'how-this-works "A brief explanation of how this browser works.") ("Buttoning behavior" #'buttoning-behavior "How the mouse buttons work in this browser.") ("Network description" #'describe-contents "A description of the kinds of items in the toolbox network." ) ("Name this toolbox" #'name-this-item "Give a unique name to this toolbox.")) :accessor left-title-items-of :allocation :class) (middle-title-items :initform '(("Widen" #'add-toolbox-node "Add a new toolbox node." :sub-items (("Add a toolbox node" #'add-toolbox-node "Add a new toolbox node.") ("Add a node and its specializations" #'add-toolbox-tree "Add a node and all its specializations."))) ("Narrow" #'narrow-view "Narrow the view" :sub-items (("Narrow the view" #'narrow-view "Narrow the view by excluding the selected objects.") ("Create a View" #'create-view "Compress part of the current view into a smaller toolbox."))) ("Links" nil "" :sub-items (("Break a link" #'break-link "Break an existing link between two nodes in the toolbox.") ("Make a link" #'make-link "Construct a directed link between two nodes in the toolbox."))) ("Recompute" #'recompute "Recompute." :sub-items (("Recompute" #'recompute "Recompute the graph.") ("Recompute labels" #'recompute-labels "Recompute the labels.") ("In Place" #'recompute-in-place "Recompute keeping current display in window.") ("Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph.") ("Lattice/Tree" #'change-format "Change format between lattice and tree"))) ("Save value" #'save-it "Save this toolbox.")) :accessor middle-title-items-of :allocation :class) ;; ;; Definitions of the icons ;; (icon :initform toolbox-icon :allocation :class) (mask :initform toolbox-icon-mask :allocation :class) (invert :initform nil :allocation :class) (title-reg :initform '(2 2 96 24) :allocation :class) (sub-view-icon :initform toolbox-map-icon :allocation :class) ;; ;; Other variables ;; (graph-format :initform *horiz-tree*) (cache-menu-p :initform t) (title :initform "A toolbox network"))) ;;; ;;; method definitions ;;; (defmethod create-view ((self toolbox)) "Creates a new view prompting for elements as necessary." (let ((the-new-view (make-instance (class-of self))) new-member) ;; ;; Put the new view in the old one ;; (widen-view self the-new-view) (browse the-new-view) ;; ;; Add members to the new view and delete them from the old one. ;; (do nil ((not (setq new-member (prompt-read self "The new member : ")))) ;; ;; Add new node in Sub-toolbox ;; (setq new-member (or ($! new-member t) (find-class new-member))) (widen-view the-new-view new-member t) ;; ;; Transporte the links of the new node inside the Sub-toolbox and ;; link the Sub-toolbox to the main toolbox ;; (dolist (link (forward-links self new-member)) (toolbox-link the-new-view link new-member) (toolbox-link self link the-new-view)) (dolist (link (backward-links self new-member)) (toolbox-link the-new-view new-member link) (toolbox-link self the-new-view link)) (narrow-view self new-member t)) (recompute the-new-view))) (defmethod backward-links ((self toolbox) linked-object) ;;; ;;; Return the BacktoolboxLink of the Linked-object ;;; (let ((links-of-nodes (find-link self linked-object))) (if links-of-nodes (third links-of-nodes) (error-cant-deduce-links-for self linked-object)))) (defmethod add-toolbox-tree ((self toolbox)) "Build the tree of classes issued from the given node and add them in the ~ toolbox." (let ((the-node-name (prompt-read self "Name of the new root toolbox node : "))) (add-toolbox-sub-tree self (find-class the-node-name)) (recompute self))) (defmethod add-toolbox-sub-tree ((self toolbox) root-node) "This method adds the sub-classes of a node on the toolbox map. It is ~ called iteratively." (dolist (link-name (class-direct-superclasses root-node)) (when (in-view! self link-name) (toolbox-link self root-node link-name))) (widen-view self root-node t) (let ((list-sub-nodes (class-direct-subclasses root-node))) (if list-sub-nodes (dolist (node list-sub-nodes) (add-toolbox-sub-tree self node))))) (defmethod narrow-view ((self toolbox) &optional old-member dont-add-to-enveloping-views-flag dont-recompute-flag) ;;; ;;; Remove Old-member from this view. if DONT-ADD-TO-ENVELOPING-VIEWS-FLAG is ;;; T then do not add OLD-MEMBER to those view which envelop this one. ;;; (if old-member (let (links-of-node) ;; ;; Remove the links with the node to remove ;; (when (setq links-of-node (find-link self old-member)) (dolist (link (backward-links self old-member)) (remove-forward-toolbox-link self link old-member)) (dolist (link (forward-links self old-member)) (remove-back-toolbox-link self link old-member)) (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list)))) ;; ;; Remove old-Member from browser ;; (setf (slot-value self 'starting-list) (remove old-member (slot-value self 'starting-list))) ;; ;; If DONT-ADD-TO-ENVELOPING-VIEWS-FLAG is NIL the Old-member ;; must be added in all views that enveloped self. ;; if Old-member is a view, some care must be taken to sort ;; out its enveloping-views as well. ;; (if (typep old-member (class-name (class-of self))) (unenvelop-by old-member self)) (unless dont-add-to-enveloping-views-flag (dolist (bigger-view (slot-value self 'enveloping-views)) (widen-view bigger-view old-member))) (unless dont-recompute-flag (recompute self))) (do nil ((not (setq old-member (prompt-read self "The member to be removed from this view" )))) (setq old-member (or ($! old-member t) (find-class old-member))) (narrow-view self old-member dont-add-to-enveloping-views-flag dont-recompute-flag)))) (defmethod name-this-item ((self toolbox) &optional object) "Specialization : method only available for sub toolboxes." (if (or (null object) (typep object 'network-view)) (call-next-method) (prompt-print self "Can't rename a quail class."))) (defmethod get-links ((self toolbox) object &key (reverse? NIL)) "Returns a list of objects to which object should be linked in the display. ~ If reverse? is T then the direction is reversed, giving all the ~ objects which are forward linked to object. ~ Specialization of NetworkView : Subtoolboxes are treated as normal nodes." (let (the-subs) (if reverse? ;; ;; Get all of the linked-objects first. (dolist (item (backward-links self object)) (when (in-view self item) (push item the-subs))) ;; ;; Get all of the linked-objects first. (dolist (item (forward-links self object)) (when (in-view self item) (push item the-subs)))) the-subs)) (defmethod forward-links ((self toolbox) linked-object) "Returns the toolbox links of the linked-object." (let ((links-of-node (find-link self linked-object))) (if links-of-node (second links-of-node) (error-cant-deduce-links-for self linked-object)))) (defmethod sub-toolbox-iteration ((self toolbox) new-toolbox node) "Add a node and its linked nodes shown on toolbox self in toolbox ~ new-toolbox." (widen-view new-toolbox node t) (if (member node (slot-value self 'bad-list)) (push node (slot-value new-toolbox 'bad-list))) (dolist (link (backward-links self node)) (toolbox-link new-toolbox node link)) (dolist (link (forward-links self node)) (when (in-view self link) (sub-toolbox-iteration self new-toolbox link)))) (defmethod sub-toolbox ((self toolbox) obj &rest rest) "Create a new toolbox with every specialization of Obj visualized on the ~ toolbox self." (let ((new-toolbox (make-instance (class-of self)))) (browse new-toolbox) (sub-toolbox-iteration self new-toolbox obj) (recompute new-toolbox))) (defmethod add-toolbox-node ((self toolbox)) "Add a node to the toolbox map, set its required variables and link it to ~ an existing node if desired." (let ((the-node-name (prompt-read self "Name of new toolbox node : ")) link-name) (setq the-node-name (or ($! the-node-name t) (find-class the-node-name))) (do nil ((not (setq link-name (prompt-read self "Link to node : ")))) (toolbox-link self the-node-name (or ($! link-name t) (find-class link-name)))) ;; (widen-view self the-node-name))) (defmethod widen-view ((self toolbox) &optional new-member dont-recompute-flag) ;;; ;;; add existing objects to this view ;;; (if new-member (progn (unless (member new-member (slot-value self 'starting-list)) (progn (push new-member (slot-value self 'starting-list)) (if (not (find-link self new-member)) (push (list new-member nil nil) (slot-value self 'link-list))))) (if (typep new-member (class-name (class-of self))) (envelop-by new-member self)) (unless dont-recompute-flag (recompute self))) (do nil ((not (and (setq new-member (prompt-read self "The new member : ")) (setq new-member (or ($! new-member t) (find-class new-member)))))) (widen-view self new-member dont-recompute-flag)))) (defmethod unread ((self toolbox) &optional object) ;;; ;;; Push the name of the class of OBJECT in the buffer but if the object is an ;;; Analysis Path, push the object itself ;;; (if (typep object 'network-view) (call-next-method) (push-in-buffer (class-name object))))
14,289
Common Lisp
.l
311
33.334405
84
0.551729
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
36c1f1ab6665c4b6240d52e3f8e0637199b63ecd78b01aceac28b7bb23578182
33,824
[ -1 ]
33,826
quail-browser.lsp
rwoldford_Quail/source/display-network/quail-browser.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-browser.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991-1992 ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; class definition ;;; (defclass quail-browser (title-bar-mixin named-object prompt-mixin browser) ;; ;; The order of inheritance is important : the mixins must be before ;; BROWSER in the list so that quail-BROWSER inherits methods and Class ;; variables of the mixins in priority on those of BROWSER ;; ((local-commands :initform '(#'box-node #'name-this-item #'how-this-works #'buttoning-behavior #'describe-contents) :allocation :class) (icon :initform view-icon :allocation :class) ; Default value of icon (mask :initform nil :allocation :class) ; default value of mask of icon (icon-font :initform nil :allocation :class) ; Font used in the Browser (icon-font-description :initform '(helvetica 7 medium) :allocation :class) (title-reg :initform '(0 31 77 10) :allocation :class) ; Default title region of Icon (invert :initform t :allocation :class) ; By default, print title of ; icon on Black background (sub-view-icon :initform view-icon :allocation :class) ; icon to appear inside a Map (cache-menu-p :initform t) ; menu is cached if T (title :initform "quail Browser") ; Title passed to GRAPHER ; package and displayed in the ; Icons )) ;;; ;;; function definitions ;;; (defun format-for-eval (expression) "Format an expression containing objects so that it can be evaluated by EVAL. ~ The problem is that the objects must be replaced by (QUOTE object) inside ~ the expression to eval if they are not symbols the evaluable expression ~ is returned." (mapcar #'(lambda (x) (cond ((symbolp x) x) ((listp x) (format-for-eval x)) (t (list 'quote x)))) expression)) (defun extract-objects (list &aux extracted) "Extract a list of objects from a list." (dolist (element list) (if (listp element) (setf extracted (append extracted (extract-objects element))) (if (object-p element) (push element extracted)))) extracted) (defmacro with-link (expression-to-eval) `(let ((result (eval (format-for-eval ',expression-to-eval))) list-link) ;; Link with Obj and all other arguments (when (object-p result) (setf list-link (extract-objects (slot-value result 'spawning-expression))) (if (understands result 'causal-link t) (dolist (arg list-link) (when (understands arg 'causal-link result) (causal-link arg result)))) (if (understands result 'analysis-link t) (dolist (arg list-link) (when (understands arg 'analysis-link result) (analysis-link arg result))))) result)) (defmacro from-map (expression) "When a function is called by menu selection, its arguments are not ~ bound because we only know the node it is applied from and the function ~ may need other arguments. This macro ask the user values for the other ~ compulsory arguments. These compulsory arguments are those declared when ~ the user ask a function to be callable by menu, using add-function-in-menu." `(let ((classification (get-mc (first ,expression))) (length (length ,expression)) arg-in-exp) (when classification (do ((arg (fourth classification) (cdr arg)) (rank 1 (+ 1 rank))) ((null arg)) (unless (nth rank ,expression) (if (>= rank length) (setf ,expression (append ,expression (list (requires-variable (first arg))))) (setf (nth rank ,expression) (requires-variable (first arg))))))))) ;;; ;;; method definitions ;;; (defmethod new-item ((self quail-browser) &optional new-item) (if new-item ($! new-item) (set-name (prompt-eval self "quail Expression") (prompt-read self "Name to be given to this quail Expression" )))) (defmethod name-this-item ((self quail-browser) &optional object) "Name the Object and display the new name in the Browser or the browser ~ itself if no object." (if object (progn (set-name object) (let ((cached-label (assoc object (slot-value self 'label-cache)))) (setf (slot-value self 'label-cache) (remove cached-label (slot-value self 'label-cache))) (get-display-label self object))) (set-name self)) (recompute self)) (defmethod left-shift-select ((self quail-browser)) (declare (special object)) (unread self object)) (defmethod middle-shift-select ((self quail-browser)) (declare (special object)) (unread self object)) (defmethod title-left-shift-select ((self quail-browser)) ;;; ;;; Specialization ;;; (unread self)) (defmethod title-middle-shift-select ((self quail-browser)) ;;; ;;; Specialization ;;; (unread self)) (defmethod get-label ((self quail-browser) object) "Get a label for an object to be displayed in the browser." (if (understands object 'descriptive-label) (descriptive-label object) (let ((name (get-name object))) (if name (concatenate 'string (string name) " " (string (class-name (class-of object)))) (class-name (class-of object)))))) (defmethod get-links ((self quail-browser) object &key (reverse? nil)) ;;; ;;; We will take care of links in class Network view ;;; nil) (defmethod show-browser ((self quail-browser) &optional browse-list window-or-title good-list) (call-next-method) ;; ;; We must install our Shrink method ;; (setf (icon-of self) #'quail-icon-fn) self) (defmethod icon-title ((self quail-browser)) ;; ;; Returns the title for this View ;; (if (slot-value self 'name) (string (slot-value self 'name)) (slot-value self 'title))) (defmethod unread ((self quail-browser) &optional object) (if object (push-in-buffer (access-expression object)) (push-in-buffer (access-expression self)))) (defmethod set-name ((self quail-browser) &optional name) ;; Specialization ;; For quail-browseRS, we must update the slot-value TITLE when the name is ;; changed ;; (call-next-method) (if (slot-value self 'name) (setf (slot-value self 'title) (slot-value self 'name)))) (defmethod call-method-and-link ((self quail-browser) expression-to-eval) "Given a selector obtained by selection in a menu, this method build the ~ expression to call macro with-link in order to update Links and then call ~ the macro . this method is Called by DO-SELECTED-COMMAND ~ Updates *quail-EXPRESSION* in order to construct the spawning expression ~ of the result later." (declare (special *quail-expression*)) (loop (if (first (last expression-to-eval)) ; remove the nils at the end (return)) ; of expression-to-eval (setf expression-to-eval (butlast expression-to-eval))) (from-map expression-to-eval) ; complete the arguments (setf *quail-expression* (setf expression-to-eval (list 'with-link expression-to-eval))) (eval expression-to-eval)) (defmethod do-selected-command ((self quail-browser) command obj) "Does the selected command or forwards it to the object. ~ The value of the command is returned." ;;; and the macros can be executed as well as the functions or ;;; methods ;;; (prog (args) (if (null command) (return nil)) (if (listp command) (progn (setf args (cdr command)) (setf command (car command)))) (if (listp obj) ;; Take care of being passed in a dummy node from browser in ;; Lattice mode Dummy nodes are indicated by having the ;; object in a list (setf obj (car obj))) (push obj args) (unless (and (not (member command (slot-value self 'local-commands))) (understands obj command)) (push self args)) (push command args) (return (call-method-and-link self args))))
9,972
Common Lisp
.l
234
31.205128
98
0.551168
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b3c3c24d63a88ec9e2a0b0ae198a918bd9b1a402592be5eb47eb46a16a47fae0
33,826
[ -1 ]
33,827
indexed-object.lsp
rwoldford_Quail/source/display-network/indexed-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; indexed-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(indexed-object ))) (defclass indexed-object () () (:documentation "Adds two methods inherited-methods-classification and ~ local-methods-classification which produce indexes to the methods ~ available in this class.")) (defmethod get-local-methods-classification ((self indexed-object)) (classify-local-methods (class-of self))) (defmethod get-inherited-methods-classification ((self indexed-object)) (classify-inherited-methods (class-of self) 'quail-object))
1,122
Common Lisp
.l
29
33.241379
85
0.487465
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9f727785dae18ced9e4473cc22f5a50e465856bd8787b0a95aa5e6b3258087fe
33,827
[ -1 ]
33,828
zoom-mixin.lsp
rwoldford_Quail/source/display-network/zoom-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; zoom-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(zoom-mixin zoom))) ;;; ;;; class definitions ;;; (defclass zoom-mixin () ((zoom-window-cache :initform nil :accessor zoom-window-cache-of))) (defmethod zoom ((self zoom-mixin)) "Zooms in on the current object by displaying it and its sub-structures in ~ a new view. ~ The browser is cached in self and self is deposited in the browser. This ~ circular structure is removed by the specialized destroy methods for ~ quail-objects and microscopic-view." (if (and (slot-value self 'zoom-window-cache) (understands (slot-value self 'zoom-window-cache) 'zoom)) (zoom (slot-value self 'zoom-window-cache)) (let ((zoomed-view (make-instance 'microscopic-view))) (setf (slot-value zoomed-view 'zoomed-object) self) (setf (slot-value self 'zoom-window-cache) zoomed-view) (zoom zoomed-view))))
1,601
Common Lisp
.l
39
32.666667
84
0.479896
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4d20dd2261182a1ea5d3386ccacbb1027126e4d65586372176097865d10ea509
33,828
[ -1 ]
33,829
analysis-path.lsp
rwoldford_Quail/source/display-network/analysis-path.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; analysis-path.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) ;;; ;;; class definitions ;;; (defclass analysis-path (network-view) ((contents-description :initform "Building an Analysis Path : Ask your quail Dealer how to do it." :allocation :class) (how-this-works :initform "Only practice can teach you that." :allocation :class) (middle-button-items :initform '(("Show location in Path" #'show-location-in-path "Flashes the node on the general browser.")) :allocation :class) (left-title-items :initform '(("How this works" #'how-this-works "A Brief explanation as to how this browser works.") ("Buttoning behavior" #'buttoning-behavior "How the mouse buttons work in this browser.") ("Building Analysis Path" #'describe-contents "How to build an Analysis Path.") ("Name this Analysis Path" #'name-this-item "Give a Unique name to this ToolBox Map.")) :allocation :class) (middle-title-items :initform '(("Widen" #'widen-view "Add a new node in the Analysis path." :sub-items (("Widen the Analysis Path" #'widen-view "Add a new node in the Analysis path.") ("Add a parameter" #'add-parameter "Add a new parameter to the Analysis path."))) ("Narrow" #'narrow-view "Removes a node from the Analysis path." :sub-items (("Narrow the Analysis path" #'narrow-view "Removes a node from the Analysis path.") ("Create a View" #'create-view "Order the Analysis Path to create a sub view when executed."))) ("Links" nil "" :sub-items (("Break a link" #'break-link "Break an existing link between two nodes in the map.") ("Make a link" #'make-link "Build an directed Analysis link between two nodes in the Analysis path."))) ("Recompute" #'recompute "Recompute." :sub-items (("Recompute" #'recompute "Recompute the graph.") ("Recompute labels" #'recompute-labels "Recompute the labels.") ("In Place" #'recompute-in-place "Recompute keeping current display in window.") ("Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph.") ("Lattice/Tree" #'change-format "Change format between lattice and tree"))) ("Inspecting" nil "" :sub-items (("Browse all operations" #'global-browser "Browse all requested operations in order to achieve the Analysis path.") ("Browse the parameters" #'parameter-browser "Browse the parameters required by the Analysis path.") ("General causal browser" #'general-browser "Browse the operations and the parameters using causal links.") ("General Analysis browser" #'general-analysis-browser "Browse the operations and the parameters using Analysis links.") ("Recompute" #'recompute "Recomputes the graph.")))) :allocation :class) ;; ;; Definitions of icons ;; (icon :initform analysis-path-icon :allocation :class) (mask :initform analysis-path-icon-mask :allocation :class) (invert :initform nil :allocation :class) (title-reg :initform '(2 2 66 20) :allocation :class) (sub-view-icon :initform analysis-path-map-icon :allocation :class) ;; ;; Other variables ;; (list-of-elements :initform nil) ; All the nodes of the Analysis ; path (visible or not) (cache-menu-p :initform t) (title :initform "An Analysis Path"))) (defclass path-element (quail-object) ((title :initform nil :documentation "For Path Elements of views, name of the view.") (class-of-element :initform nil :documentation "Class of the node that can be constructed by this Path element.") (needed-arguments :initform nil :documentation "Arguments needed to compute the spawning expression.") (local-data :initform nil :documentation "IVs of the corresponding analysis node that have a corresponding path-element in the Analysis path.") )) ;;; ;;; function definitions ;;; (defun tree-member (element tree) "Returns NIL unless element is a member of tree or of a sub-tree of tree." (or (member element tree) (dolist (sub-tree tree nil) (and (listp sub-tree) (tree-member element sub-tree) (return t))))) (defun translate-parameter (list-to-translate path) "Translate a list of arguments to a list of corresponding path-elements." (let (translate result) (dolist (item list-to-translate) (push (cond ((not (object-p item)) item) ((typep item 'network-view) path) ((setf translate (intersection (slot-value path 'list-of-elements) (slot-value item 'list-of-path-elements))) (first translate))) result)) (nreverse result))) ;;; ;;; method definitions ;;; (defmethod update-links ((self path-element) from to) "Build the symetric links for a path-element." (dolist (link (slot-value self from)) (unless (member self (slot-value link to)) (push self (slot-value link to))))) (defmethod replace-in-equivalence ((self path-element) value) "Replaces in equivalence table of the analysis-path the previous value ~ equivalent to path-element (which is NIL if everything works OK) by value ~ equivalence is a special variable defined in method apply-analysis-path." (declare (special equivalence)) (nsubst (cons self value) (assoc self equivalence) equivalence) (dolist (item (slot-value self 'local-data)) (replace-in-equivalence (second item) (slot-value value (first item))))) (defmethod remove-other-elements ((self path-element) path) ;;; (setf (slot-value path 'list-of-elements) (remove self (slot-value path 'list-of-elements))) (dolist (link (slot-value self 'back-causal-links)) (when (and (not (member link (slot-value path 'starting-list))) (equal (slot-value link 'causal-links) (list self))) (remove-other-elements link path)))) (defmethod parent-nodes ((self quail-object)) "Return the list of parent nodes of self i.e. the back-causal-links for the ~ nodes which have some and the required inits for other ones." (or (slot-value self 'back-causal-links) (let (data list-data) (dolist (item (list-required-inits (class-of self))) (when (object-p (setf data (slot-value self (slot-value item 'name)))) (push data list-data))) list-data))) (defmethod build-make-instance-expression ((self path-element) path template) "If a node has been built using add-analysis-node, we build a path-element ~ with a make-instance spawning-expression and the required arguments as ~ parameters." (let (value result) (dolist (slot (list-required-inits (class-of template))) (setf value (slot-value template (slot-value slot 'name))) (push (first (translate-parameter (list value) path)) result) (push (slot-initarg slot) result)) (push (list 'quote (class-name (class-of template))) result) (push 'make-instance result) (list 'with-link result))) (defmethod compute-spawning-expression ((self path-element) path) "Build a spawning-expression to create the node corresponding to a ~ path-element when an analysis path is applied. ~ This method returns three values : the first one is T or NIL depending on the ~ validity of the spawning-expression computed (value is T if some arguments ~ are unknown in the spawning-expression); the second value is the ~ spawning-expression if this one is correct NIL otherwise; the third is ~ the result when the spawning expression is applied. ~ Special variables are defined in method apply-analysis-path." (let ((new-spawning-expression (copy-tree (slot-value self 'spawning-expression))) evaluable-expression) (if ;compute the new spawning expression (labels ((repl (expression &aux the-arg) (declare (special list-of-elements equivalence)) (do ((arg expression (cdr arg))) ((null arg) t) (cond ((listp (setf the-arg (first arg))) (unless (repl (first arg)) (return nil))) ((object-p the-arg) (cond ((member the-arg list-of-elements) (unless (setf (first arg) (cdr (assoc the-arg equivalence))) (return nil))) ((typep the-arg 'analysis-path) (setf (first arg) (cdr (assoc path equivalence))) (t (quail-error "Unknown argument in expression to eval : ~s" the-arg))))))))) (repl new-spawning-expression)) ;; ;; The spawning-expression computed has the same form of that of the ;; template but is not directly evaluable. we save it to put in ;; spawning-expression because this is a simple form and we then ;; transform it in order to have an evaluable one ;; The link in an analysis path are not updated by with-link but by the ;; method Apply-Analysis-path itself. So we just consider the rest of the ;; expression ;; (progn (setf evaluable-expression (if (eql (first new-spawning-expression) 'with-link) (second new-spawning-expression) new-spawning-expression)) ;; ;; The transformation to obtain an evaluable expression given a ;; simple spawning-expression is obtain by applying ;; Form-for-eval. ;; We can finally return the 3 values of the method ;; (values nil new-spawning-expression (eval (format-for-eval evaluable-expression )))) ;; ;; Else, if some arguments are unknown ;; (values t nil nil)))) (defmethod add-other-elements ((self quail-object) path) "Add recursively the nodes which are needed to construct a given node self ~ in the analysis-path. ~ We must first create the path-elements parents of some of the new-member ~ if not already created otherwise just add them in the list-of-elements." (declare (special list-of-elements)) (dolist (node (parent-nodes self)) (let ((path-node (intersection (slot-value node 'list-of-path-elements) list-of-elements))) (cond (path-node (unless (member (first path-node) (slot-value path 'list-of-elements)) (push (first path-node) (slot-value path 'list-of-elements)))) ((parent-nodes node) (add-other-elements node path)) (t (add-parameter path node))))) ;; ;; Now we can create the Path-element for new-member ;; (if (not (intersection (slot-value self 'list-of-path-elements) list-of-elements)) (let ((new-node (make-instance 'path-element))) (update-path-element new-node path self) (push new-node (slot-value path 'list-of-elements)) (push new-node list-of-elements) (push new-node (slot-value self 'list-of-path-elements))) ;; ;; or only update List-of-elements of the Analysis-path if the ;; new-member already exists as a path-element ;; (let ((new-node (first (intersection (slot-value self 'list-of-path-elements) list-of-elements)))) (when new-node (push new-node (slot-value path 'list-of-elements)))))) (defmethod add-parents-node ((self path-element) the-new-view) "Copy the parents nodes of a new member in the list-of-elements of ~ the-new-view. This is used by create-view so that the new ~ analysis-path created as a ~ sub-view can be applied separately to its parent. In order to do that, it ~ must contain every path-element needed to build the nodes selected by the ~ user." (dolist (node (append (slot-value self 'back-causal-links) (slot-value self 'needed-arguments))) (unless (or (null node) (typep node 'analysis-path) (member node (slot-value the-new-view 'list-of-elements) )) (push node (slot-value the-new-view 'list-of-elements)) (add-parents-node node the-new-view)))) (defmethod compute-list-of-elements ((self analysis-path)) "Returns a list of all the Path-elements needed to complete an ~ analysis-path, which is the collection of path-elements of the ~ analysis-path and every enveloped analysis-path." (declare (special list-of-elements)) (dolist (element (slot-value self 'list-of-elements)) (when element (push element list-of-elements))) (dolist (sub-analysis-path (slot-value self 'enveloped-views)) (compute-list-of-elements sub-analysis-path)) list-of-elements) (defmethod zoom ((self path-element)) (describe self)) (defmethod update-path-element ((self path-element) path template) "Initializes the path element corresponding to the analysis node template ~ in the analysis path." (setf (slot-value self 'spawning-expression) (if (tree-member 'add-analysis-node (slot-value template 'spawning-expression)) (build-make-instance-expression self path template) (translate-parameter (slot-value template 'spawning-expression) path))) ;; (dolist (arg (slot-value self 'spawning-expression)) (when (object-p arg) (push arg (slot-value self 'needed-arguments)))) (dolist (arg (list-required-inits (class-of template))) (when (and (setf arg (slot-value template (slot-value arg 'name))) (typep (setf arg (car (translate-parameter (list arg) path))) 'path-element) (not (member arg (slot-value self 'needed-arguments)))) (push arg (slot-value self 'needed-arguments)))) ;; (setf (slot-value self 'class-of-element) (class-of template)) ;; (update-links-path-element self path template) ;; (if (understands template 'list-subs t) (let (data) (dolist (item (list-subs template t)) (when (and (object-p (setf data (car item))) (object-p (setf data (car (translate-parameter (list data) path))))) (push (list (cdr item) data) (slot-value self 'local-data)))))) ;; ;; Convert local data of parent Elements in Path-Elements ;; (let (data) (dolist (node (slot-value template 'back-causal-links)) (when (object-p node) (dolist (item (class-slots (class-of node))) (when (and (setf item (slot-value item 'name)) (eq (setf data (slot-value node item)) template)) (push (list item self) (slot-value (car (translate-parameter (list node) path)) 'local-data)))))))) (defmethod update-links-path-element ((self path-element) path template) "Update links of path-element by transposing links of template on it." (dolist (type-link '((analysis-links . back-analysis-links) (back-analysis-links . analysis-links) (causal-links . back-causal-links) (back-causal-links . causal-links))) (setf (slot-value self (first type-link)) nil) (dolist (link (translate-parameter (slot-value template (first type-link)) path)) (when (object-p link) (push link (slot-value self (first type-link))))) (update-links self (first type-link) (cdr type-link)))) (defmethod descriptive-label ((self path-element)) ;;; ;;; Specialization ;;; (if (class-p (slot-value self 'class-of-element)) (class-name (slot-value self 'class-of-element)) (slot-value self 'title))) (defmethod widen-view ((self analysis-path) &optional (new-member nil) (dont-recompute-flg nil)) ;;; Add existing Objects to this View ;;; (declare (special list-of-elements)) (let (list-member) (cond ((and new-member (listp new-member)) (setf list-member new-member)) (new-member (setf list-member (list new-member))) (t (do nil ((not (setf new-member ($! (prompt-read self "The new member : "))))) (push new-member list-member)))) ;; ;; List-member is a list of new members to add in the Analysis path ;; ;; ;; first add the parameters in the path if some are selected by user ;; (dolist (member list-member) (when (and (not (eq (class-of member) (find-class 'path-element))) (member 'add-root (slot-value member 'spawning-expression))) (add-parameter self member t))) ;; ;; then add the other members ;; (dolist (member list-member) (let (new-node) ;; New-node is the associated Path-Element of a given member (cond ;; ;; If Member is a Path element, that means that we want ;; an invisible path-element of the path to become ;; visible so New-node = Member ;; If Member is an Analysis path, we don't build a new ;; Path-element, we just add it in the starting-list. ;; New-node = Member ;; ((member (class-of member) (list (find-class 'path-element) (class-of self))) (setf new-node member)) ;; ;; If Member is a view, we add all its elements in a ;; sub-path and the sub-path in the AnalysisPath ;; ((typep member 'network-view) (let ((sub-path (make-instance 'analysis-path))) (zoom sub-path) (widen-view sub-path (slot-value member 'starting-list)) (widen-view self sub-path))) ;; ;; If the selected node has been built by an Analysis ;; path, New-node is the Path-Element used to build it. ;; We only must update this Path-Element in case the ;; links have been changed ;; ((setf new-node (first (intersection (slot-value member ' list-of-path-elements ) (slot-value self 'list-of-elements)))) (update-links-path-element new-node self member)) ;; ;; Otherwise we must create and update a new Path element ;; (t (setf list-of-elements nil) (compute-list-of-elements self) (add-other-elements member self) (setf new-node (first (intersection (slot-value member ' list-of-path-elements ) (slot-value self 'list-of-elements)) )))) ;; ;; Now we have New-node. We just have to add it in the starting ;; list and in list-of-elements ;; (when new-node (unless (member new-node (slot-value self 'list-of-elements)) (push new-node (slot-value self 'list-of-elements))) (unless (member new-node (slot-value self 'starting-list)) (push new-node (slot-value self 'starting-list))) (if (eq (class-of new-node) (class-of self)) (envelop-by new-node self))) ;; ;; Recompute if necessary ;; (unless dont-recompute-flg (recompute self)))))) (defmethod show-location-in-path ((self analysis-path) object) "Flashes the selected node on the general browser of the analysis path." (general-browser self) (flash-node self object)) (defmethod print-summary ((self analysis-path)) (print-summary (class-of self))) (defmethod narrow-view ((self analysis-path) &optional old-member dont-add-to-enveloping-views-flag dont-recompute-flag) ;;; ;;; Remove OldMember from this view. If Dont-Add-To-Enveloping-Views-Flag is T ;;; then do not add OldMember to those views which envelop this one ;;; (call-next-method) ;; ;; Updating of List-of-elements : ;; Old-member and its parents are removed from List-of-Elements if they ;; are not necessary for building other nodes of the Analysis-Path ;; (if (and old-member (typep old-member 'path-element)) (if (slot-exists-p old-member 'causal-links) (unless (slot-value old-member 'causal-links) (remove-other-elements old-member self)) (error-cant-deduce-links-for old-member)) (setf (slot-value self 'list-of-elements) (remove old-member (slot-value self 'list-of-elements))))) (defmethod make-link ((self analysis-path)) ;;; ;;; Make a link from node-1 to node-2 ;;; (let ((node-1 ($! (prompt-read self "Node to link from :"))) node-2) (if (not (typep node-1 'path-element)) (prompt-print self "You can only make links between elements of the Analysis-path" ) (progn (setf node-2 ($! (prompt-read self "Node to break the link to : ")) ) (if (not (typep node-2 'path-element)) (prompt-print self "You can only make links between elements of the Analysis-path" ) (when (and node-1 node-2) (analysis-link node-1 node-2) (recompute self))))))) (defmethod parameter-browser ((self analysis-path)) ;;; ;;; Browse the parameters of the analysis path ;;; (let ((old-starting-list (slot-value self 'starting-list)) new-starting-list) (dolist (item (slot-value self 'list-of-elements)) (unless (class-p (slot-value item 'class-of-element)) (push item new-starting-list))) (setf (slot-value self 'starting-list) new-starting-list) (recompute self) (setf (slot-value self 'starting-list) old-starting-list))) (defmethod global-browser ((self analysis-path)) "Browse all the operations to apply to complete the analysis path (the ~ parameters are not browsed -- used links are causal links)." (declare (special *causal-link-flg*)) (let ((old-starting-list (slot-value self 'starting-list)) new-starting-list) (dolist (item (slot-value self 'list-of-elements)) (when (class-p (slot-value item 'class-of-element)) (push item new-starting-list))) (setf (slot-value self 'starting-list) new-starting-list) (setf *causal-link-flg* t) (recompute self) (makunbound '*causal-link-flg*) (setf (slot-value self 'starting-list) old-starting-list))) (defmethod general-browser ((self analysis-path)) "Browse all the nodes constructed to complete the analysis-path, even those ~ which will not be viewed when the analysis path is applied. ~ Used links are the causal links." (declare (special *causal-link-flg*)) (let ((old-starting-list (slot-value self 'starting-list))) (setf (slot-value self 'starting-list) (copy-list (slot-value self 'list-of-elements))) (setf *causal-link-flg* t) (recompute self) (makunbound '*causal-link-flg*) (setf (slot-value self 'starting-list) old-starting-list))) (defmethod general-analysis-browser ((self analysis-path)) "Browse all the nodes constructed to complete the analysis path. Even those ~ which will not be viewed when the analysis path is applied. ~ Links used are the analysis links." (let ((old-starting-list (slot-value self 'starting-list))) (setf (slot-value self 'starting-list) (copy-list (slot-value self 'list-of-elements))) (recompute self) (setf (slot-value self 'starting-list) old-starting-list))) (defmethod forward-links ((self analysis-path) linked-object) "Returns the analysis-links or causal-links of the linked-object depending ~ on the value of *causal-link-flg*." (declare (special *causal-link-flg*)) (if (boundp '*causal-link-flg*) (if (slot-exists-p linked-object 'causal-links) (slot-value linked-object 'causal-links) (error-cant-deduce-links-for linked-object)) (if (slot-exists-p linked-object 'analysis-links) (slot-value linked-object 'analysis-links) (error-cant-deduce-links-for linked-object)))) (defmethod create-view ((self analysis-path)) "Creates a view inside the analysis path." (let ((the-new-view (make-instance (class-of self))) new-member) ;; ;; add the new view in SELF ;; (widen-view self the-new-view) (zoom the-new-view) ;; ;; Add members to the new view and delete them from SELF. The user ;; is prompt for New-member in the promptWindow ;; (do nil ((not (setf new-member ($! (prompt-read self "The new member : "))))) (widen-view the-new-view new-member t) (add-parents-node new-member the-new-view) (narrow-view self new-member t)) (recompute the-new-view))) (defmethod break-link ((self analysis-path)) ;;; ;;; Break a link between two nodes ;;; (let ((node-1 ($! (prompt-read self "Node to break the link from : "))) node-2) (if (not (typep node-1 'path-element)) (prompt-print self "You can only manipulate the links between Elements of the Analysis path." ) (progn (setf node-2 ($! (prompt-read self "Node to break the link to : ")) ) (if (not (typep node-2 'path-element)) (prompt-print self "You can only manipulate the links between Elements of the Analysis path." ) (if (and node-1 node-2) (progn (analysis-unlink node-1 node-2) (recompute self)))))))) (defmethod backward-links ((self analysis-path) linked-object) ;;; ;;; Returns the back-analysis-links or Back-causal-links of the linked object ;;; depending on the value of *CAUSAL-LINK-FLG* ;;; (declare (special *causal-link-flg*)) (if (boundp '*causal-link-flg*) (if (slot-exists-p linked-object 'back-causal-links) (slot-value linked-object 'back-causal-links) (error-cant-deduce-links-for linked-object)) (if (slot-exists-p linked-object 'back-analysis-links) (slot-value linked-object 'back-analysis-links) (error-cant-deduce-links-for linked-object)))) (defmethod add-parameter ((self analysis-path) &optional new-parameter visible-in-path) "Prompt and update the analysis path for a new parameter to the path." (if new-parameter (prog (new-node) (if (typep new-parameter 'path-element) (setf new-node new-parameter) (if (setf new-node (intersection (slot-value self 'list-of-elements) (slot-value new-parameter 'list-of-path-elements))) (setf new-node (first new-node)) (progn (setf new-node (make-instance 'path-element)) (setf (slot-value new-node 'class-of-element) "PARAMETER") (push new-node (slot-value self 'list-of-elements)) (push new-node (slot-value new-parameter 'list-of-path-elements)) (when visible-in-path (push new-node (slot-value self 'starting-list)))))) ;; (unless (equal (slot-value new-node 'class-of-element) "PARAMETER") (setf (slot-value new-node 'class-of-element) "PARAMETER") (dolist (parent (slot-value new-node 'needed-arguments)) (remove-other-elements parent self))) (setf (slot-value new-node 'title) (prompt-read self (format nil "Name of ~A in the Analysis path : " (or (get-name new-parameter) (string (class-name (class-of new-parameter )))))))) ;; (do nil ((not (setf new-parameter ($! (prompt-read self "The new parameter : "))))) (add-parameter self new-parameter)))) (defmethod apply-analysis-path ((self analysis-map) &optional (template nil)) "Apply a user defined Analysis path : The definition is made by building an ~ instance of Analysis-path which contains all the operations to execute ~ (Path elements). See Create-Analysis-Path." (declare (special list-of-elements equivalence)) ;; ;; --------------------------- VARIABLES DEFINITIONS -------------------------- ;; ;; TEMPLATE : Name of the reference Analysis-Path ;; (unless template (setf template ($! (prompt-read self "Name of the Analysis Path to apply : ")))) ;; ;; LIST-OF-ELEMENTS : All the Path-Elements and Sub-Analysis-Path necessary ;; to complete the Analysis-Path ;; (setf list-of-elements (list template)) (compute-list-of-elements template) (setf list-of-elements (delete-duplicates list-of-elements)) ;; ;; THE-NEW-VIEW : The result of the Analysis-path is put in a new AnalysisMap ;; included in the main one. Its name is THE-NEW-VIEW (let ((the-new-view (make-instance 'analysis-map)) (nb-functions-in-previous-loop 0) sub-nodes list-functions) ;; ;; EQUIVALENCE : List of equivalence of Data. There are 4 types of data : ;; 1 - Parameters : Path-elements with slot Class-of-element bound to ;; "PARAMETER" . Their equivalent value is given by the user when he applies ;; the Analysis path ;; 2 - Local-Variables : Data which doesn't have to be built because they ;; are created simultaneously with an enveloping object and will be built ;; when the enveloping object is created by a regular path-element ;; 3 - Analysis-Path : Element corresponding to an analysis-path applied ;; inside another analysis path. The result of this sub-analysis-path is put ;; in a nested analysis-map when applied ;; 4 - Path-Elements : The regular path-element correspond to the building ;; of a node ;; (setf equivalence (list (cons template the-new-view))) (dolist (node list-of-elements) (unless (eq node template) (push (cons node nil) equivalence))) ;; ;; SUB-NODES : List of nodes which are generated at creation of other nodes ;; so they don't have to be computed, only extracted from their parent (They ;; correspond to what we called local-variables in EQUIVALENCE) ;; (let (list-init) (dolist (node list-of-elements) (when (typep node 'path-element) (if (understands (slot-value node 'class-of-element) 'list-required-inits) (setf list-init (list-required-inits (slot-value node 'class-of-element))) (setf list-init nil)) (dolist (item (slot-value node 'local-data)) (unless (or (member (first item) list-init) (member (first item) sub-nodes)) (push (second item) sub-nodes)))))) ;; ;; LIST-FUNCTIONS : List of functions to apply to complete the Analysis path ;; . This list is shortened every time a new node is built. WHEN NIL that ;; means that the Analysis path is completed ;; (dolist (node list-of-elements) (unless (or (eq node template) (member node sub-nodes)) (push node list-functions))) ;; ;; -------------------------- END OF VARIABLE DEFINITIONS ------------------- ;; (widen-view self the-new-view) (zoom the-new-view) ;; ;; Ask for the values of parameters and update the Equivalence Table ;; (dolist (node list-of-elements) (when (and (typep node 'path-element) (not (class-p (slot-value node 'class-of-element)))) (let ((answer ($! (prompt-read self (format nil "Parameter equivalent to ~S :" (slot-value node 'title)))))) (replace-in-equivalence node answer) (setf list-functions (remove node list-functions))))) ;; ;; Beginning of the method ;; (do nil ((null list-functions)) (if (eql nb-functions-in-previous-loop (setf nb-functions-in-previous-loop (length list-functions))) (quail-error "Infinite Loop in evaluation of Analysis Path")) (dolist (funct list-functions) (let (expression-to-eval unknown-arg new-node) ;; ;; We first compute and eval the spawning expression if it is ;; correct. ;; 3 values are returned by the method : ;; - T if there are some unknown arguments in the expression to ;; eval NIL otherwise for the first value ;; - The Expression to eval to obtain the result ( NIL if some ;; arguments are unknown) ;; - The result of the evaluation of this expression (NIL if ;; some arguments are unknown) ;; ;;; ;;; The Computed spawning expression for a node created by Add Analysis Node ;;; should be an expression creating a new instance with initializations. This ;;; isn't programmed in the current version because the initarg option in ;;; defclass is not working correctly. So, if the user creates an Analysis ;;; path containing elements created by Add Analysis Node, he will have to ;;; give informations related to initializations which are theorically not ;;; required . ;;; When Initarg is working, we will have to modify Update Path Element so ;;; that the generated spawning expression and the required arguments are OK ;;; (multiple-value-setf (unknown-arg expression-to-eval new-node) (compute-spawning-expression funct template)) ;; ;; If EXPRESSION-TO-EVAL is correct (all required arguments are ;; known) then the work variables are updated ;; (unless unknown-arg (if new-node (setf (slot-value new-node 'spawning-expression) expression-to-eval)) (setf list-functions (remove funct list-functions)) (replace-in-equivalence funct new-node))))) ;; ;; When every node of the Analysis-path is built, we update their links and ;; add them in the views they must be in ;; (dolist (node equivalence) (let ((new-node (cdr node)) node-link) (when new-node (when (slot-exists-p new-node 'list-of-path-elements) (setf (slot-value new-node 'list-of-path-elements) (remove (first node) (slot-value new-node 'list-of-path-elements))) (push (first node) (slot-value new-node 'list-of-path-elements))) (when (typep (first node) 'path-element) (dolist (link (slot-value (first node) 'back-analysis-links)) (if (setf node-link (cdr (assoc link equivalence))) (analysis-link node-link new-node))) (dolist (link (slot-value (first node) 'analysis-links)) (if (setf node-link (cdr (assoc link equivalence))) (analysis-link new-node node-link))) (dolist (link (slot-value (first node) 'back-causal-links)) (if (setf node-link(cdr (assoc link equivalence))) (causal-link node-link new-node))) (dolist (link (slot-value (first node) 'causal-links)) (if (setf node-link (cdr (assoc link equivalence))) (causal-link new-node node-link))))))) ;; ;; we then add the nodes in the analysis-map they must appear in ;; (dolist (view equivalence) (when (typep (first view) 'analysis-path) (dolist (node (slot-value (first view) 'starting-list)) (let ((new-node (cdr (assoc node equivalence)))) (unless (member new-node (slot-value self 'starting-list)) (widen-view (cdr view) new-node)))))) (recompute self))) (defmethod compute-spawning-expression ((self analysis-path) path) "When applying an Analysis path, if the function to apply is an analysis ~ path, we must create a view. ~ The method returns 3 values as it is the case for the corresponding method ~ for a path element. The First one NIL indicates that all the parameters ~ are known in the spawning expression and this one can be applied. The ~ second value is the spawning expression which will be stored in the ~ correct slot of the result and the THIRD value is the result after the ~ spawning expression is applied." (values nil '(zoom (make-instance 'analysis-map)) (let ((result (make-instance 'analysis-map))) (zoom result) result))) (defmethod replace-in-equivalence ((self analysis-path) value) "Replaces in Equivalence Table of the Analysis-Path the previous value ~ equivalent to SELF (which is NIL if everything works OK) by value. ~ Equivalence is a special variable defined in method Apply-Analysis-Path." (declare (special equivalence)) (nsubst (cons self value) (assoc self equivalence) equivalence)) (defmethod after-init ((self path-element)) ;;The default method is updating the spawning expression but this is not ;; necessary for a PathElement because the spawning expression we need ;; doesn't represent how the path-element was built, but how the ;; analysis-node represented by the path element was built. This is defined ;; in method Update-path-element ;; self) (defmethod add-parents-node ((self analysis-path) the-new-view) ;;; If a new element is an Analysis Path, we don't have to create any new ;;; element ;;; So the method does nothing ;;; self)
44,873
Common Lisp
.l
906
34.671082
106
0.544426
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4430de5de869f251f57ce8ad000166ba5b58f0ee38da8e5ab157b218a14e76e3
33,829
[ -1 ]
33,830
utility.lsp
rwoldford_Quail/source/display-network/utility.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; utility.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) ;;; ;;; this file adds some methods to objects and defines some other ;;; utility functions ;;; ;;; ;;; package definitions ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(list-slot-contents! class-p classify-local-methods classify-inherited-methods classify-combined-methods should-not-implement slot-initarg slot-initform sub-class-responsibility list-required-inits descriptive-label get-name class-understands required-init $ $! get-mc))) (defun mode-of-list (the-list) "Determines the common type of the elements of a list in order to build an ~ array of the correct type. The different available modes are ~ STRING, FLOAT and BOOLEAN." (let ((common-mode 'i-dont-know)) (dolist (item the-list) (case common-mode (i-dont-know (cond ((or (null item) (eq item 't)) (setq common-mode 'boolean)) ((or (integerp item) (floatp item)) (setq common-mode 'float)) (t (setq common-mode 'string)))) ((boolean) (cond ((or (null item) (eq item 't)) nil) (t (setq common-mode 'string)))) ((float) (cond ((or (integerp item) (floatp item)) nil) (t (setq common-mode 'string)))) ((string) (return)))) common-mode)) (defmacro required-init (init-form) (declare (ignore init-form)) nil) (defun requires-variable (var) "Prompts for var." (let ((result (quail-prompt-read (concatenate 'string "Enter the value for " (symbol-name var))))) (if (symbolp result) (or ($! result t) (list 'quote result)) (eval result)))) ;;; ;;; method definitions related to PCL objects ;;; (defmethod list-slot-contents! ((self standard-class) slot &optional verbose-flg (sub-classes nil)) ;;; ;;; returns the list of the contents of the slot SLOT concatenated with the ;;; contents of the slots SLOT of ;;; - the supers of SELF recursively if SUB-CLASSES is NIL ;;; - the sub-classes of SELF recursively if SUB-CLASSES is not NIL ;;; Omit content of STANDARD-OBJECT and CLASS unless Verbose-flg is T ;;; (let ((result nil) value) ;; ;; we bind Value with the Slot-value SLOT of self and transforme ;; it in a List ;; (or (listp (setf value (slot-value self slot))) (setf value (list value))) ;; ;; we then push each element of this list which isn't already in ;; result ;; (dolist (element value) (or (member element result) (push element result))) ;; ;; we call this method recursively for each super of SELF or its ;; SUB-CLASSES depending on the value of SUB-CLASSES ;; (dolist (super-or-subs (if sub-classes (class-direct-subclasses self) (class-direct-superclasses self))) (unless (or verbose-flg (member super-or-subs (list (find-class 'standard-class) (find-class 'standard-object)))) (setf result (append result (list-slot-contents! super-or-subs slot verbose-flg sub-classes))))) ;; ;; Here is the result of the method ;; result)) (defmethod classify-local-methods ((self standard-class) &optional (stop-list nil)) ;;; ;;; Index the methods of this class according to their Method-classification ;;; property. The result is a propList style list of pairs <Classification> ;;; <List of methods so classified> ;;; The classification of methods is stored in global variable ;;; *quail-METHODS-CLASSIFICATION* ;;; (let (result classification characteristics) (dolist (method (slot-value self 'direct-methods)) (when (setf characteristics (get-mc method)) (setf classification (second characteristics)) (setf (getf result classification) (push (list (third characteristics) (first characteristics) "") (getf result classification))))) result)) (defmethod classify-inherited-methods ((self standard-class) &optional (stop-list nil) (allowed-classes nil)) ;;; ;;; Index the methods of the Supers of this Class according to their ;;; Method-Classification property. The Result is a propList style List of ;;; pairs <Classification> <list of methods so classified> ;;; When called by the user, Allowed-classes is usually NIL but it is used to ;;; save time in the recursion by the method itself ;;; (declare (special *quail-methods-classification*)) (flet ((list-understands (list-of-objects method) ;; ;; Returns T if method is understood by all the elements ;; of LIST-OF-OBJECTS ;; Returns NIL if one element doesn't understand method ;; (unless (listp list-of-objects) (setf list-of-objects (list list-of-objects))) (dolist (object list-of-objects t) (if (not (class-understands (find-class object) method)) (return nil)))) ;;; (list-not-understands (list-of-objects method) ;; ;; Returns T if method isn't understood by all elements ;; of LIST-OF-OBJECTS ;; Returns NIL if one element understands method ;; (unless (listp list-of-objects) (setf list-of-objects (list list-of-objects))) (dolist (object list-of-objects t) (if (class-understands (find-class object) method) (return nil))))) ;;; (let (result) (dolist (x *quail-methods-classification*) (if (and (class-understands self (first x)) (list-not-understands stop-list (first x)) (list-understands allowed-classes (first x))) (setf (getf result (second x)) (push (list (third x) (first x) "") (getf result (second x)))))) result))) (defmethod should-not-implement ((self t) selector) ;;; ;;; A do nothing method used to void specified inherited methods. The method ;;; Should-not-implement produces an error if actually invoked ;;; (quail-error "~S is not implemented for the class : ~S" selector (class-name (class-of self)))) (defmethod sub-class-responsibility ((self t) selector) ;;; ;;; This method indicates that the implementation of the method given by ;;; selector depends on the subclass, even though, abstractly, it is a method ;;; of some generic class. The method Sub-Class-Responsability produces an ;;; ERROR if actually invoked ;;; (quail-error "~S must be specialized for ~S" selector (class-name (class-of self)))) (defmethod list-required-inits ((self standard-class) &optional (stop-list NIL)) "List those variables which require initialization." (let (forbidden-ivs result) ;; ;; Compute undesirable IVs ;; (dolist (class (if (listp stop-list) stop-list (list stop-list))) (dolist (iv (class-slots class)) (when (and (not (member iv forbidden-ivs)) (listp (slot-initform iv)) (equal (first (slot-initform iv)) 'required-init)) (push iv forbidden-ivs)))) ;; ;; Compute IV to init which are not undesirable ;; (dolist (iv (class-slots self)) (when (and (not (member iv forbidden-ivs)) (listp (slot-initform iv)) (equal (first (slot-initform iv)) 'required-init)) (push iv result))) result)) (defmethod descriptive-label ((self standard-class)) ;; Construct a descriptive string label. (get-name self)) (defmethod get-name ((self standard-class)) ;; Read the name of an object SELF. (class-name self)) (defmethod class-understands ((self standard-class) selector) ; Returns NIL if instances of ; SELF doesn't understand the ; method SELECTOR, T otherwise (if (generic-function-p selector) (let (result) (dolist (super (class-precedence-list self)) (when (get-method (symbol-function selector) nil (list super) nil) (setf result t) (return))) result) nil)) (defmethod zoom ((self standard-class)) (inspect self)) ;;; ;;; other functions ;;; (defun slot-initarg (slot) "Return the initarg of slot." (first (slot-value slot 'initargs))) (defun slot-initform (slot) "Return the initform of slot." (slot-value slot 'initform)) (defmacro $ (name) "Find an object from its name." (declare (special *quail-object-names*)) `(let ((result (if (boundp '*quail-object-names*) (gethash ',name *quail-object-names*)))) (or result (quail-error "No Object named ~S" ',name)))) (defun $! (name &optional no-error-flg) "Returns the object which name is the value of name if it is a symbol ~ If name is a list, we look for the evaluation of this list~ if name is an object, it is returned. ~ This is done by consulting the Hash table *quail-object-names* which is~ updated every time set-name is called. ~ If no-error-flg is T and no object is named name, NIL is returned instead~ of an error." (declare (special *quail-object-names*)) (if (listp name) (setf name (eval name))) (if (typep name 'standard-object) name (let ((result (if (boundp '*quail-object-names*) (gethash name *quail-object-names*)))) (if name (or result (if no-error-flg nil (quail-error "No object named ~S" name))))))) (defun get-mc (method) "MC stands for Method Classification. ~ Returns the value of the Property classification of method by looking in~ global variable *quail-methods-classification*." (declare (special *quail-methods-classification*)) (if (symbolp method) (assoc method *quail-methods-classification*) (let ((name (slot-value (slot-value method 'generic-function) 'name))) (if (symbolp name) (assoc name *quail-methods-classification*))))) (defun add-function-in-menu (function name-in-menu classification &rest args) ;;; make a function callable by menu. ;;; name-in-menu is the name which will be printed for function in menu ;;; classification enables to create a one level hierarchy ;;; args is the list of compulsory arguments to the function (declare (special *quail-methods-classification*)) (push (list function classification name-in-menu args) *quail-methods-classification*)) (defun add-function-in-menu (function name-in-menu classification &rest args) ;;; make a function callable by menu. ;;; name-in-menu is the name which will be printed for function in menu ;;; classification enables to create a one level hierarchy ;;; args is the list of compulsory arguments to the function (declare (special *quail-methods-classification*)) (push (list function classification name-in-menu args) *quail-methods-classification*)) ;;; ;;; How to make a function callable from a menu ;;; you just have to call the function add-function-in-menu and give ;;; as arguments the name of the function (with package if not in Quail) ;;; the label you want to appear in the menu ;;; the classification, which enables you to create a hierarchy in menus ;;; the compulsory parameters, which the user will be asked to complete ;;; if they are unknown when the function is called (defvar *quail-methods-classification* nil)
15,132
Common Lisp
.l
332
30.466867
86
0.514916
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
43212c23c16362ee9049c3e17bf172e2ffdb5fd0d256dd3004fc7a704b0e2800
33,830
[ -1 ]
33,831
title-bar-mixin.lsp
rwoldford_Quail/source/display-network/title-bar-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; title-bar-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(title-bar-mixin))) (defclass title-bar-mixin () ((left-title-items :initform '(("Set package" #'set-package "Select a package") ("How this works" #'how-this-works "A brief explanation as to how this browser works.") ("Buttoning behavior" #'buttoning-behavior "How the mouse works in this browser")) :allocation :class) (middle-title-items :initform '(("Recompute" #'recompute "" :sub-items (("Recompute" #'recompute "Recompute the graph.") ("Recompute labels" #'recompute-labels "Recompute the labels." ) ("In place" #'recompute-in-place "Recompute keeping current view in window" ) ("Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph" ) ("Lattice/Tree" #'change-format "Change format between lattice and tree" ))) ("Return to display" #'remove-from-bad-list "Restore item previously deleted from the display")) :allocation :class) (local-commands :initform '(#'buttoning-behavior #'how-this-works #'describe-contents) :allocation :class) (left-shift-button-behavior :initform "Retrieves the name of (or pointer to) the selected item" :allocation :class) (title-left-button-behavior :initform "Information on the display" :allocation :class) (title-middle-button-behavior :initform "Actions to be taken on the display" :allocation :class) (title-right-button-behavior :initform "The usual window operations" :allocation :class) (body-left-button-behavior :initform "Information on the selected object" :allocation :class) (body-middle-button-behavior :initform "Actions the selected object may take" :allocation :class) (body-right-button-behavior :initform "The usual window operations" :allocation :class) (body-left-control-button-behavior :initform "Reposition the selected object on the display" :allocation :class) (how-this-works :initform "No description is yet available" :allocation :class) (contents-description :initform "No description is yet available" :allocation :class)) (:documentation "A mixin to allow menus on title bars of windows.")) (defmethod describe-contents ((self title-bar-mixin)) ;;; ;;; Describe the content of this browser by consulting the class Value ;;; Contents-Description ;;; (quail-print-help " The content of this type of display " :font-case 'bold) (quail-print-help (slot-value self 'contents-description))) (defmethod how-this-works ((self title-bar-mixin)) "Describe how this browser works." (quail-print-help (format NIL "~&How this works:~%") :font-case 'bold) (quail-print-help (slot-value self 'how-this-works))) (defmethod buttoning-behavior ((self title-bar-mixin)) "Produces some text describing the behavior of the mouse buttons in this ~ browser by consulting the Class variables Left-shift-button-behavior, ~ Title-Left-button-behavior, Title-Middle-button-behavior, ~ Title-Right-button-behavior, Body-Left-button-behavior, ~ Body-Middle-button-behavior, Body-Right-button-behavior and ~ Body-Left-Control-Button-Behavior." (quail-print-help "~%~%~% Mouse Button behavior Left button and Left Shift : " :font-case 'bold) (quail-print-help (slot-value self 'left-shift-button-behavior)) (quail-print-help " When in the Title bar Left Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-left-button-behavior)) (quail-print-help "Middle Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-middle-button-behavior)) (quail-print-help "Right Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-right-button-behavior)) (quail-print-help " When in the body of the display Left Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-left-button-behavior)) (quail-print-help "Middle Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-middle-button-behavior)) (quail-print-help "Right Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-right-button-behavior)) (quail-print-help "Control key and left Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-left-control-button-behavior)))
5,430
Common Lisp
.l
112
39.4375
96
0.603616
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
12ee3c7402f9add343fa676885cd28938e62f01935020c53f7b9c0a0c1079ad7
33,831
[ -1 ]
33,832
problems
rwoldford_Quail/source/display-network/problems
? (mk::compile-display-network) ; - Compiling system "display-network" ; - Compiling source file ; "q;Source:Analysis-map:display-network:quail-functions-mcl.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:quail-functions-mcl.lisp" : ; Unused lexical variable VARIABLE, in ACCESS-EXPRESSION. ; Undeclared free variable *CURRENT-EVENT*, in WINDOW-ZOOM-EVENT-HANDLER. ; Unused lexical variable MESSAGE, in WINDOW-ZOOM-EVENT-HANDLER. ; Undeclared free variable *CURRENT-EVENT* (2 references), in WINDOW-EVENT. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:quail-functions-mcl.lisp" : ; Undefined function MAKE-RECORD, in WINDOW-EVENT. ; Undefined function RREF (2 references), in WINDOW-EVENT. ; Undefined function WPTR, in WINDOW-EVENT. ; Undefined function WINDOW-SELECT, in WINDOW-CLICK-EVENT-HANDLER. ; Undefined function WINDOW-HIDE, in WINDOW-CLICK-EVENT-HANDLER. ; Undefined function DOUBLE-CLICK-P, in WINDOW-CLICK-EVENT-HANDLER. ; Undefined function CANVAS-DRAW-STRING, in VIEW-DRAW-CONTENTS. ; Undefined function STRING-WIDTH, in VIEW-DRAW-CONTENTS. ; Undefined function BITMAP-WIDTH, in VIEW-DRAW-CONTENTS. ; Undefined function CANVAS-MOVE-TO, in VIEW-DRAW-CONTENTS. ; Undefined function SET-VIEW-FONT, in VIEW-DRAW-CONTENTS. ; Undefined function BITMAP-HEIGHT, in VIEW-DRAW-CONTENTS. ; Undefined function CANVAS-BITBLT, in VIEW-DRAW-CONTENTS. ; Undefined function BROWSER-OF, in VIEW-DRAW-CONTENTS. ; Undefined function ICON-TITLE, in VIEW-DRAW-CONTENTS. ; Undefined function WINDOW-HIDE, in WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function WINDOW-SHOW, in WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function MAKE-POINT, in WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function MAKE-CANVAS, in WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function BROWSER-OF (2 references), in WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function MAKE-POINT (2 references), in QUAIL-PRINT-HELP. ; Undefined function WPTR, in QUAIL-PRINT-HELP. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-functions-mcl.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:utility.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-icon-mcl.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:prompt-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:dated-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:initable-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:editable-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:indexed-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:named-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:documented-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:linked-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:zoom-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:tool-box-link.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:find-where-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:body-menu.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:title-bar-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-object.fasl" ;Warning: CCL::CLASS QUAIL-OBJECT previously defined in: q;Source:Kernel:Basic:quail-object.lisp ; is now being redefined in: q;Source:Analysis-map:display-network:quail-object.lisp ; ; While executing: CCL:RECORD-SOURCE-FILE ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:memo.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-browser.fasl" > Error: There is no package named "BROWSER" . > While executing: CCL::%FASLOAD > Type Command-/ to continue, Command-. to abort. > If continued: Retry finding package with name "BROWSER". See the RestartsÉ menu item for further choices. 1 > Make "BROWSER" be a nickname for package "QUAIL". ; - Compiling source file ; "q;Source:Analysis-map:display-network:network-view.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:network-view.lisp" : ; Unused lexical variable LINKED-OBJECT, in FORWARD-LINKS. ; Unused lexical variable LINKED-OBJECT, in BACKWARD-LINKS. ; Unused lexical variable NAME, in SET-NAME. ; Unused lexical variable OBJ, in DO-SELECTED-COMMAND. ; Unused lexical variable COMMAND, in DO-SELECTED-COMMAND. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:network-view.lisp" : ; Undefined function MAKE-MENU, in RETURN-AN-EXPLODED-VIEW. ; Undefined function SELECT-IN-MENU, in RETURN-AN-EXPLODED-VIEW. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:network-view.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:micro-view.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:micro-view.lisp" : ; Unused lexical variable DONT-RECOMPUTE-FLAG, in WIDEN-VIEW. ; Unused lexical variable NEW-MEMBER, in WIDEN-VIEW. ; Unused lexical variable THE-LARGER-VIEW, in UNENVELOP-BY. ; Unused lexical variable DONT-RECOMPUTE-FLAG, in RETURN-AN-EXPLODED-VIEW. ; Unused lexical variable THE-EXPLODED-VIEW, in RETURN-AN-EXPLODED-VIEW. ; Unused lexical variable A-MEMBER, in PATH-TO. ; Unused lexical variable DONT-RECOMPUTE-FLAG, in NARROW-VIEW. ; Unused lexical variable DONT-ADD-TO-ENVELOPING-VIEW, in NARROW-VIEW. ; Unused lexical variable OLD-MEMBER, in NARROW-VIEW. ; Unused lexical variable LINKED-OBJECT, in FORWARD-LINKS. ; Unused lexical variable DONT-RECOMPUTE-FLAG, in EXPLODE-A-NESTED-VIEW. ; Unused lexical variable THE-SELECTED-VIEW, in EXPLODE-A-NESTED-VIEW. ; Unused lexical variable THE-LARGER-VIEW, in ENVELOP-BY. ; Unused lexical variable LINKED-OBJECT, in BACKWARD-LINKS. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:micro-view.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:analysis-network.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-network.lisp" : ; Unused lexical variable ITEM-CV, in GET-CLASS-MENU-ITEMS. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-network.lisp" : ; Undefined function APPLY-ANALYSIS-PATH, in ADD-ANALYSIS-NODE. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:analysis-network.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:toolbox-network.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:toolbox-network.lisp" : ; Unused lexical variable REST, in SUB-TOOLBOX. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:toolbox-network.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:analysis-path.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-path.lisp" : ; Unused lexical variable DONT-RECOMPUTE-FLAG, in NARROW-VIEW. ; Unused lexical variable DONT-ADD-TO-ENVELOPING-VIEWS-FLAG, in NARROW-VIEW. ; Unused lexical variable PATH, in COMPUTE-SPAWNING-EXPRESSION. ; Unused lexical variable THE-NEW-VIEW, in ADD-PARENTS-NODE. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-path.lisp" : ; Undefined function UNKNOWN-ARG, in APPLY-ANALYSIS-PATH. ; Undefined function MULTIPLE-VALUE-SETF, in APPLY-ANALYSIS-PATH. ; Undefined function OBJECT-P, in UPDATE-LINKS-PATH-ELEMENT. ; Undefined function OBJECT-P (4 references), in UPDATE-PATH-ELEMENT. ; Undefined function OBJECT-P, in REPL inside COMPUTE-SPAWNING-EXPRESSION. ; Undefined function T, in REPL inside COMPUTE-SPAWNING-EXPRESSION. ; Undefined function OBJECT-P, in PARENT-NODES. ; Undefined function OBJECT-P, in TRANSLATE-PARAMETER. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:analysis-path.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-methods-mcl.fasl" ; - Providing system display-network
8,864
Common Lisp
.l
147
58.210884
102
0.736915
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
40107c3180636f4d6a857d06806b4564fcefd07890c616a1b5862e6b8f060eaf
33,832
[ -1 ]
33,833
prompt-mixin.lsp
rwoldford_Quail/source/display-network/prompt-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prompt-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prompt-mixin))) (defclass prompt-mixin () () (:documentation "This class specializes the prompt methods of web-editor for quail-browser ~ so that a *quail-prompt-window* is used for the prompt. ~ the place of this mixin in the inheritance list of quail-browser or ~ quail-object is important.")) (defmethod prompt-eval ((self prompt-mixin) msg) ;;"Specialization." (wb::prompt-user :read-type :eval :prompt-string msg )) (defmethod prompt-read ((self prompt-mixin) msg) ;; ;; Specialization ;; (wb::prompt-user :read-type :read :prompt-string msg))
1,195
Common Lisp
.l
32
32.71875
81
0.494313
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
63c7de0640a6c15e23fe71ca153435cacaf9d0c5307ea769fb6b0f6f98f46205
33,833
[ -1 ]
33,834
named-object.lsp
rwoldford_Quail/source/display-network/named-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; named-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(named-object))) (defclass named-object () ((name :initform nil :documentation "Name of this object.")) (:documentation "Enables to give a name to an Object. The name must be updated using ~ set-name method exclusively. Do not change directly the slot-value because ~ an association list *quail-object-name* must be updated in the same time ~ which permits to find rapidly an object given its name ~ An object can be found when we know its name using the macro ($ Name) ~ which returns Object." )) (defmethod get-name ((self named-object)) ;;; ;;; Read the name of an object SELF. ;;; (slot-value self 'name)) (defmethod set-name ((self named-object) &optional name) "Give a name to an Object. If name is NIL, ask the user for a name ~ the hash table *quail-object-names* is updated by this method. ~ The equivalence is made on the printed name only, so that the user doesn't ~ have to care about packages. So, the name in the equivalence variable ~ *quail-object-names* is a string." (declare (special *quail-object-names*)) (or name (setq name (prompt-read self "Name to be given to this object : "))) (let ((previous-name (get-name self))) (if ($! name t) ;; ;; doesn't allow 2 objects with the same name. So if the name ;; is already used, the user is asked whether he wants to ;; remove the previous existing name he has given or he wants ;; to put another name ;; (if (member (prompt-read self (format nil "The name ~S is already used, do you want to set this name anyway (Y or N) " name)) '(y \y yes |yes|)) (setf (slot-value ($! name) 'name) nil) (progn (set-name self) (setq name nil)))) ;; (if name (progn ;; Build an empty Hash-Table if it doesn't exist yet ;; (or (boundp '*quail-object-names*) (setq *quail-object-names* (make-hash-table))) ;; ;; Update Hash-Table with new name ;; (if previous-name (remhash previous-name *quail-object-names*)) (setf (gethash name *quail-object-names*) self) ;; ;; Update Slot-name of self ;; (setf (slot-value self 'name) name))) self))
3,252
Common Lisp
.l
79
30.860759
116
0.505473
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d0c451d112cd2c8789b18c1a252c63fddee2c3663d1b33616f96b7a00931fcc5
33,834
[ -1 ]
33,835
junk-extract.lsp
rwoldford_Quail/source/display-network/junk-extract.lsp
;;; -*- Mode: LISP -*- (in-package :quail) ;;; this file is only an example to show how we can deal with more complex data ;;; ;;; class definition ;;; (defclass junk-extract (quail-object) ((a :initform (required-init ($! (quail-prompt-read "Initialization for A : "))) :initarg :a) (b :initform (required-init ($! (quail-prompt-read "Initialization for B : "))) :initarg :b) (sum :initform nil) (product :initform nil))) ;;; ;;; method definitions ;;; (defmethod after-init ((self junk-extract)) ;;; ;;; Specialization : Computes IVs of SELF ;;; (call-next-method) (setf (slot-value self 'sum) (+ (slot-value self 'a) (slot-value self 'b))) (setf (slot-value self 'product) (* (slot-value self 'a) (slot-value self 'b)))) (defmethod list-subs ((self junk-extract) &optional dont-signal-error) ;;; ;;; Returns the subs of SELF ;;; (let (quail-object-ivs result) (dolist (iv (class-slots (find-class 'quail-object))) (push (slot-value iv 'name) quail-object-ivs)) (dolist (iv (class-slots (class-of self))) (unless (member (setq iv (slot-value iv 'name)) quail-object-ivs) (push (cons (slot-value self iv) iv) result))) result))
1,692
Common Lisp
.l
45
24.088889
80
0.475892
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f846dbf632c99df6950e710fa332cc0e5dbd6bba67a6b2a0147f5bb977858fef
33,835
[ -1 ]
33,836
editable-object.lsp
rwoldford_Quail/source/display-network/editable-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; editable-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(editable-object notes-of))) (defclass editable-object (dated-object initable-object) ((notes :initform nil ;; (CONCATENATE 'STRING "Object ;; " (OR (SLOT-VALUE SELF 'NAME) ;; "") " created by " ;; (SLOT-VALUE SELF 'CREATOR) " ;; " (IL:GDATE (SLOT-VALUE SELF ;; 'CREATED)) " using " (CAR ;; (SLOT-VALUE SELF ;; 'SPAWNING-EXPRESSION))) :initarg :notes :accessor notes-of :documentation "User added notes on this object." ) ) (:documentation "Mixin class used to collect notes on an object.")) (defmethod read-notes ((self editable-object)) ;;; ;;; Read the notes recorded on this item ;;; (if (null (slot-value self 'notes)) (quail-print-help "Nothing recorded on this item yet") (edit-text (slot-value self 'notes) :read-only t))) (defmethod edit-notes ((self editable-object)) "Invoke an editor to edit the notes on the Notes IV." (setf (notes-of self) (edit-text (notes-of self)))) (defmethod add-notes ((self editable-object)) "Stash user supplied note onto the Notes IV." (setf (notes-of self) (edit-text (concatenate 'string (notes-of self) (format "~&Edited by ~s. ~%~ Time: ~s~%" (user-name) (get-universal-time)) ) )))
2,193
Common Lisp
.l
56
28.625
93
0.449952
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
37884c6643d023b638b90c031154e3f0cc9d26147a154d71e955d4d7279b6460
33,836
[ -1 ]
33,837
micro-view.lsp
rwoldford_Quail/source/display-network/micro-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; micro-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; class definition ;;; (defclass microscopic-view (network-view) ((left-button-items :initform '(("Name this item" #'name-this-item "Give a name to this item.") ("Edit Notes" #'edit-notes "Edit the notes attached to this item.") ("Zoom" #'zoom "View this item in greater detail.")) :allocation :class) (left-title-items :initform '(("How this works" #'how-this-works "A brief explanation as to how a microscopic view works.") ("Buttoning Behavior" #'buttoning-behavior "How the mouse buttons work in this kind of View.") ("Show location on map" #'show-location-on-map "Flash the node of this zoomed object in the Analysis map.") ("Short summary of zoomed object" #'short-summary "A short description of the kind of item zommed in on.")) :allocation :class) (middle-title-items :initform '(("Recompute" #'recompute "Recompute." :sub-items (("Recompute" #'recompute "Recompute the graph.") ("Recompute labels" #'recompute-labels "Recompute the labels.") ("In Place" #'recompute-in-place "Recompute keeping current display in window.") ("Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph.") ("Lattice/Tree" #'change-format "Change format between lattice and tree.")))) :allocation :class) (icon :initform zoom-icon :allocation :class) (mask :initform zoom-icon-mask :allocation :class) (title-reg :initform '(2 2 50 27) :allocation :class) (sub-view-icon :initform zoom-icon :allocation :class) (graph-format :initform *horiz-lattice*) (title :initform "Microscopic view") (zoomed-object :initform nil))) ;;; ;;; method definitions ;;; (defmethod zoom ((self microscopic-view)) (let ((the-zoomed-object (slot-value self 'zoomed-object))) (or the-zoomed-object (setq the-zoomed-object ($! (prompt-read "Give the object whose internal structure is to be viewed : " )))) (setf (slot-value self 'starting-list) (list the-zoomed-object)) (call-next-method))) (defmethod widen-view ((self microscopic-view) &optional new-member dont-recompute-flag) (should-not-implement self 'widen-view)) (defmethod unenvelop-by ((self microscopic-view) the-larger-view) (should-not-implement self 'unenvelop-by)) (defmethod show-location-on-map ((self microscopic-view)) (show-location-on-map (slot-value self 'zoomed-object))) (defmethod short-summary ((self microscopic-view)) (short-summary (slot-value self 'zoomed-object))) (defmethod return-an-exploded-view ((self microscopic-view) &optional the-exploded-view dont-recompute-flag) (should-not-implement self 'return-an-exploded-view)) (defmethod path-from ((self microscopic-view) linked-object) (if (eq linked-object (slot-value self 'zoomed-object)) (list-subs linked-object))) (defmethod path-to ((self microscopic-view) a-member) (should-not-implement self 'paths-to)) (defmethod narrow-view ((self microscopic-view) &optional old-member dont-add-to-enveloping-view dont-recompute-flag) (should-not-implement self 'narrow-view)) (defmethod get-links ((self microscopic-view) object &key (reverse? NIL)) (if reverse? (quail-error "Can't go backwards in a microscopic view ! ") (let ((the-subs (path-from self object)) result) (if the-subs (if (listp the-subs) (progn (dolist (item the-subs) (if (listp item) (let* ((sub-object (car item)) (sub-label (cdr item)) (cached-label (assoc sub-object (slot-value self 'menu-cache)))) (if (null cached-label) (let ((new-label (format nil "~A : ~A" sub-label (get-label self sub-object)))) (push (cons sub-object new-label) (slot-value self 'label-cache)))) (push sub-object result)) (push item result))) result) the-subs))))) (defmethod forward-links ((self microscopic-view) linked-object) (should-not-implement self 'forward-links)) (defmethod explode-a-nested-view ((self microscopic-view) &optional the-selected-view dont-recompute-flag) (should-not-implement self 'explode-a-nested-view)) (defmethod envelop-by ((self microscopic-view) the-larger-view) (should-not-implement self 'envelop-by)) (defmethod create-view ((self microscopic-view)) (should-not-implement self 'create-view)) (defmethod backward-links ((self microscopic-view) linked-object) (should-not-implement self 'backward-links))
6,615
Common Lisp
.l
138
32.586957
84
0.514466
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
875d8a4eb6d9935b83e77c637331d6090bbbd2bf7e39216f19af0aea9fb5f20e
33,837
[ -1 ]
33,838
setup-menus.lsp
rwoldford_Quail/source/display-network/setup-menus.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; setup-menus.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (add-function-in-menu #'in-view "in view" '|Objects in this view| 'self) (add-function-in-menu #'in-view! "in view!" '|Objects in this view| 'self) (add-function-in-menu #'widen-view "widen view" '|Widen this view| 'self) (add-function-in-menu #'add-forward-analysis-link "add forward analysis link" 'Link-operators 'self 'linkee) (add-function-in-menu #'analysis-link "analysis link" 'Link-operators 'self 'linkee) (add-function-in-menu #'analysis-unlink "analysis unlink" 'Link-operators 'self 'linkee) (add-function-in-menu #'remove-back-analysis-link "remove back analysis-link" 'Link-operators 'self 'linkee) (add-function-in-menu #'remove-forward-analysis-link "remove forward analysis-link" 'Link-operators 'self 'linkee) (add-function-in-menu #'and "and" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'or "or" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'xor "xor" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'* "*" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'+ "+" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'- "-" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'/ "/" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'< "<" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'= "=" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'> ">" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'mod "mod" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'rem "rem" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'^ "^" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'!= "!=" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'! "!" 'reexpression 'self) (add-function-in-menu #'abs "abs" 'reexpression 'self) (add-function-in-menu #'acos "acos" 'reexpression 'self) (add-function-in-menu #'exp "exp" 'reexpression 'self) (add-function-in-menu #'expt "expt" 'reexpression 'self 'exponent) (add-function-in-menu #'floor "floor" 'reexpression 'self) ;;(add-function-in-menu #'gamma "gamma" 'reexpression 'self) ;;(add-function-in-menu #'lgamma "lgamma" 'reexpression 'self) (add-function-in-menu #'log "log" 'reexpression 'self) (add-function-in-menu #'log10 "log 10" 'reexpression 'self) (add-function-in-menu #'sin "sin" 'reexpression 'self) (add-function-in-menu #'sqrt "sqrt" 'reexpression 'self) (add-function-in-menu #'trunc "trunc" 'reexpression 'self) (add-function-in-menu #'unary-minus "unary minus" 'reexpression 'self) (add-function-in-menu #'asin "asin" 'reexpression 'self) (add-function-in-menu #'atan "atan" 'reexpression 'self) (add-function-in-menu #'ceiling "ceiling" 'reexpression 'self) (add-function-in-menu #'cos "cos" 'reexpression 'self) (add-function-in-menu #'add-analysis-node "add analysis node" '|Widen this view| 'self '|new analysis node|)
3,594
Common Lisp
.l
63
52.365079
84
0.618723
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9ca555f7660533a062c5efef94b70e7d35f089143af9eec59e9d1b891b08b031
33,838
[ -1 ]
33,839
analysis-network.lsp
rwoldford_Quail/source/display-network/analysis-network.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; analysis-network.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988 - 1992. ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) ;;; ;;; class definition ;;; (defclass analysis-map (body-menu network-view) ((contents-description :initform "If you have time, you should type in a description of the content of an Analysis Map" :allocation :class) (how-this-works :initform "As you will notice, it works pretty well." :allocation :class) ;; ;; Menu items for Left button selection. Value sent as message to ;; object or browser .. See LocalCommands ;; (left-button-items :initform '(("Name this item" #'name-this-item "Give a name to this item.") ("Edit Notes" #'add-notes "Edit the notes attached to this item.") ("A short summary" #'short-summary "A short description of the kind of item selected.") ("Zoom" #'zoom "View this item in greater detail.")) :accessor left-button-items-of :allocation :class) (left-title-items :initform '(("How this works" #'how-this-works "A brief explanation as to how this kind of view works.") ("Buttoning Behavior" #'buttoning-behavior "How the mouse buttons work in this kind of View.") ("Building analysis" #'describe-contents "How to build analysis in this display.") ("Name this Analysis Map" #'name-this-item "Give a unique name to this Analysis Map.")) :accessor left-title-items-of :allocation :class) (middle-title-items :initform '(("Widen" #'widen-view "Widen the View." :sub-items (("Widen the View" #'widen-view "Widen the view by including existing objects.") ("Add a new kind of Analysis node" #'add-analysis-node "Add a new kind of node to the Analysis Map ~ (usually by taking one from a ToolBox).") ("Add result of a form evaluation" #'add-root "Prompt for a form to be evaluated; ~ the result is added to this Analysis Map."))) ("Narrow" #'narrow-view "Narrow the view." :sub-items (("Narrow the View" #'narrow-view "Narrow the view by excluding the selected Objects.") ("Create a View" #'create-view "Compress part of the current view into a smaller Analysis Map."))) ("Nesting" nil "" :sub-items (("Explode a nested Analysis Map" #'explode-a-nested-view "Explode an Analysis map nested in this display.") ("Return an exploded Analysis Map" #'return-an-exploded-view "Return to the display an Analysis Map that was exploded."))) ("Links" nil "" :sub-items (("Break a Link" #'break-link "Break an existing link between two nodes in he map.") ("Make a Link" #'make-link "Construct a directed Analysis link between two nodes in the Map.") ("Insert a Memo between two nodes" #'interpose-memo "Interpose a Memo Object between two nodes in the Map."))) ("Create an Analysis Path" #'create-analysis-path "Create a new Analysis Path") ("Recompute" #'recompute "Recompute." :sub-items (("Recompute" #'recompute "Recompute the graph." ) ("Recompute labels" #'recompute-labels "Recompute the labels.") ("In Place" #'recompute-in-place "Recompute keeping current display in window.") ("Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph.") ("Lattice/Tree" #'change-format "Change format between lattice and tree"))) ("Save Value" #'save-it "Save this Analysis Map")) :allocation :class :accessor middle-title-items-of) (icon :initform map-icon :allocation :class) (mask :initform map-icon-mask :allocation :class) (invert :initform nil :allocation :class) (title-reg :initform '(2 2 46 21) :allocation :class) (sub-view-icon :initform analysis-map-icon :allocation :class) (title :initform "An Analysis Map" :accessor title-of))) ;;; ;;; method definitions ;;; (defmethod make-link ((self analysis-map)) ;;; ;;; Link from Node-1 to Node-2 ;;; (let ((node-1 ($! (prompt-read self "Node to link from :"))) node-2) (if (and node-1 (eq (find-class 'analysis-map) (class-of node-1))) (prompt-print self (format nil "Sorry, there are no Analysis links from an Analysis Map. Instead, you must explode ~S to manipulate the Analysis links." (or (slot-value node-1 'name) node-1))) (progn (setq node-2 ($! (prompt-read self "Node to break the link to : ")) ) (if (and node-2 (eq (find-class 'analysis-map) (class-of node-2))) (prompt-print self (format nil "Sorry, there are no Analysis links from an Analysis Map. Instead, you must explode ~S to manipulate the Analysis links." (or (slot-value node-2 'name) node-2))) (if (and node-1 node-2) (progn (analysis-link node-1 node-2) (recompute self)))))))) (defmethod break-link ((self analysis-map)) ;;; ;;; Break a link between two nodes ;;; (let ((node-1 ($! (prompt-read self "Node to break the link from : "))) node-2) (if (and node-1 (eq (find-class 'analysis-map) (class-of node-1))) (prompt-print self (format nil "Sorry, there are no Analysis links from an Analysis Map. Instead, you must explode ~S to manipulate the Analysis links." (or (slot-value node-1 'name) node-1))) (progn (setq node-2 ($! (prompt-read self "Node to break the link to : ")) ) (if (and node-2 (eq (find-class 'analysis-map) (class-of node-2))) (prompt-print self (format nil "Sorry, there are no Analysis links from an Analysis Map. Instead, you must explode ~S to manipulate the Analysis links." (or (slot-value node-2 'name) node-2))) (if (and node-1 node-2) (progn (analysis-unlink node-1 node-2) (recompute self)))))))) (defmethod forward-links ((self analysis-map) linked-object) ;;; ;;; Returns the Analysis-Links of the Linked-Object ;;; (if (slot-exists-p linked-object 'analysis-links) (slot-value linked-object 'analysis-links) (error-cant-deduce-links-for linked-object))) (defmethod backward-links ((self analysis-map) linked-object) ;;; ;;; Returns the Back-Analysis-Links of the Linked-Object ;;; (if (slot-exists-p linked-object 'back-analysis-links) (slot-value linked-object 'back-analysis-links) (error-cant-deduce-links-for linked-object))) (defmethod interpose-memo ((self analysis-map)) "Place a memo object between two quail objects." (let ((node-1 ($! (prompt-read self "Node to break link from "))) node-2 memo-node) (if (eq (class-of node-1) (find-class 'analysis-map)) (progn (prompt-print self "Can't, Memos can only be inserted between two quail-objects." ) (prompt-print self (format nil "Explode the Analysis Map ~S and insert ~ the Memo accordingly." node-1))) (progn (setq node-2 ($! (prompt-read self "Node to break link to "))) (if (eq (class-of node-2) (find-class 'analysis-map)) (progn (prompt-print self "Can't, Memos can only be inserted between~ two quail-objects." ) (prompt-print self (format nil "Explode the Analysis Map ~S and~ insert the Memo accordingly." node-2))) (if (and node-1 node-2) (progn (setq memo-node (make-instance 'memo)) (analysis-unlink node-1 node-2) (analysis-link node-1 memo-node) (analysis-link memo-node node-2) (widen-view self memo-node)))))))) (defmethod add-analysis-node ((self analysis-map) new-node) "Add a new kind of node (usually selecting it in a Toolbox). If the node ~ corresponds to a class, add-instance-node is applied otherwise method ~ apply-analysis-path is applied." (if new-node (if (eq (find-class 'analysis-path) (class-of ($! new-node t))) (apply-analysis-path self ($! new-node)) (add-instance-node self new-node)))) (defmethod add-instance-node ((self analysis-map) new-node) "Add an object to an analysis map. The user is asked for the analysis links ~ but the causal links are updated automatically." (let ((the-node-object (make-instance new-node)) link-name) (do nil ((not (setq link-name ($! (prompt-read self "Link to node : ")) ))) (analysis-link link-name the-node-object)) (widen-view self the-node-object) the-node-object)) (defmethod extraction ((self analysis-map) object slot-to-extract) "Add a new object on the Map which is taken among the instance variables of ~ the parent-object selected on the analysis-Map. ~ We first link the new object with his parent and then add it in the view." (let ((object-to-extract (slot-value object slot-to-extract))) (analysis-link object object-to-extract) (widen-view self object-to-extract))) (defmethod get-class-menu-items ((self analysis-map) item-cv) "Build the part of menu related to extraction." (declare (special object)) (let ((the-item-list (call-next-method)) extraction-list quail-object-slots slot-name) ;; compute the list of slots of quail-object (dolist (item (class-slots (find-class 'quail-object))) (push (slot-value item 'name) quail-object-slots)) ;; the variables you can extract are those which are not inherited from ;; quail-object and bound to an object (dolist (item (class-slots (class-of object))) (setq slot-name (slot-value item 'name)) (when (and (typep (slot-value object slot-name) 'object) (not (member slot-name quail-object-slots))) (push (list slot-name (list 'extraction (list 'quote slot-name)) "Release button to extract the selected object.") extraction-list))) (when extraction-list (cons :sub-items (list extraction-list)) (setq the-item-list (append the-item-list (list (list "Extraction" nil "Slide over to see the objects you can extract." extraction-list))))) the-item-list)) (defmethod create-analysis-path ((self analysis-map)) "Create and zoom a new analysis-path." (let ((new-path (make-instance 'analysis-path))) (zoom new-path) (widen-view new-path) new-path))
13,674
Common Lisp
.l
268
34.697761
173
0.504417
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a59c900a6a2fb1e46d99b0aafd63660101474a8f4e1000e8bf54e2c5ce313ac7
33,839
[ -1 ]
33,841
quail-object.lsp
rwoldford_Quail/source/display-network/quail-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) ;;; ;;; First mix the new class definitions into Quail-object ;;; (eval-when (load compile) (loop for c in '(prompt-mixin linked-object indexed-object editable-object named-object documented-object) do (add-mixin-to-quail-object c))) #| (defmethod init-ivs ((self ref-array)) ;;; ;;; Specialization ;;; self) |# (defmethod list-subs ((self quail-object) &optional (dont-signal-error nil)) "Return a list comprised of the sub-structures of self. Invoked by a ~ MicroView. SubClassResponsibility to provide the definitive description." (if dont-signal-error nil (sub-class-responsibility self 'list-subs))) (defmethod descriptive-label ((self quail-object)) "Construct a descriptive string label SuClass responsibility to specialize ~ with more elaborate description." (let ((my-name (get-name self)) (my-class (class-name (class-of self)))) (concatenate 'string (if my-name (string my-name) " ") " " (string my-class))))
1,720
Common Lisp
.l
48
27.854167
83
0.484146
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4a9e9aed4edee3ed1f7a4fbdcb6e4bcb07834eb7938a37fb5487cdfa905d57ae
33,841
[ -1 ]
33,842
documented-object.lsp
rwoldford_Quail/source/display-network/documented-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; documented-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(documented-object long-summary-of reference-of short-summary-of glossary-of))) (defclass documented-object () ((long-summary :initform "No summary is available on this item" :allocation :class :accessor long-summary-of) (reference :initform "No references are available for this item" :allocation :class :accessor reference-of) (short-summary :initform "No summary is available on this item" :allocation :class :accessor short-summary-of) (glossary :initform "No glossary is available for this item" :allocation :class :accessor glossary-of)) (:documentation "This mixin stores textual information for the given class of object.")) (defmethod references ((self documented-object) object) ; Produce a list of references ; in the litterature for this ; kind of quail-object (quail-print-help (if (slot-exists-p object 'references) (slot-value object 'references) "description not available"))) (defmethod short-summary ((object documented-object)) ; Produce a short summary of ; this kind of OBJECT (quail-print-help (if (slot-exists-p object 'short-summary) (slot-value object 'short-summary) "description not available"))) (defmethod long-summary ((object documented-object)) ; Produce a long summary of ; this kind of OBJECT (quail-print-help (if (slot-exists-p object 'long-summary) (slot-value object 'long-summary) "description not available"))) (defmethod print-summary ((self documented-object)) ; Produce a summary of ; this kind of quail-object (quail-print-help (if (slot-exists-p self 'glossary) (slot-value self 'glossary) "description not available")))
3,055
Common Lisp
.l
60
34
129
0.462445
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c3d01a2453193075eb7003ae102234704dd5708ebb2bb3a90878368f691dd718
33,842
[ -1 ]
33,846
Z-browser.lsp
rwoldford_Quail/source/display-network/junk/Z-browser.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) ;;; ;;; class definition ;;; (defclass Z-browser (title-bar-mixin named-object-mixin prompt-mixin browser::browser) ;; ;; The order of inheritance is important : the mixins must be before ;; BROWSER in the list so that Z-BROWSER inherits methods and Class ;; variables of the mixins in priority on those of BROWSER ;; ((local-commands :initform '(box-node name-this-item how-this-works buttoning-behavior describe-contents) :allocation :class) (icon :initform view-icon :allocation :class) ; Default value of icon (mask :initform nil :allocation :class) ; default value of mask of icon (icon-font :initform nil :allocation :class) ; Font used in the Browser (icon-font-description :initform '(helvetica 7 medium) :allocation :class) (title-reg :initform '(0 31 77 10) :allocation :class) ; Default title region of Icon (invert :initform t :allocation :class) ; By default, print title of ; icon on Black background (sub-view-icon :initform view-icon :allocation :class) ; icon to appear inside a Map (cache-menu-p :initform t) ; menu is cached if T (title :initform "Z Browser") ; Title passed to GRAPHER ; package and displayed in the ; Icons )) ;;; ;;; function definitions ;;; (defun format-for-eval (expression) ;;; ;;; Format an expression containing objects so that it can be evaluated by EVAL ;;; The problem is that the objects must be replaced by (QUOTE object) inside ;;; the expression to eval if they are not symbols ;;; the evaluable expression is returned ;;; (mapcar #'(lambda (x) (cond ((symbolp x) x) ((listp x) (format-for-eval x)) (t (list 'quote x)))) expression)) (defun extract-objects (list &aux extracted) ;;; extract a list of objects from a list (dolist (element list) (if (listp element) (setf extracted (append extracted (extract-objects element))) (if (object-p element) (push element extracted)))) extracted) (defmacro with-link (expression-to-eval) `(let ((result (eval (format-for-eval ',expression-to-eval))) list-link) ;; Link with Obj and all other arguments (when (object-p result) (setf list-link (extract-objects (slot-value result 'spawning-expression))) (if (understands result 'causal-link t) (dolist (arg list-link) (when (understands arg 'causal-link result) (causal-link arg result)))) (if (understands result 'analysis-link t) (dolist (arg list-link) (when (understands arg 'analysis-link result) (analysis-link arg result))))) result)) (defmacro from-map (expression) ;;; when a function is called by menu selection, its arguments are not ;;; bound because we only know the node it is applied from and the function ;;; may need other arguments. This macro ask the user values for the other ;;; compulsory arguments. These compulsory arguments are those declared when ;;; the user ask a function to be callable by menu, using add-function-in-menu `(let ((classification (get-mc (first ,expression))) (length (length ,expression)) arg-in-exp) (when classification (do ((arg (fourth classification) (cdr arg)) (rank 1 (+ 1 rank))) ((null arg)) (unless (nth rank ,expression) (if (>= rank length) (setf ,expression (append ,expression (list (requires-variable (first arg))))) (setf (nth rank ,expression) (requires-variable (first arg))))))))) ;;; ;;; method definitions ;;; (defmethod new-item ((self Z-browser) &optional new-item) ;;; ;;; specialization ;;; (if new-item ($! new-item) (set-name (prompt-eval self "Z Expression") (prompt-read self "Name to be given to this Z Expression" )))) (defmethod name-this-item ((self Z-browser) &optional object) ;;; ;;; Name the Object and display the new name in the Browser or the browser ;;; itself if no object ;;; (if object (progn (set-name object) (let ((cached-label (assoc object (slot-value self 'label-cache)))) (setf (slot-value self 'label-cache) (remove cached-label (slot-value self 'label-cache))) (get-display-label self object))) (set-name self)) (recompute self)) (defmethod left-shift-select ((self Z-browser)) ;;; ;;; Specialization ;;; (declare (special object)) (unread self object)) (defmethod middle-shift-select ((self Z-browser)) ;;; ;;; Specialization ;;; (declare (special object)) (unread self object)) (defmethod title-left-shift-select ((self Z-browser)) ;;; ;;; Specialization ;;; (unread self)) (defmethod title-middle-shift-select ((self Z-browser)) ;;; ;;; Specialization ;;; (unread self)) (defmethod get-label ((self Z-browser) object) ;;; ;;; Get a label for an object to be displayed in the browser ;;; (if (understands object 'descriptive-label) (descriptive-label object) (let ((name (get-name object))) (if name (concatenate 'string (string name) " " (string (class-name (class-of object)))) (class-name (class-of object)))))) (defmethod get-links ((self Z-browser) object &key (reverse? nil)) ;;; ;;; We will take care of links in class Network view ;;; nil) (defmethod show ((self Z-browser) &optional browse-list window-or-title good-list) (call-next-method) ;;; ;;; We must install our Shrink method ;;; (setf (icon-of (slot-value self 'window) #'Z-icon-fn) self) (defmethod icon-title ((self Z-browser)) ;;; ;;; Returns the title for this View ;;; (if (slot-value self 'name) (string (slot-value self 'name)) (slot-value self 'title))) (defmethod unread ((self Z-browser) &optional object) (if object (push-in-buffer (access-expression object)) (push-in-buffer (access-expression self)))) (defmethod set-name ((self Z-browser) &optional name) ;;; ;;; Specialization ;;; For Z-BROWSERS, we must update the slot-value TITLE when the name is ;;; changed ;;; (call-next-method) (if (slot-value self 'name) (setf (slot-value self 'title) (slot-value self 'name)))) (defmethod call-method-and-link ((self Z-browser) expression-to-eval) ;;; Given a selector obtained by selection in a menu, this method build the ;;; expression to call macro with-link in order to update Links and then call ;;; the macro . this method is Called by DO-SELECTED-COMMAND ;;; Updates *Z-EXPRESSION* in order to construct the spawning expression ;;; of the result later ;;; (declare (special *Z-expression*)) (loop (if (first (last expression-to-eval)) ; remove the nils at the end (return)) ; of expression-to-eval (setf expression-to-eval (butlast expression-to-eval))) (from-map expression-to-eval) ; complete the arguments (setf *Z-expression* (setf expression-to-eval (list 'with-link expression-to-eval))) (eval expression-to-eval)) (defmethod do-selected-command ((self Z-browser) command obj) ;;; ;;; Does the selected command or forwards it to the object ;;; Differs from distributed version in that the value of the command is ;;; returned and the macros can be executed as well as the functions or ;;; methods ;;; (prog (args) (if (null command) (return nil)) (if (listp command) (progn (setf args (cdr command)) (setf command (car command)))) (if (listp obj) ;; Take care of being passed in a dummy node from browser in ;; Lattice mode Dummy nodes are indicated by having the ;; object in a list (setf obj (car obj))) (push obj args) (unless (and (not (member command (slot-value self 'local-commands))) (understands obj command)) (push self args)) (push command args) (return (call-method-and-link self args))))
10,212
Common Lisp
.l
241
28.912863
104
0.535026
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
16060b2a8d113effce52b83a3f25c971062e8485762b721da7be13d45a4d1f94
33,846
[ -1 ]
33,848
Z-arrays-obs.lsp
rwoldford_Quail/source/display-network/junk/Z-arrays-obs.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) ;;; ;;; class definitions ;;; (defclass Z-string () nil) (defclass fixnum () nil) (defclass flonum () nil) (defclass string-array (ref-array) nil) (defclass float-array (ref-array) nil) (defclass boolean-array (ref-array) nil) (defclass Z-matrix (ref-array) nil) (defclass Z-scalar (ref-array) nil) (defclass Z-vector (ref-array) nil) (defclass boolean-matrix (boolean-array Z-matrix) nil) (defclass boolean-scalar (boolean-array Z-scalar) nil) (defclass boolean-vector (boolean-array Z-vector) nil) (defclass float-matrix (float-array Z-matrix) nil) (defclass float-scalar (float-array Z-scalar) nil) (defclass float-vector (float-array Z-vector) nil) (defclass string-matrix (string-array Z-matrix) nil) (defclass string-scalar (string-array Z-scalar) nil) (defclass string-vector (string-array Z-vector) nil) ;;; ;;; method definitions ;;; (defmethod descriptive-label ((self ref-array)) ;;; ;;; Construct a label describing this array for display in a browser ;;; (let ((my-name (if (get-name self) (string (get-name self)) "")) (my-class (class-name (class-of self))) (my-shape (ref-array-dimensions self))) (if (typep self 'Z-scalar) (format nil "~A ~S" my-name (as-native-object self)) (format nil "~A ~S ~S" my-name my-class my-shape)))) (defmethod Z-type ((self Z-vector)) ;;; 'vector) (defmethod mode ((self string-array)) ;;; 'string) (defmethod as-linearly-adressable-array ((self string-array)) ;;; (make-array (ref-array-total-size self) :element-type t :displaced-to (slot-value self 'the-cml-array))) (defmethod as-any-string ((self string-array)) ;;; self) (defmethod message-not-understood ((self Z-string) selector message-arguments super-flg) ;;; (apply selector (cons self (cdr message-arguments)))) (defmethod as-any-string ((self Z-string)) ;;; self) (defmethod Z-type ((self Z-scalar)) ;;; 'scalar) (defmethod as-native-object ((self Z-scalar)) ;;; (aref (slot-value self 'the-cml-array) 0)) (defmethod Z-type ((self Z-matrix)) ;;; 'matrix) (defmethod message-not-understood ((self flonum) selector message-arguments super-flg) ;;; (apply selector (cons self (cdr message-arguments)))) (defmethod as-any-float ((self flonum)) ;;; self) (defmethod na-representation ((self float-array)) ;;; ;;; Return the representation for the Not Available value for objects of this ;;; class ;;; (declare (special *ieee.not.available*)) *ieee.not.available*) (defmethod mode ((self float-array)) ;;; ;;; 'float) (defmethod as-list-of-integers ((self float-array)) ;;; (let ((na (na-representation self)) result) (dolist (x (as-list self)) (unless (eql na x) (push (round x) result))) (reverse result))) (defmethod as-linearly-adressable-array ((self float-array)) ;;; (make-array (ref-array-total-size self) :element-type 'single-float :displaced-to (slot-value self 'the-cml-array))) (defmethod message-not-understood ((self fixnum) selector message-arguments super-flg) ;;; (apply selector (cons self (cdr message-arguments)))) (defmethod as-any-float ((self fixnum)) ;;; (float self)) (defmethod as-any-float ((self float-array)) ;;; self) (defmethod na-representation ((self boolean-array)) ;;; ;;; Return the representation for the Not Available value for objects of this ;;; class ;;; (declare (special *Z.boolean.not.available*)) *Z.boolean.not.available*) (defmethod mode ((self boolean-array)) ;;; 'boolean) (defmethod as-linearly-adressable-array ((self boolean-array)) ;;; (make-array (ref-array-total-size self) :element-type t :displaced-to (slot-value self 'the-cml-array))) (defmethod as-any-boolean ((self boolean-array)) ;;; self) (defmethod Z-type ((self ref-array)) ;;; ;;; Returns the type of self ;;; 'ref-array) (defmethod reexpression ((self ref-array) fcn fn-name) ;;; ;;; Returns an array object having the same shape as self and with components ;;; obtained by applying the function fcn to the components of self ;;; (let* ((result (clone self)) (linear-result (as-linearly-adressable-array result))) (dotimes (i (ref-array-total-size result) t) (setf (aref linear-result i) (funcall fcn (aref linear-result i)))) result)) (defmethod conform-with ((self ref-array) reference) ;;; ;;; if self has higher dimensionality than reference then just return self ;;; else return an object having the same type and shape as reference and with ;;; self aproprietely replicated as its contents. ;;; (let ((ref-shape (ref-array-dimensions reference)) (self-shape (ref-array-dimensions self)) (ref-rank (ref-array-rank reference)) (self-rank (ref-array-rank self))) (if (equal self-shape ref-shape) self (if (> self-rank ref-rank) self (if (< self-rank ref-rank) (conform-with-internal self self-shape self-rank reference ref-shape ref-rank) (if (> (ref-array-total-size self) (ref-array-total-size reference)) self (if (eql (ref-array-total-size self) 1) (conform-with-internal self self-shape self-rank reference ref-shape ref-rank) (quail-error "Can't conform ~S with ~S !" (descriptive-label self) (descriptive-label reference))))))))) (defmethod clone ((self ref-array) &optional ignore-contents) ;;; ;;; Returns a new array object shaped like self and, unless ignore-contents is ;;; not NIL with same contents. ;;; (let ((the-new-object (make-instance (class-of self)))) (if ignore-contents (setf (slot-value the-new-object 'the-cml-array) (make-array (ref-array-dimensions self) :element-type (ref-array-element-type self))) (setf (slot-value the-new-object 'the-cml-array) (make-array (ref-array-dimensions self) :element-type (ref-array-element-type self) :initial-contents (as-list self)))) the-new-object)) (defmethod as-list ((self ref-array)) ;;; ;;; Returns contents of the-CML-array as a list ;;; (let ((linear-self (as-linearly-adressable-array self)) result) (dotimes (i (ref-array-total-size self)) (push (aref linear-self i) result)) (reverse result))) (defmethod ref-array-total-size ((self ref-array)) ;;; ;;; Returns the total number of elements in The-CML-Array calculated as the ;;; product of all dimensions. Note that the total size of a zero-dimensionnal ;;; array is 1.0 ;;; (array-total-size (slot-value self 'the-cml-array))) (defmethod ref-array-rank ((self ref-array)) ;;; ;;; Returns the number of dimensionsd (axes) of the-CML-Array to parallel the ;;; indexing range. this is a zero-origin number. ;;; (array-rank (slot-value self 'the-cml-array))) (defmethod ref-array-element-type ((self ref-array)) ;;; ;;; Returns a type specifier for the set of objects that can be stored in ;;; The-CML-Array ;;; (array-element-type (slot-value self 'the-cml-array))) (defmethod ref-array-dimensions ((self ref-array)) ;;; ;;; Returns a list whose elements are the dimensions of The-CML-Array ;;; (array-dimensions (slot-value self 'the-cml-array))) (defmethod ref-array-dimension ((self ref-array) axis-number) ;;; ;;; Returns the length of dimension number <axis-number> of the-CML-Array ;;; <axis-number>. ;;; Should be a non negative integer less than rank of The-CML-Array ;;; (array-dimension (slot-value self 'the-cml-array) axis-number)) (defmethod na-representation ((self string-array)) ;;; ;;; Return the representation for the Not Available value for objects of this ;;; Class ;;; (declare (special *Z.string.not.available*)) *Z.string.not.available*) (defmethod pcl::initialize-instance :after ((self float-array) &key shape init) ;;; initializes the array according to the init-list. the elements for the ;;; initialization must coerce with SINGLE-FLOAT (let (coerced-init) (if (listp init) (dolist (item init) (setq coerced-init (append coerced-init (list (coerce item 'single-float) ))))) (setf (slot-value self 'the-cml-array) (if (null init) (make-array shape :element-type 'single-float) (if (listp init) (make-array shape :element-type 'single-float :initial-contents coerced-init) (make-array shape :element-type 'single-float :initial-element (coerce init 'single-float)))) ) self)) (defmethod pcl::initialize-instance :after ((self boolean-array) &key shape init) ;;; Initializing a new Boolean Array (setf (slot-value self 'the-cml-array) (if (null init) (make-array shape :element-type t) (if (symbolp init) (make-array shape :element-type t :initial-element init) (make-array shape :element-type t :initial-contents init)))) self) (defmethod pcl::initialize-instance :after ((self string-array) &key shape init) (setf (slot-value self 'the-cml-array) (if (null init) (make-array shape :element-type t) (if (stringp init) (make-array shape :element-type t :initial-element init) (make-array shape :element-type t :initial-contents init)))) self) ;;; ;;; function definitions ;;; (defun apply-binary-op (operation arg-left arg-right &optional mode-of-result) ;;; ;;; Apply operation elementwise over the components of the conformed ;;; ref-array objects arg-left and arg-right returning a new object of mode ;;; Mode-of-result (Or Arg-Left if not supplied) ;;; (let* ((result (make-instance (class-from-mode-type arg-left mode-of-result nil) :shape (ref-array-dimensions arg-left))) (linear-left (as-linearly-adressable-array arg-left)) (linear-right (as-linearly-adressable-array arg-right)) (linear-result (as-linearly-adressable-array result))) (dotimes (i (ref-array-total-size result)) (setf (aref linear-result i) (funcall operation (aref linear-left i) (aref linear-right i)))) result)) (defun apply-ternary-op (operation arg-left arg-right arg-far-right &optional mode-of-result) ;;; ;;; Apply operation elementwise over the components of the conformed ;;; ref-array objects arg-left arg-right and Arg-far-right returning a new ;;; object of mode Mode-of-result (Or Arg-Left if not supplied) ;;; (let* ((result (make-instance (class-from-mode-type arg-left mode-of-result nil) :shape (ref-array-dimensions arg-left))) (linear-left (as-linearly-adressable-array arg-left)) (linear-right (as-linearly-adressable-array arg-right)) (linear-far-right (as-linearly-adressable-array arg-far-right)) (linear-result (as-linearly-adressable-array result))) (dotimes (i (ref-array-total-size result)) (setf (aref linear-result i) (funcall operation (aref linear-left i) (aref linear-right i) (aref linear-far-right i)))) result)) (defun c (the-list) ;;; ;;; Transform The-list into a ref-array compatible with the data that ;;; contains The-List ;;; (or (listp the-list) (setq the-list (list the-list))) (let ((common-mode (mode-of-list the-list)) (common-type (if (= (length the-list) 1) 'scalar 'vector))) ;; ;; (make-instance (class-from-mode-type nil common-mode common-type) :shape (list (length the-list)) :init the-list))) (defun class-from-mode-type (ref-array-object &optional (mode nil) (type nil)) ;;; ;;; returns the class corresponding to MODE and TYPE taking the default value ;;; of ref-array-OBJECT if not given ;;; (let ((the-mode (if mode mode (mode ref-array-object))) (the-type (if type type (Z-type ref-array-object)))) (intern (concatenate 'string (symbol-name the-mode) "-" (symbol-name the-type)) 'Z))) (defun conform-with-internal (self self-shape self-rank reference ref-shape ref-rank) ;;; ;;; Called by method CONFORM-WITH when self has smaller rank than reference. ;;; The idea is to replicate self to produce an object with the same shape as ;;; reference. Presently, only scalar self is handled (in the obvious way) .. ;;; fill an object shaped like reference with the scalar ;;; (declare (ignore ref-rank self-rank self-shape)) (if (eql (Z-type self) 'scalar) (make-instance (class-of reference) :shape ref-shape :init (as-native-object self)) (if (eql (ref-array-total-size self) 1) (make-instance (class-of reference) :shape ref-shape :init (aref ( as-linearly-adressable-array self) 0)) (quail-error "Can't conform ~S with ~S" (descriptive-label self) (descriptive-label reference))))) (defun conforming-binary-op (operation arg-left arg-right &optional mode-of-result) ;;; ;;; Conform the ref-array objects Arg-left and Arg-right then apply ;;; operation Elementwise. The Conform-With operation is a bit subtle : If the ;;; self object is not "Smaller" than the argument object, then self is ;;; returned unchanged. So, typically, only one of the two Conform-with calls ;;; bellow does any work ;;; (apply-binary-op operation (conform-with arg-left arg-right) (conform-with arg-right arg-left) mode-of-result)) (defun Z-coerce (self as-mode) ;;; ;;; Apply the method As-mode to self if it understands it ;;; (if (understands ($! self t) as-mode) (funcall as-mode ($! self t)) (quail-error "Can't coerce ~S to ~S" (if (understands self 'descriptive-label) (descriptive-label self) self) as-mode)))
17,966
Common Lisp
.l
403
30.121588
82
0.541811
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
751b94069e739bb07ba47b771ad9d80240f6dc0e55da5c9f0ae5bcb145234275
33,848
[ -1 ]
33,849
quail-object-mixins.lsp
rwoldford_Quail/source/display-network/junk/quail-object-mixins.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-object-mixins.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; Classes definitions ;;; (defclass fast-dated-object () ((created :initform (get-universal-time)) ; Internal format time of ; creation of object (creator :initform (get-user-name)) ; Username of creator of object )) (defclass initable-object-mixin () ((spawning-expression :initform nil))) (defclass body-menu-mixin () ;;; ;;; This mixin is here only to replace the methods LEFT-CHOICE and ;;; MIDDLE-CHOICE of BROWSER in quail-BROWSER ;;; ((middle-button-items :initform nil :allocation :class) ;; ;; item to be done if middleButton is selected in main Window ;; All the methods concerning MIDDLE-BUTTON-ITEMS are in ;; BODY-MENU-MIXIN ;; (generic-middle-menus :initform nil :allocation :class) ;; offer up menus specific to the class of an item which has been ;; (middle) buttoned . A single ClassVariable Generic-Middle-Menus ;; caches as an association list the menus constructed for the various ;; classes. )) (defclass documented-object-mixin () ((long-summary :initform "No summary is available on this item" :allocation :class) (reference :initform "No references are available for this item" :allocation :class) (short-summary :initform "No summary is available on this item" :allocation :class) (glossary :initform "No glossary is available for this item" :allocation :class))) (defclass editable-object-mixin (fast-dated-object initable-object-mixin) ((notes :initform nil ; (CONCATENATE 'STRING "Object ; " (OR (SLOT-VALUE SELF 'NAME) ; "") " created by " ; (SLOT-VALUE SELF 'CREATOR) " ; " (IL:GDATE (SLOT-VALUE SELF ; 'CREATED)) " using " (CAR ; (SLOT-VALUE SELF ; 'SPAWNING-EXPRESSION))) ))) (defclass find-where-mixin () nil) (defclass indexed-object-mixin () ;; Adds two methods inherited-Methods-Classification and ;; Local-Methods-Classification which produce indexes to the methods ;; available in this class nil) (defclass linked-object-mixin () ((analysis-links :initform nil) ; Forward pointer list for the ; analysis links (back-analysis-links :initform nil) ; Backward pointer list for the ; analysis links (causal-links :initform nil) ; Forward pointer list for the ; causal links (back-causal-links :initform nil) ; Backward pointer list for the ; causal links (back-data-links :initform nil) ; Backward pointer list for ; Data links : Non implemented ; yet (list-of-path-elements :initform nil) ; The path-elements associated ; with this object because the ; object has been created by ; this path-element or the path ; element has been created by ; this object )) (defclass named-object-mixin () ;;; ;;; Enables to give a name to an Object. The name must be updated using ;;; SET-NAME method exclusively. Do not change directly the slot-value because ;;; an association list *quail-object-NAME* must be updated in the same time ;;; which permits to find rapidly an object given its name ;;; An object can be found when we know its name using the macro ($ Name) ;;; which returns Object ((name :initform nil))) (defclass prompt-mixin () ;;; ;;; This class specializes the PROMPT methods of WEB-EDITOR for quail-BROWSER ;;; so that a *quail-PROMPT-WINDOW* is used for the Prompt. ;;; The place or this mixin in the inheritence list of quail-BROWSER or ;;; quail-object is important nil) (defclass title-bar-mixin () ((left-title-items :initform '(("Set package" set-package "Select a package") ("How this works" how-this-works "A brief explanation as to how this browser works." ) ("Buttoning behavior" buttoning-behavior "How the mouse works in this browser" )) :allocation :class) (middle-title-items :initform '(("Recompute" recompute "" (sub-items ("Recompute" recompute "Recompute the graph." ) ("Recompute labels" recompute-labels "Recompute the labels." ) ("In place" recompute-in-place "Recompute keeping current view in window" ) ("Shape to hold" shape-to-hold "Make window large or small enough to just hold graph" ) ("Lattice/Tree" change-format "Change format between lattice and tree" ))) ("Return to display" remove-from-bad-list "Restore item previously deleted from the display")) :allocation :class) (local-commands :initform '(buttoning-behavior how-this-works describe-contents) :allocation :class) (left-shift-button-behavior :initform "Retrieves the name of (or pointer to) the selected item" :allocation :class) (title-left-button-behavior :initform "Information on the display" :allocation :class) (title-middle-button-behavior :initform "Actions to be taken on the display" :allocation :class) (title-right-button-behavior :initform "The usual window operations" :allocation :class) (body-left-button-behavior :initform "Information on the selected object" :allocation :class) (body-middle-button-behavior :initform "Actions the selected object may take" :allocation :class) (body-right-button-behavior :initform "The usual window operations" :allocation :class) (body-left-control-button-behavior :initform "Reposition the selected object on the display" :allocation :class) (how-this-works :initform "No description is yet available" :allocation :class) (contents-description :initform "No description is yet available" :allocation :class))) (defclass tool-box-link-mixin () ((link-list :initform nil)) ; Link manager of ToolBoxes ) ;;; ;;; methods definitions ;;; (defmethod get-local-methods-classification ((self indexed-object-mixin)) (classify-local-methods (class-of self))) (defmethod get-inherited-methods-classification ((self indexed-object-mixin)) (classify-inherited-methods (class-of self) 'quail-object)) (defmethod read-notes ((self editable-object-mixin)) ;;; ;;; Read the notes recorded on this item ;;; (if (null (slot-value self 'notes)) (quail-print-help "Nothing recorded on this item yet") (edit-text (slot-value self 'notes) :read-only t))) (defmethod edit-notes ((self editable-object-mixin)) ;;; ;;; Invoke TEDIT to edit the notes on the Notes IV ;;; (setf (slot-value self 'notes) (edit-text (slot-value self 'notes)))) (defmethod add-notes ((self editable-object-mixin)) ;;; ;;; Stash user supplied note onto the Notes IV of quailObject ;;; (setf (slot-value self 'notes) (edit-text (concatenate 'string (slot-value self 'notes) " " "Edited by " (get-user-name) " " (get-universal-time) " : ")))) (defmethod references ((self documented-object-mixin) object) ; Produce a list of references ; in the litterature for this ; kind of quail-object (quail-print-help (if (slot-exists-p object 'references) (slot-value object 'references) "description not available"))) (defmethod short-summary ((object documented-object-mixin)) ; Produce a short summary of ; this kind of OBJECT (quail-print-help (if (slot-exists-p object 'short-summary) (slot-value object 'short-summary) "description not available"))) (defmethod long-summary ((object documented-object-mixin)) ; Produce a long summary of ; this kind of OBJECT (quail-print-help (if (slot-exists-p object 'long-summary) (slot-value object 'long-summary) "description not available"))) (defmethod print-summary ((self documented-object-mixin)) ; Produce a summary of ; this kind of quail-object (quail-print-help (if (slot-exists-p self 'glossary) (slot-value self 'glossary) "description not available"))) (defmethod describe-contents ((self title-bar-mixin)) ;;; ;;; Describe the content of this browser by consulting the class Value ;;; Contents-Description ;;; (quail-print-help " The content of this type of display " :font-case 'bold) (quail-print-help (slot-value self 'contents-description))) (defmethod how-this-works ((self title-bar-mixin)) ;;; ;;; Describe how this browser works by consulting the CV HOW-THIS-WORKS ;;; (quail-print-help " How this works : " :font-case 'bold) (quail-print-help (slot-value self 'how-this-works))) (defmethod buttoning-behavior ((self title-bar-mixin)) ;;; ;;; Produces some text describing the behavior of the mouse buttons in this ;;; browser by consulting the Class variables Left-shift-button-behavior, ;;; Title-Left-button-behavior, Title-Middle-button-behavior, ;;; Title-Right-button-behavior, Body-Left-button-behavior, ;;; Body-Middle-button-behavior, Body-Right-button-behavior and ;;; Body-Left-Control-Button-Behavior ;;; (quail-print-help " Mouse Button behavior Left button and Left Shift : " :font-case 'bold) (quail-print-help (slot-value self 'left-shift-button-behavior)) (quail-print-help " When in the Title bar Left Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-left-button-behavior)) (quail-print-help "Middle Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-middle-button-behavior)) (quail-print-help "Right Button : " :font-case 'bold) (quail-print-help (slot-value self 'title-right-button-behavior)) (quail-print-help " When in the body of the display Left Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-left-button-behavior)) (quail-print-help "Middle Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-middle-button-behavior)) (quail-print-help "Right Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-right-button-behavior)) (quail-print-help "Control key and left Button : " :font-case 'bold) (quail-print-help (slot-value self 'body-left-control-button-behavior))) (defmethod get-class-menu-items ((self body-menu-mixin) item-cv) ;;; ;;; Build the list necessary to construct the middle menu of an object of the ;;; body of the browser ;;; (declare (special object)) (flet ((make-menu-list (list-methods &aux result) (do ((pair list-methods (cddr pair))) ((null pair)) (push (list (first pair) (first pair) "Slide over to see methods fitting this description." (append (list 'sub-items) (second pair))) result)) result)) (let ((local-methods (make-menu-list (classify-local-methods (class-of object)))) (inherited-methods (make-menu-list (classify-inherited-methods (class-of object) 'quail-object))) item-1 item-2) (setq item-1 (if local-methods (list "Class specific methods" nil "Slide over to see methods intended specifically for this class of object" (append (list 'sub-items) local-methods)) (list "Class specific methods" nil "Slide over to see methods intended specifically for this class of object"))) (setq item-2 (if inherited-methods (list "Other methods" nil "Slide over to see methods inherited by this object from more general classes" (append (list 'sub-items) inherited-methods)) (list "Other methods" nil "Slide over to see methods inherited by this object from more general classes"))) (list item-1 item-2)))) (defmethod build-middle-menu ((self body-menu-mixin) item-cv) ;;; ;;; Method used to build a menu corresponding to a middle buttoning in the ;;; body of the window. The difference with the standard CHOICE-MENU used for ;;; the other menus is that the cached menu is seeked in Generic-middle-menus ;;; The menu is built by calling method GET-CLASS-MENU-ITEMS instead of ;;; reading the class variable MIDDLE-BUTTON-ITEMS so that the menu is ;;; automatically built according the methods defined for the class of the ;;; selected node. ;;; (declare (special object)) (prog (items (menu (assoc (class-of object) (slot-value self 'generic-middle-menus)))) (if menu (setq menu (cdr menu))) ; if menu is not NIL it ; contains the cached menu (cond ((and (slot-value self 'cache-menu-p) (menu-p menu)) ; if we have a cached menu and ; want to use it (return menu)) ((not (listp (setq items ; if we don't use the cached ; menu and can't build a ; correct one NIL is returned (get-class-menu-items self item-cv)))) (return nil))) (setq menu ; otherwise we build a new menu (make-menu :items items :when-selected-fn 'browser-when-selected-fn :when-held-fn 'browser-when-held-fn :change-offset-fn t)) (and (slot-value self 'cache-menu-p) ; and cache it if necessary (let ((my-cached-menu (assoc (class-of object) (slot-value self 'generic-middle-menus)))) (if my-cached-menu (setf (cdr my-cached-menu) menu) (push (cons (class-of object) menu) (slot-value self 'generic-middle-menus))))) (return menu) ; we eventually display the new ; menu )) (defmethod middle-choice ((self body-menu-mixin)) ;;; ;;; Make a selection from the menu build using Middle-Button-Items or ;;; Shift-middle-Button-Items ;;; (prog (menu) (setq menu (if (the-shift-key-p) (if (slot-value self 'shift-middle-button-items) (build-middle-menu self 'shift-middle-button-items) (if (understands self 'middle-shift-select) (prog nil (middle-shift-select self) (return nil)) (build-middle-menu self 'middle-button-items))) (build-middle-menu self 'middle-button-items))) (return (and menu (select-in-menu menu))))) (defmethod prompt-eval ((self prompt-mixin) msg) ;;; ;;; Specialization ;;; (eval (prompt-read self msg))) (defmethod prompt-read ((self prompt-mixin) msg) ;;; ;;; Specialization ;;; (quail-prompt-read msg)) (defmethod get-name ((self named-object-mixin)) ;;; ;;; Read the name of an object SELF. ;;; (slot-value self 'name)) (defmethod set-name ((self named-object-mixin) &optional name) ;;; ;;; Give a name to an Object. If name is NIL, ask the user for a name ;;; The Hash table *quail-object-NAMES* is updated by this method ;;; The equivalence is made on the printed name only, so that the user doesn't ;;; have to care about packages. So, the name in the equivalence variable ;;; *quail-object-NAMES* is a string ;;; (declare (special *quail-object-names*)) (or name (setq name (prompt-read self "Name to be given to this object : "))) (let ((previous-name (get-name self))) (if ($! name t) ;; ;; doesn't allow 2 objects with the same name. So if the name ;; is already used, the user is asked whether he wants to ;; remove the previous existing name he has given or he wants ;; to put another name ;; (if (member (prompt-read self (format nil "the name ~S is already used, do you want to set this name anyway (Y or N) " name)) '(y \y yes |yes|)) (setf (slot-value ($! name) 'name) nil) (progn (set-name self) (setq name nil)))) ;; (if name (progn ;; Build an empty Hash-Table if it doesn't exist yet ;; (or (boundp '*quail-object-names*) (setq *quail-object-names* (make-hash-table))) ;; ;; Update Hash-Table with new name ;; (if previous-name (remhash previous-name *quail-object-names*)) (setf (gethash name *quail-object-names*) self) ;; ;; Update Slot-name of self ;; (setf (slot-value self 'name) name))) self)) (defmethod remove-back-analysis-link ((self linked-object-mixin) linkee) ;;; ;;; Removes Linkee from Back Analysis links of self ;;; (setf (slot-value self 'back-analysis-links) (remove linkee (slot-value self 'back-analysis-links)))) (defmethod remove-forward-analysis-link ((self linked-object-mixin) linkee) ;;; ;;; Removes Linkee from Analysis links of self ;;; (setf (slot-value self 'analysis-links) (remove linkee (slot-value self 'analysis-links)))) (defmethod analysis-unlink ((self linked-object-mixin) linkee) ;;; ;;; Break an existing link between two quail Objects both directions. ;;; (remove-forward-analysis-link self linkee) (remove-back-analysis-link self linkee) (remove-forward-analysis-link linkee self) (remove-back-analysis-link linkee self)) (defmethod analysis-link ((self linked-object-mixin) linkee) ;;; ;;; Establish an Analysis Link between two quail Objects ;;; (add-forward-analysis-link self linkee) (add-back-analysis-link linkee self) linkee) (defmethod causal-link ((self linked-object-mixin) linkee) ;;; ;;; Establish a Causal Link between two quail Objects ;;; (add-forward-causal-link self linkee) (add-back-causal-link linkee self) linkee) (defmethod add-forward-analysis-link ((self linked-object-mixin) linkee) ;;; ;;; Adds linkee to Analysis-Links of self ;;; (if (not (member linkee (slot-value self 'analysis-links) :test #'eq)) (push linkee (slot-value self 'analysis-links)))) (defmethod add-forward-causal-link ((self linked-object-mixin) linkee) ;;; ;;; Adds linkee to Causal-Links of self ;;; (if (not (member linkee (slot-value self 'causal-links) :test #'eq)) (push linkee (slot-value self 'causal-links)))) (defmethod add-back-analysis-link ((self linked-object-mixin) linkee) ;;; ;;; Adds linkee to Back-Analysis-Links of self ;;; (if (not (member linkee (slot-value self 'back-analysis-links) :test #'eq)) (push linkee (slot-value self 'back-analysis-links)))) (defmethod add-back-causal-link ((self linked-object-mixin) linkee) ;;; ;;; Adds linkee to Back-Causal-Links of self ;;; (if (not (member linkee (slot-value self 'back-causal-links) :test #'eq)) (push linkee (slot-value self 'back-causal-links)))) (defmethod initialize-instance :after ((object initable-object-mixin) &key) ;;; ;;; Examines a new instance making certain that all IV's which require ;;; initialization are initialized then send the new instance the AfterInit ;;; message ;;; (init-ivs object) (after-init object) (set-anonymous-object object) (after-building object) object) (defmethod init-ivs ((self initable-object-mixin)) ;;; ;;; Initialize all IVs for this new instance whose have a Required Init . ;;; We recognize a Required init because the INITFORM has the value ;;; (REQUIRED-INIT XXX) ;;; If XXX is T then the method simply checks that an initial value was ;;; supplied to the IV (via New-With-Values). If the value of the required ;;; Init is a form or can be applied then EVAL the form or APPLY the function ;;; to determine an initial value for the IV ;;; (dolist (iv (list-required-inits (class-of self))) (if (eq (slot-value self (slot-value iv 'name)) (eval (slot-initform iv))) (let ((initializer (second (slot-initform iv)))) (setf (slot-value self (slot-value iv 'name)) (if (eq initializer t) (quail-error "Required Initialization missing for ~S" (slot-value iv 'name)) (if (listp initializer) (eval initializer) (if (functionp initializer) (funcall initializer self (slot-value iv 'name)) (quail-error "Can't initialize ~S with ~S" (slot-value iv 'name) initializer))))))))) (defmethod after-init ((self initable-object-mixin)) ;;; ;;; A method which is invoked just after creation of a new instance. This ;;; method only update Spawning Expression and return self. Specializations ;;; however should call-next-method, do some work then return Self ;;; (declare (special *quail-expression*)) ;; ;; The *quail-EXPRESSION* is updated in method CALL-METHOD-AND-LINK ;; if the new node is built using the menus of the browser. Otherwise, ;; it means that a command has been entered using the listener and the ;; *quail-EXPRESSION* can be obtained by consulting the last item of ;; the History list ;; (unless (and (boundp '*quail-expression*) (listp *quail-expression*)) (setq *quail-expression* (get-last-typed-command)) (or (listp *quail-expression*) (setq *quail-expression* (list *expression* nil)))) (setf (slot-value self 'spawning-expression) *quail-expression*) ;; we then reset *quail-EXPRESSION* for other uses (makunbound '*quail-expression*) self) (defmethod after-building ((self initable-object-mixin)) ;;; ;;; This method updates the spawning-Expression and causal-links of objects ;;; generated simultaneously with a main object ;;; (let (link) (dolist (instance-variable (set-difference (class-slots (class-of self)) (list-required-inits (class-of self)))) (when (typep (setq link (slot-value self (slot-value instance-variable 'name))) 'object) (causal-link self link) (setf (slot-value link 'spawning-expression) (slot-value self 'spawning-expression)))))) (defmethod toolbox-link ((self tool-box-link-mixin) node linkee) ;;; ;;; Establish a Toolbox link between two quail-object-CLASSES or TOOLBOXES ;;; (if (and (not (equal self node)) (not (equal linkee node)) (not (equal linkee self))) (progn (add-forward-toolbox-link self linkee node) (add-back-toolbox-link self node linkee)))) (defmethod toolbox-unlink ((self tool-box-link-mixin) node linkee) ;;; ;;; Break an existing link between two quail-objectS or TOOLBOXES - Both ;;; directions ;;; (remove-forward-toolbox-link self node linkee) (remove-back-toolbox-link self node linkee) (remove-forward-toolbox-link self linkee node) (remove-back-toolbox-link self linkee node)) (defmethod remove-forward-toolbox-link ((self tool-box-link-mixin) node linkee) ;;; ;;; removes linkee from the forward toolbox links of node ;;; (let ((links-of-node (find-link self node))) (if links-of-node (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (setq links-of-node (list (first links-of-node) (remove linkee (second links-of-node )) (third links-of-node))) (if (not (equal links-of-node (list node nil nil))) (push links-of-node (slot-value self 'link-list))))) )) (defmethod remove-back-toolbox-link ((self tool-box-link-mixin) node linkee) ;;; ;;; removes linkee from the back toolbox links of node ;;; (let ((links-of-node (find-link self node))) (if links-of-node (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (setq links-of-node (list (first links-of-node) (second links-of-node) (remove linkee (third links-of-node )))) (if (not (equal links-of-node (list node nil nil))) (push links-of-node (slot-value self 'link-list))))) )) (defmethod make-link ((self tool-box-link-mixin)) ;;; ;;; Add a new Toolbox link ;;; (let ((node-1 (prompt-read self "Node to make link from : ")) (node-2 (prompt-read self "Node to make link to : "))) (setq node-1 (or ($! node-1 t) (find-class node-1))) (setq node-2 (or ($! node-2 t) (find-class node-2))) (if (and node-1 node-2) (progn (toolbox-link self node-2 node-1) (recompute self))))) (defmethod find-link ((self tool-box-link-mixin) node) ;;; ;;; Return the element of link-list corresponding to node ;;; (let (selection) (dolist (item (slot-value self 'link-list)) (if (eq (car item) node) (return (setq selection item)))) (if selection selection (list node nil nil)))) (defmethod break-link ((self tool-box-link-mixin)) ;;; ;;; Break an existing Toolbox link ;;; (let ((node-1 (prompt-read self "Node to break link from : ")) (node-2 (prompt-read self "Node to break link to : "))) (setq node-1 (or ($! node-1 t) (find-class node-1))) (setq node-2 (or ($! node-2 t) (find-class node-2))) (if (and node-1 node-2) (progn (toolbox-unlink self node-1 node-2) (recompute self))))) (defmethod add-forward-toolbox-link ((self tool-box-link-mixin) node linkee) ;;; ;;; Adds Linkee to CADR of LinkList ;;; (let ((links-of-node (find-link self node))) (if (not links-of-node) (push (list node nil (list linkee)) (slot-value self 'link-list)) (if (not (member linkee (second links-of-node))) (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (push linkee (second links-of-node)) (push links-of-node (slot-value self 'link-list))))) )) (defmethod add-back-toolbox-link ((self tool-box-link-mixin) node linkee) ;;; ;;; Adds Linkee to CADDR of LinkList ;;; (let ((links-of-node (find-link self node))) (if (not links-of-node) (push (list node nil (list linkee)) (slot-value self 'link-list)) (if (not (member linkee (third links-of-node))) (progn (setf (slot-value self 'link-list) (remove links-of-node (slot-value self 'link-list))) (push linkee (third links-of-node)) (push links-of-node (slot-value self 'link-list))))) ))
37,288
Common Lisp
.l
734
31.194823
131
0.478444
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
28808a884e8354d5a718544730a0609a145cc87e9fd8a4159f0427ea03683cd1
33,849
[ -1 ]
33,850
Z-binops-obs.lsp
rwoldford_Quail/source/display-network/junk/Z-binops-obs.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) ;;; ;;; method definitions ;;; (defmethod Z-+ ((arg-left string-array) &optional arg-right) ;;; ;;; String concatenation ;;; (conforming-binary-op #'es.concatenate arg-left (Z-coerce arg-right 'as-any-string))) (defmethod Z-~= ((arg-left string-array) &optional arg-right) ;;; ;;; String inequality ;;; (conforming-binary-op #'es.~= arg-left (Z-coerce arg-right 'as-any-string) 'boolean)) (defmethod Z-> ((arg-left string-array) &optional arg-right) ;;; ;;; String comparison ;;; (conforming-binary-op #'es.> arg-left (Z-coerce arg-right 'as-any-string) 'boolean)) (defmethod Z-== ((arg-left string-array) &optional arg-right) ;;; ;;; String equality ;;; (conforming-binary-op #'es.= arg-left (Z-coerce arg-right 'as-any-string) 'boolean)) (defmethod Z-< ((arg-left string-array) &optional arg-right) ;;; ;;; String Comparison ;;; (conforming-binary-op #'es.< arg-left (Z-coerce arg-right 'as-any-string) 'boolean)) (defmethod Z-~= ((arg-left float-array) &optional arg-right) ;;; ;;; Not Equal predicate ;;; (conforming-binary-op #'er.~= arg-left (Z-coerce arg-right 'as-any-float) 'boolean)) (defmethod Z-^ ((arg-left float-array) &optional arg-right) ;;; ;;; Exponentiation ;;; (conforming-binary-op #'er.^ arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-rem ((arg-left float-array) arg-right) ;;; ;;; Modulus ;;; (conforming-binary-op #'er.rem arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-mod ((arg-left float-array) &optional arg-right) ;;; ;;; Integer divide ;;; (conforming-binary-op #'er.mod arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-> ((arg-left float-array) &optional arg-right) ;;; ;;; Greater than predicate ;;; (conforming-binary-op #'er.> arg-left (Z-coerce arg-right 'as-any-float) 'boolean)) (defmethod Z-== ((arg-left float-array) &optional arg-right) ;;; ;;; Equality ;;; (conforming-binary-op #'er.= arg-left (Z-coerce arg-right 'as-any-float) 'boolean)) (defmethod Z-< ((arg-left float-array) &optional arg-right) ;;; ;;; Less than predicate ;;; (conforming-binary-op #'er.< arg-left (Z-coerce arg-right 'as-any-float) 'boolean)) (defmethod Z-/ ((arg-left float-array) &optional arg-right) ;;; ;;; Division ;;; (conforming-binary-op #'er./ arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-- ((arg-left float-array) &optional arg-right) ;;; ;;; Substraction ;;; (conforming-binary-op #'er.- arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-+ ((arg-left float-array) &optional arg-right) ;;; ;;; Addition ;;; (conforming-binary-op #'er.+ arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-* ((arg-left float-array) &optional arg-right) ;;; ;;; Multiplication ;;; (conforming-binary-op #'er.* arg-left (Z-coerce arg-right 'as-any-float))) (defmethod Z-xor ((arg-left boolean-array) &optional arg-right) ;;; ;;; Logical exclusif OR ;;; (conforming-binary-op #'eb.xor arg-left (Z-coerce arg-right 'as-any-boolean))) (defmethod Z-or ((arg-left boolean-array) &optional arg-right) ;;; ;;; Logical OR ;;; (conforming-binary-op #'eb.or arg-left (Z-coerce arg-right 'as-any-boolean))) (defmethod Z-and ((arg-left boolean-array) &optional arg-right) ;;; ;;; Logical AND ;;; (conforming-binary-op #'eb.and arg-left (Z-coerce arg-right 'as-any-boolean)))
5,509
Common Lisp
.l
147
21.251701
74
0.440272
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d74c4a2885a491791cffec2e690423b3959b2ff77f2237b6993398a16eb72d7b
33,850
[ -1 ]
33,851
mixins.lsp
rwoldford_Quail/source/display-network/junk/mixins.lsp
;;; -*- Mode: LISP -*- (in-package :quail) ;;; ;;; Classes definitions ;;; ;;; ;;; methods definitions ;;;
167
Common Lisp
.l
8
12.375
24
0.542056
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3d83c9c835597cae575ccb0c0388a866c93115fd97ad7c6bf0385af71e3a45f0
33,851
[ -1 ]
33,852
Z.lsp
rwoldford_Quail/source/display-network/junk/Z.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) ;;; ;;; class definitions ;;; (defclass quail-object (prompt-mixin linked-object-mixin indexed-object-mixin editable-object-mixin named-object-mixin documented-object-mixin) ((zoom-window-cache :initform nil))) (defclass ref-array (quail-object) ;; ;; An abstract class from which instantiable Array classes inherit ;; generic behaviors ;; ((the-cml-array :initform nil) ;; ;; The array of data values is installed here once and for all when ;; the instance of the array is made. Thereafter this instance ;; variable may not be changed ;; )) (defclass memo (quail-object) nil) ;;; ;;; method definitions ;;; (defmethod zoom ((self ref-array)) ;;; ;;; Brings up Array inspector on the contents of this array. ;;; (inspect (slot-value self 'the-cml-array))) (defmethod init-ivs ((self ref-array)) ;;; ;;; Specialization ;;; self) (defmethod zoom ((self quail-object)) ;;; ;;; Zooms in on the current object by displaying it and its sub-structures in ;;; a new view. ;;; The browser is cached in self and self is deposited in the browser. This ;;; circular structure is removed by the specialized Destroy methods for ;;; quail-objectS and Microscopic-View ;;; (if (and (slot-value self 'zoom-window-cache) (understands (slot-value self 'zoom-window-cache) 'zoom)) (zoom (slot-value self 'zoom-window-cache)) (let ((zoomed-view (make-instance 'microscopic-view))) (setf (slot-value zoomed-view 'zoomed-object) self) (setf (slot-value self 'zoom-window-cache) zoomed-view) (zoom zoomed-view)))) (defmethod list-subs ((self quail-object) &optional (dont-signal-error nil)) ;;; ;;; Return a list comprised of the sub-structures of self. Invoked by a ;;; MicroView. SubClassResponsibility to provide the definitive description ;;; (if dont-signal-error nil (sub-class-responsibility self 'list-subs))) (defmethod descriptive-label ((self quail-object)) ;;; ;;; Construct a descriptive string label SuClass responsibility to specialize ;;; with more elaborate description. ;;; (let ((my-name (get-name self)) (my-class (class-name (class-of self)))) (concatenate 'string (if my-name (string my-name) " ") " " (string my-class)))) (defmethod zoom ((self memo)) ;;; ;;; Specialized to edit notes ;;; (read-notes self)) ;;; ;;; function definitions ;;; (defun mode-of-list (the-list) ;;; ;;; Determines the common type of the elements of a list in order to build an ;;; array of the correct type ;;; The different available modes are STRING, FLOAT and BOOLEAN ;;; (let ((common-mode 'i-dont-know)) (dolist (item the-list) (case common-mode (i-dont-know (cond ((or (null item) (eq item 't)) (setq common-mode 'boolean)) ((or (integerp item) (floatp item)) (setq common-mode 'float)) (t (setq common-mode 'string)))) ((boolean) (cond ((or (null item) (eq item 't)) nil) (t (setq common-mode 'string)))) ((float) (cond ((or (integerp item) (floatp item)) nil) (t (setq common-mode 'string)))) ((string) (return)))) common-mode)) (defmacro required-init (init-form) (declare (ignore init-form)) nil) (defun requires-variable (var) ;;; ;;; prompts for var ;;; (let ((result (Z-prompt-read (concatenate 'string "Enter the value for " (symbol-name var))))) (if (symbolp result) (or ($! result t) (list 'quote result)) (eval result))))
4,917
Common Lisp
.l
123
25.471545
79
0.496964
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f5bd1029a669a79a20cd273b6cdee47c102e593857604092fc79d7b5d804c911
33,852
[ -1 ]
33,854
Z-reexps-obs.lsp
rwoldford_Quail/source/display-network/junk/Z-reexps-obs.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) ;;; ;;; method definitions ;;; (defmethod Z-cos ((self float-array)) ;;; ;;; Cosine ;;; (reexpression self #'er.cos 'cos)) (defmethod Z-ceiling ((self float-array)) ;;; ;;; Least integer greater than or equal to argument ;;; (reexpression self #'er.ceiling 'ceiling)) (defmethod Z-atan ((self float-array)) ;;; ;;; Arc-tangent ;;; (reexpression self #'er.atan)) (defmethod Z-asin ((self float-array)) ;;; ;;; Arc-sine ;;; (reexpression self #'er.asin 'asin)) (defmethod Z-unary-minus ((self float-array)) ;;; ;;; -1 times the argument ;;; (reexpression self #'er.unary-minus 'unary-minus)) (defmethod Z-trunc ((self float-array)) ;;; ;;; The integer part of the argument ;;; (reexpression self #'er.trunc 'trunc)) (defmethod quail-sqrt ((self float-array)) ;;; ;;; Square root ;;; (reexpression self #'er.sqrt 'sqrt)) (defmethod Z-sin ((self float-array)) ;;; ;;; Sine ;;; (reexpression self #'er.sin 'sin)) (defmethod Z-log10 ((self float-array)) ;;; ;;; Base 10 logarithm ;;; (reexpression self #'er.log10 'log10)) (defmethod Z-log ((self float-array)) ;;; ;;; Natural logarithm ;;; (reexpression self #'er.log 'log)) (defmethod Z-lgamma ((self float-array)) ;;; ;;; The natural log of the Gamma function of the argument ;;; (reexpression self #'er.lgamma 'lgamma)) (defmethod Z-gamma ((self float-array)) ;;; ;;; The Gamma function applied to the arguments ;;; (reexpression self #'gamma 'gamma)) (defmethod Z-floor ((self float-array)) ;;; ;;; Greater integer less than or equal to the argument. ;;; (reexpression self #'er.floor 'floor)) (defmethod Z-exp ((self float-array)) ;;; ;;; Exponentiate the arguments ;;; (reexpression self #'er.exp 'exp)) (defmethod Z-acos ((self float-array)) ;;; ;;; Arc-Cosine ;;; (reexpression self #'er.acos 'acos)) (defmethod Z-abs ((self float-array)) ;;; ;;; Absolute value ;;; (reexpression self #'er.abs 'abs)) (defmethod Z-! ((self boolean-array)) ;;; ;;; Logical NOT ;;; (reexpression self #'eb.not '!))
2,553
Common Lisp
.l
90
21.1
58
0.609528
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7f23d414511263559ebed8ebde4b7af8e57f20703eadea8e1b53130287264873
33,854
[ -1 ]
33,855
extended-ops-obs.lsp
rwoldford_Quail/source/display-network/junk/extended-ops-obs.lsp
;;; -*- Mode: LISP -*- (in-package 'Z) (defvar *Z.boolean.not.available* 'NA) (defvar *ieee.not.available* -9999.99) (defvar *Z.string.not.available* "Not Available") ;;; ;;; function definitions ;;; (defun eb.and (x y) (declare (special *Z.boolean.not.available*)) (if (or (eq x *Z.boolean.not.available*) (eq y *Z.boolean.not.available*)) *Z.boolean.not.available* (and x y))) (defun eb.not (x) (declare (special *Z.boolean.not.available*)) (if (eq x *Z.boolean.not.available*) *Z.boolean.not.available* (not x))) (defun eb.or (x y) (declare (special *Z.boolean.not.available*)) (if (or (eq x *Z.boolean.not.available*) (eq y *Z.boolean.not.available*)) *Z.boolean.not.available* (or x y))) (defun eb.xor (x y) (declare (special *Z.boolean.not.available*)) (if (or (eq x *Z.boolean.not.available*) (eq y *Z.boolean.not.available*)) *Z.boolean.not.available* (or (and x (not y)) (and (not x) y)))) (defun er.* (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (* x y))) (defun er.+ (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (+ x y))) (defun er.- (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (- x y))) (defun er./ (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*) (equal y 0.0)) *ieee.not.available* (/ x y))) (defun er.< (x y) (declare (special *ieee.not.available* *Z.boolean.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *Z.boolean.not.available* (< x y))) (defun er.= (x y) (declare (special *ieee.not.available* *Z.boolean.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *Z.boolean.not.available* (equal x y))) (defun er.> (x y) (declare (special *ieee.not.available* *Z.boolean.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *Z.boolean.not.available* (> x y))) (defun er.abs (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (abs x))) (defun er.acos (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (> (abs x) 1.0)) *ieee.not.available* (acos x))) (defun er.asin (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (> (abs x) 1.0)) *ieee.not.available* (asin x))) (defun er.atan (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (atan x))) (defun er.ceiling (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (fceiling x))) (defun er.cos (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (cos x))) (defun er.exp (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (> (abs x) 180.0)) *ieee.not.available* (exp x))) (defun er.floor (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (ffloor x))) (defun er.log (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (not (> x 0.0))) *ieee.not.available* (log x))) (defun er.log10 (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (not (> x 0.0))) *ieee.not.available* (log x 10))) (defun er.mod (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (float (mod x y)))) (defun er.qgauss (p &optional (center 0.0) (scale 1.0)) (declare (special *ieee.not.available*)) (if (or (eql p *ieee.not.available*) (eql center *ieee.not.available*) (eql scale *ieee.not.available*) (not (> p 0.0)) (not (> 1.0 p))) *ieee.not.available* (+ center (* scale (qgauss p))))) (defun er.random (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (+ x (random (- y x))))) (defun er.rem (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (mod x y))) (defun er.rgauss (&optional (center 0.0) (scale 1.0)) (declare (special *ieee.not.available*)) (if (or (eql center *ieee.not.available*) (eql scale *ieee.not.available*)) *ieee.not.available* (let (v1 v2 (s 2.0)) (do nil ((< s 1.0)) (setq v1 (- (random 2.0) 1.0)) (setq v2 (- (random 2.0) 1.0)) (setq s (+ (* v1 v1) (* v2 v2)))) (+ center (* scale v1 (sqrt (/ (* -2.0 (log s)) s))))))) (defun er.sin (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (sin x))) (defun er.sqrt (x) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (< x 0.0)) *ieee.not.available* (sqrt x))) (defun er.trunc (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (float (truncate x)))) (defun er.unary-minus (x) (declare (special *ieee.not.available*)) (if (eq x *ieee.not.available*) *ieee.not.available* (- x))) (defun er.^ (x y) (declare (special *ieee.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *ieee.not.available* (if (< x 0.0) (if (not (eql y (float (truncate y)))) *ieee.not.available* (expt x (truncate y))) (expt x y)))) (defun er.~= (x y) (declare (special *ieee.not.available* *Z.boolean.not.available*)) (if (or (eq x *ieee.not.available*) (eq y *ieee.not.available*)) *Z.boolean.not.available* (not (eql x y)))) (defun es.< (x y) (declare (special *Z.string.not.available* *Z.boolean.not.available*)) (if (or (eq x *Z.string.not.available*) (eq y *Z.string.not.available*)) *Z.boolean.not.available* (string< x y))) (defun es.= (x y) (declare (special *Z.string.not.available* *Z.boolean.not.available*)) (if (or (eq x *Z.string.not.available*) (eq y *Z.string.not.available*)) *Z.boolean.not.available* (string= x y))) (defun es.> (x y) (declare (special *Z.string.not.available* *Z.boolean.not.available*)) (if (or (eq x *Z.string.not.available*) (eq y *Z.string.not.available*)) *Z.boolean.not.available* (string> x y))) (defun es.concatenate (x y) (declare (special *Z.string.not.available*)) (if (or (eq x *Z.string.not.available*) (eq y *Z.string.not.available*)) *Z.string.not.available* (concatenate 'string x y))) (defun es.~= (x y) (declare (special *Z.string.not.available* *Z.boolean.not.available*)) (if (or (eq x *Z.string.not.available*) (eq y *Z.string.not.available*)) *Z.boolean.not.available* (not (string= x y)))) (defun qgauss (p) ;;; ;;; Rational approximation to the Gaussian inverse distribution function. ;;; Return Xp s.t. P{quail<= Xp} = P Abramowitz and Stegun 26.3.23 ;;; (setq p (float p)) (if (or (> p 1.0) (< p 0.0)) (quail-error "Illegal argument ~S" p) (prog (pp tt num denom xp) (setq pp (if (< p 0.5) p (- 1.0 p))) (setq tt (sqrt (* -2.0 (log pp)))) (setq num (+ (* (+ (* 0.010328 tt) 0.802853) tt) 2.515517)) (setq denom (+ (* (+ (* (+ (* 0.001308 tt) 0.189269) tt) 1.432788) tt) 1.0)) (setq xp (- tt (/ num denom))) (return (if (< p 0.5) (- xp) xp)))))
10,565
Common Lisp
.l
283
24.367491
74
0.456125
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
39a7b6a9aebce0d02c749723298b2dd1ed1a2f8be1359f5120f868140895066c
33,855
[ -1 ]
33,856
Quail-utility.lsp
rwoldford_Quail/source/display-network/junk/Quail-utility.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-utility.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988 - 1989 ;;; R.W. Oldford 1985 - 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail) ;;; ;;; this file adds some methods to PCL objects and defines some other ;;; utility functions ;;; ;;; ;;; package definitions ;;; (import '(specific:push-in-buffer quail-mop:direct-subclasses quail-mop:direct-superclasses quail-mop:class-p quail-mop:class-slots quail-mop:direct-methods )) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(list-slot-contents! direct-subclasses direct-superclasses class-p class-slots direct-methods classify-local-methods classify-inherited-methods classify-combined-methods should-not-implement slot-initarg slot-initform sub-class-responsibility list-required-inits descriptive-label get-name class-understands required-init *quail-methods-classification* $ $! get-mc))) (defvar *quail-methods-classification* nil) ;;; ;;; method definitions related to PCL objects ;;; (defmethod list-slot-contents! ((self standard-class) slot &optional verbose-flg (sub-classes nil)) ;;; ;;; returns the list of the contents of the slot SLOT concatenated with the ;;; contents of the slots SLOT of ;;; - the supers of SELF recursively if SUB-CLASSES is NIL ;;; - the sub-classes of SELF recursively if SUB-CLASSES is not NIL ;;; Omit content of STANDARD-OBJECT and STANDARD-CLASS unless Verbose-flg is T ;;; (let ((result nil) value) ;; ;; we bind Value with the Slot-value SLOT of self and transforme ;; it in a List ;; (or (listp (setf value (slot-value self slot))) (setf value (list value))) ;; ;; we then push each element of this list which isn't already in ;; result ;; (dolist (element value) (or (member element result) (push element result))) ;; ;; we call this method recursively for each super of SELF or its ;; SUB-CLASSES depending on the value of SUB-CLASSES ;; (dolist (super-or-subs (if sub-classes (class-direct-subclasses self) (class-direct-superclasses self))) (unless (or verbose-flg (member super-or-subs (list (find-class 'standard-class) (find-class 'standard-object)))) (setf result (append result (list-slot-contents! super-or-subs slot verbose-flg sub-classes))))) ;; ;; Here is the result of the method ;; result)) (defmethod classify-local-methods ((self standard-class) &optional (stop-list nil)) "Index the methods of this class according to their Method-classification ~ property. The result is a propList style list of pairs <Classification> ~ <List of methods so classified>. ~ The classification of methods is stored in global variable ~ *quail-methods-classification*." (let (result classification characteristics) (dolist (method (class-direct-methods self)) (when (setf characteristics (get-mc method)) (setf classification (second characteristics)) (setf (getf result classification) (push (list (third characteristics) (first characteristics) "") (getf result classification))))) result)) (defmethod classify-inherited-methods ((self standard-class) &optional (stop-list nil) (allowed-classes nil)) ;;; ;;; Index the methods of the Supers of this Class according to their ;;; Method-Classification property. The Result is a propList style List of ;;; pairs <Classification> <list of methods so classified> ;;; When called by the user, Allowed-classes is usually NIL but it is used to ;;; save time in the recursion by the method itself ;;; (declare (special Quail:*quail-methods-classification*)) (flet ((list-understands (list-of-objects method) ;; ;; Returns T if method is understood by all the elements ;; of LIST-OF-OBJECTS ;; Returns NIL if one element doesn't understand method ;; (unless (listp list-of-objects) (setf list-of-objects (list list-of-objects))) (dolist (object list-of-objects t) (if (not (class-understands (find-class object) method)) (return nil)))) ;;; (list-not-understands (list-of-objects method) ;; ;; Returns T if method isn't understood by all elements ;; of LIST-OF-OBJECTS ;; Returns NIL if one element understands method ;; (unless (listp list-of-objects) (setf list-of-objects (list list-of-objects))) (dolist (object list-of-objects t) (if (class-understands (find-class object) method) (return nil))))) ;;; (let (result) (dolist (x *quail-methods-classification*) (if (and (class-understands self (first x)) (list-not-understands stop-list (first x)) (list-understands allowed-classes (first x))) (setf (getf result (second x)) (push (list (third x) (first x) "") (getf result (second x)))))) result))) (defmethod should-not-implement ((self t) selector) "A do nothing method used to void specified inherited methods. The method ~ Should-not-implement produces an error if actually invoked." (quail-error "~S is not implemented for the class : ~S" selector (class-name (class-of self)))) (defmethod sub-class-responsibility ((self t) selector) "This method indicates that the implementation of the method given by ~ selector depends on the subclass, even though, abstractly, it is a method ~ of some generic class. The method Sub-Class-Responsibility produces an ~ error if actually invoked." (quail-error "~S must be specialized for ~S" selector (class-name (class-of self)))) (defmethod list-required-inits ((self standard-class) &optional (stop-list NIL)) "Returns a list of those variables which require initialization." (let (forbidden-ivs result) ;; ;; Compute undesirable IVs ;; (dolist (class (if (listp stop-list) stop-list (list stop-list))) (dolist (iv (class-slots class)) (when (and (not (member iv forbidden-ivs)) (listp (slot-initform iv)) (equal (first (slot-initform iv)) 'required-init)) (push iv forbidden-ivs)))) ;; ;; Compute IV to init which are not undesirable ;; (dolist (iv (class-slots self)) (when (and (not (member iv forbidden-ivs)) (listp (slot-initform iv)) (equal (first (slot-initform iv)) 'required-init)) (push iv result))) result)) (defmethod descriptive-label ((self standard-class)) "Construct a descriptive string label." (get-name self)) (defmethod get-name ((self standard-class)) "Read the name of the object." (class-name self)) (defmethod class-understands ((self standard-class) selector) ; Returns NIL if instances of ; SELF doesn't understand the ; method SELECTOR, T otherwise (if (generic-function-p selector) (let (result) (dolist (super (class-precedence-list self)) (when (get-method (symbol-function selector) nil (list super) nil) (setf result t) (return))) result) nil)) (defmethod zoom ((self standard-class)) (inspect self)) ;;; ;;; other functions ;;; (defun slot-initarg (slot) "Return the initarg of slot." (first (slot-value slot 'initargs))) (defun slot-initform (slot) "Return the initform of slot." (slot-value slot 'initform)) (defmacro $ (name) "Find a quail object by giving its name." (declare (special *quail-object-names*)) `(let ((result (if (boundp '*quail-object-names*) (gethash ',name *quail-object-names*)))) (or result (quail-error "No Object named ~S" ',name)))) (defun $! (name &optional no-error-flg) ;;; ;;; Returns the object whose name is the value of NAME if it is a symbol ;;; If NAME is a list, we look for the evaluation of this list ;;; if NAME is an object, it is returned ;;; This is done by consulting the Hash table *quail-object-NAMES* which is ;;; updated every time SET-NAME is called ;;; IF NO-ERROR-FLG is T and no object is named NAME, NIL is returned instead ;;; of an error ;;; (declare (special *quail-object-names*)) (if (listp name) (setf name (eval name))) (if (typep name 'standard-object) name (let ((result (if (boundp '*quail-object-names*) (gethash name *quail-object-names*)))) (if name (or result (if no-error-flg nil (quail-error "No object named ~S" name))))))) (defun get-mc (method) "MC stands for Method Classification. ~ Returns the value of the Property CLASSIFICATION of method by looking in ~ global variable *quail-methods-classification*." (declare (special Quail:*quail-methods-classification*)) (if (symbolp method) (assoc method Quail:*quail-methods-classification*) (let ((name (slot-value (slot-value method 'generic-function) 'name))) (if (symbolp name) (assoc name Quail:*quail-methods-classification*))))) (defun add-function-in-menu (function name-in-menu classification &rest args) "Make a function callable by menu. ~ The second argument, name-in-menu, is the name which will be printed ~ for function in menu ~ classification enables to create a one level hierarchy ~ args is the list of compulsory arguments to the function." (declare (special *quail-methods-classification*)) (push (list function classification name-in-menu args) *quail-methods-classification*)) ;;; ;;; How to make a function callable from a menu ;;; you just have to call the function add-function-in-menu and give ;;; as arguments the name of the function (with package if not in Quail) ;;; the label you want to appear in the menu ;;; the classification, which enables you to create a hierarchy in menus ;;; the compulsory parameters, which the user will be asked to complete ;;; if they are unknown when the function is called (add-function-in-menu #'in-view "in view" '|Objects in this view| 'self) (add-function-in-menu #'in-view! "in view!" '|Objects in this view| 'self) (add-function-in-menu #'widen-view "widen view" '|Widen this view| 'self) (add-function-in-menu #'add-forward-analysis-link "add forward analysis link" 'Link-operators 'self 'linkee) (add-function-in-menu #'analysis-link "analysis link" 'Link-operators 'self 'linkee) (add-function-in-menu #'analysis-unlink "analysis unlink" 'Link-operators 'self 'linkee) (add-function-in-menu #'remove-back-analysis-link "remove back analysis-link" 'Link-operators 'self 'linkee) (add-function-in-menu #'remove-forward-analysis-link "remove forward analysis-link" 'Link-operators 'self 'linkee) (add-function-in-menu 'and "and" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu 'or "or" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu 'xor "xor" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'* "*" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'+ "+" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'- "-" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'/ "/" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'< "<" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'= "=" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'> ">" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu #'mod "mod" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'rem "rem" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu '^ "^" 'binary-operation 'arg-left 'arg-right) (add-function-in-menu #'/= "/=" 'binary-comparison 'arg-left 'arg-right) (add-function-in-menu '! "!" 'reexpression 'self) (add-function-in-menu #'abs "abs" 'reexpression 'self) (add-function-in-menu #'acos "acos" 'reexpression 'self) (add-function-in-menu #'exp "exp" 'reexpression 'self) (add-function-in-menu #'expt "expt" 'reexpression 'self 'exponent) (add-function-in-menu #'floor "floor" 'reexpression 'self) ;;(add-function-in-menu #'gamma "gamma" 'reexpression 'self) ;;(add-function-in-menu #'lgamma "lgamma" 'reexpression 'self) (add-function-in-menu #'log "log" 'reexpression 'self) (add-function-in-menu #'log "log base a" 'reexpression 'self 'a) (add-function-in-menu #'sin "sin" 'reexpression 'self) (add-function-in-menu #'sqrt "sqrt" 'reexpression 'self) ;;(add-function-in-menu #'trunc "trunc" 'reexpression 'self) ;;(add-function-in-menu #'unary-minus "unary minus" 'reexpression 'self) (add-function-in-menu #'asin "asin" 'reexpression 'self) (add-function-in-menu #'atan "atan" 'reexpression 'self) (add-function-in-menu #'ceiling "ceiling" 'reexpression 'self) (add-function-in-menu #'cos "cos" 'reexpression 'self) (add-function-in-menu #'add-analysis-node "add analysis node" '|Widen this view| 'self '|new analysis node|)
16,650
Common Lisp
.l
343
34.816327
86
0.547879
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a1f7185758086133fd7a76f9d858e46d283b55837b0ffe7ba67417eb4ca7de04
33,856
[ -1 ]
33,857
quail-package.lsp
rwoldford_Quail/source/quail/quail-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1992. ;;; R.W. Oldford 1992. ;;; ;;;---------------------------------------------------------------------------- #+:cl-2 (defpackage "QUAIL" (:use "VIEWS" "NEW-MATH" "QUAIL-KERNEL" "COMMON-LISP") (:SHADOWING-IMPORT-FROM "NEW-MATH" "ARRAY-ELEMENT-TYPE" "ARRAY-RANK" "ARRAY-DIMENSION" "ARRAY-DIMENSIONS" "ARRAY-TOTAL-SIZE" "ARRAY-IN-BOUNDS-P" "ADJUSTABLE-ARRAY-P" "ARRAY-ROW-MAJOR-INDEX" "SORT" "+" "-" "*" "/" "FLOAT" "RATIONAL" "RATIONALIZE" "<" "<=" "=" ">" ">=" "MIN" "MAX" "EXP" "SQRT" "ISQRT" "ABS" "PHASE" "SIGNUM" "SIN" "COS" "TAN" "CIS" "ASIN" "ACOS" "ATAN" "SINH" "COSH" "TANH" "ASINH" "ACOSH" "ATANH" "NUMERATOR" "DENOMINATOR" "REALPART" "IMAGPART" "FLOOR" "CEILING" "TRUNCATE" "ROUND" "FFLOOR" "FCEILING" "FTRUNCATE" "FROUND" "COMPLEX" "EXPT" "LOG" "REM" "MOD" "GCD" "LCM" "CONJUGATE" "LOGIOR" "LOGXOR" "LOGAND" "LOGEQV" "LOGNAND" "LOGNOR" "LOGANDC1" "LOGANDC2" "LOGORC1""LOGORC2" "LOGNOT" "LOGTEST" "LOGBITP" "ASH" "LOGCOUNT" "INTEGER-LENGTH" "BOOLE") ;(:IMPORT-FROM "QUAIL-KERNEL" "<-") ;(:IMPORT-FROM "VIEWS" "ROTATING-PLOT") ; 05 FEB 2020 (:nicknames "Q") ) #-:cl-2 (in-package "QUAIL" :use '(new-math quail-kernel pcl lisp) :nicknames '(q))
2,273
Common Lisp
.l
50
29.48
85
0.35724
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1da26b5c7392d380e9df1079746ff6fb1ae257281e12676c524cade1cf0095f3
33,857
[ -1 ]
33,858
doc-utility.lsp
rwoldford_Quail/source/documentation/doc-utility.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-utility.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(documentable-uses destring string-downcase-object string-downcase-list string-first-n...))) ;;;--------------------------------------------------------------------------- ;;; ;;; Miscellaneous utility functions for making documentation. ;;; ;;;--------------------------------------------------------------------------- ;;;----------------------------------------------------------------------------- ;;; ;;; Uses of a symbol to be documented. ;;; ;;;----------------------------------------------------------------------------- (defun documentable-uses (sym &optional package) "Returns the list of documentable uses of this symbol in the package ~ (if specified). ~ For example as a variable, a class name, a function, a macro, et cetera." (let ((uses '())) (if sym ;; then process it if we find it (and (setf sym (if package (find-symbol (string sym) package) (find-symbol (string sym)))) (progn (if (eql :function (function-information sym)) (cond ((generic-function-p (symbol-function sym)) (push :generic-function uses) ) (T (push :function uses))) ) (if (eql :macro (function-information sym)) (push :macro uses)) (if (eql :special-form (function-information sym)) (push :special-form uses)) (if (eql :special-operator (function-information sym)) ;27oct05 (push :special-operator uses)) ;27oct05 (if (and (boundp sym) (constantp sym)) (push :constant uses)) (if (and (boundp sym) (not (constantp sym))) (push :variable uses)) (if (get sym :topic NIL) (push :topic uses)) (if (find-package sym) (push :package uses)) (cond ((structure-p sym) (push :structure uses)) ((built-in-class-p sym) (push :built-in-class uses)) ((find-class sym nil) (push :class uses)))) ) ;; else NIL is a constant (push :constant uses)) uses)) (defun list-names-of-docs (doc-list) "Returns a list of the names of the documents given in the argument doc-list. ~ Duplicates are removed." (if (listp doc-list) (remove-duplicates (loop for d in doc-list collect (name d))) (list (name doc-list)))) (defun symbol-from-doc (doc) "Returns the symbol to which the argument, a documentation-object object, ~ is attached." (find-symbol (name doc) (package doc))) ;;;------------------------------------------------------------------------------------- ;;; ;;; Some handy string utility functions. ;;; ;;; ;;;------------------------------------------------------------------------------------ (defun destring (string) "Reads and returns the first item in the string." (with-input-from-string (s string) (read s))) (defun string-downcase-object (object) "Returns the downcased string of the argument print name." (string-downcase (format NIL "~a" object))) (defun string-downcase-list (list-of-objects) "Returns a list of the downcased elements of the given list of objects." (loop for object in list-of-objects collect (if (listp object) (string-downcase-list object) (string-downcase-object object)))) (defun string-first-n... (string &optional (n 50)) "Returns a string of characters of length no greater than the value ~ of the second optional argument n. ~ The result is either the value of the input string (if the string ~ has n or fewer characters) or it is a string containing the first ~ n-3 elements of the input string and ... as its last three elements." (if (<= (length string) n) string (concatenate 'string (subseq string 0 (- n 4)) "..."))) ;;;------------------------------------------------------------------------------------
4,687
Common Lisp
.l
112
34.633929
115
0.488192
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e87ebafebf87ba1c74d2d13b7d507a6e5b513bf3ef1777adcfcd8d340bbe3ade
33,858
[ -1 ]
33,859
doc-tex-index.lsp
rwoldford_Quail/source/documentation/doc-tex-index.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-tex-index.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1990 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-tex-doc-from-index))) (defun make-tex-doc-from-index (index-file &key (destination nil) (documenttype 'article) (documentstyles '(fullpage)) (point-size 10) (input-files nil)) "Constructs a TeX file from a sorted documentation index file~ The result is stored in the index.tex file in the documentation ~ directory." (declare (special tex-doc-style)) (setf documentstyles (concatenate 'list (list (format nil "~apt" point-size)) documentstyles tex-doc-style)) (if (null destination) (setf destination (concatenate 'string (directory-namestring index-file) "index.tex"))) (with-open-file (ifile index-file :direction :input :if-does-not-exist nil) (with-open-file (ofile destination :direction :output :if-does-not-exist :create) ;; ;; Set up the header of the document. ;; (format ofile "~&\\documentstyle") (write-tex-args ofile documentstyles) (format ofile "{~a}" documenttype) (format ofile "~&\\begin{document}") ;; ;; Set up the input files ;; (when input-files (if (not (listp input-files)) (setf input-files (list input-files))) (loop for file in input-files do (format ofile "~&\\input{~a}" file))) (do* ((i (read ifile nil nil) (read ifile nil nil)) (j (read ifile nil nil) (read ifile nil nil)) (current-doc-type j)) ((or (null i) ( null j)) (format ofile "~&\\end{document}")) (when (not (eql current-doc-type j)) (setf current-doc-type j) (format ofile "~&\\newpage")) (write-tex-header-box ofile :left i :right j)) ))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Some examples ;;; ;;; #| (make-tex-doc-from-index "melewis:quail:doc-index.lisp") |#
3,007
Common Lisp
.l
80
26.1625
92
0.435657
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
69344a20f528cd08aa2b886a4edcbbc3f07bdb4d5fd18199eb162ad2f45bd757
33,859
[ -1 ]
33,860
install-topics.lsp
rwoldford_Quail/source/documentation/install-topics.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; install-topics.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(install-topics load-topics make-?-topic ensure-loaded-topics load-topics-file topics-file-to-topic-files export-topic-syms))) (defun load-topics (&key package symbol-list) "Loads the topic documentation (if any) ~ for all external symbols given by the ~ keyword package or only those specified ~ by the keyword symbol-list." (if symbol-list (if package (loop for sym in symbol-list do (setf sym (find-symbol (string sym) package)) (if sym (doc sym :topic)) (vw::inform-user-busy)) (loop for sym in symbol-list do (doc sym :topic) (vw::inform-user-busy))) (do-external-symbols (sym package) (doc sym :topic) (vw::inform-user-busy)) ) (vw:inform-user "Topics Loaded")) (let ((already-loaded? NIL)) (defun ensure-loaded-topics (&key package symbol-list) (declare (special *quail-terminal-io*)) (unless already-loaded? (vw::inform-user (format NIL "~&~%OK, I have to load some topic information.~%~ This may take a while ... ~%~ The good news is that I will eventually finish and ~%~ I only have to do it once.~%")) (load-topics :package package :symbol-list symbol-list) (setf already-loaded? T))) ) (defun install-topics (&key package symbol-list) "Installs the topic documentation (if any) ~ as a super-topic of all its sub-topics. ~ Which topics to be installed are specified by the values ~ of the keyword parameters package and symbol-list. If only the package is specified, then all external symbols ~ having a value for (doc symbol \:topic ) are installed. ~ Otherwise only the symbols on the symbol-list which are in ~ the package (if specified) are installed." (flet ((install-topic (topic) (if topic (loop for st in (sub-topics topic) do (install-super-topic topic st))))) (if symbol-list (if package (loop for sym in symbol-list do (setf sym (find-symbol (string sym) package)) (if sym (install-topic (doc sym :topic)))) (loop for sym in symbol-list do (install-topic (doc sym :topic)))) (do-external-symbols (sym package) (install-topic (doc sym :topic))) ) "Topics Installed")) (defun make-?-topic (package &optional topics) "Creates the topic documentation for the ? symbol in the given package. ~ If a list of topics are specified as the value of the optional argument ~ topics, then these topics are installed as the sub-topics of the general ~ question-mark topic. ~ If topics are not specified, then all symbols in this package which have ~ topic documentation on them and are themselves not the sub-topic of another ~ topic are included as sub-topics of the question-mark topic." (let* ((question-mark-sym (find-symbol "?" package)) (question-mark-topic (doc question-mark-sym :topic)) ;; The following is pretty ugly, but easy. (do-something? T)) (if question-mark-topic ;;then ;; Should it be used or not? (if (not (quail-yes-or-no-p "Topic documentation for the question-mark already exists in the package ~a ! ~ Do you want to add to it? " (package-name package))) ;; then (if (quail-yes-or-no-p "Do you want to over-ride the existing documentation and create a new topic? ") ;; then ;; make a new one and set it. (setf question-mark-topic (setf (doc question-mark-sym :topic) (make-doc question-mark-sym :topic))) ;;else ;; We're not going to do anything. (setf do-something? NIL)) ;; no else, use the topic we found. ) ;;else (setf question-mark-topic (setf (doc question-mark-sym :topic) (make-doc question-mark-sym :topic)))) ;; now blow out or do something (when do-something? (let (current-topic) (if topics ;; then (loop for sym in topics when (setf current-topic (doc sym :topic)) do (install-sub-topic question-mark-topic current-topic) ) (do-external-symbols (sym package) (setf current-topic (doc sym :topic)) (if (and ;; we have a topic current-topic ;; and it isn't known to be a sub-topic of something else (not (super-topics current-topic))) ;; then we'll take it (install-sub-topic question-mark-topic current-topic))))) (if (null (doc-capsule question-mark-topic)) (setf (doc-capsule question-mark-topic) (format nil "General help topic for the package ~a. See the sub-topics for ~ information on various areas." (package-name package)))) (if (null (doc-elaboration question-mark-topic)) (setf (doc-elaboration question-mark-topic) (format nil "The sub-topics listed below contain information on different topics. ~ This information can be accessed on any sub-topic by invoking the help ~ command on the symbol that names it."))) ) ) NIL) (defun load-topics-file (filename &optional (package :quail)) (with-open-file (ofile filename :direction :input) (let ((topic (read ofile nil nil)) name sub-topics) (loop while topic do (setf name (first topic)) (setf sub-topics (second topic)) (setf (doc name :topic) (make-instance 'qk::topic-documentation :name (format nil "~a" name) :sub-topics sub-topics :package package )) (setf topic (read ofile nil nil)))))) (defun topics-file-to-topic-files (filename &optional (package :quail)) (declare (special *user-doc-out-path-function*)) (let* ((ofile-fun (if (functionp *user-doc-out-path-function*) *user-doc-out-path-function* #'doc-auto-path-name)) (the-package (find-package package)) ;(package-use-list (package-use-list package)) ; 30JUL2023 ;(package-used-by-list (package-used-by-list package)) ; 30JUL2023 symbol-package) (with-open-file (ifile filename :direction :input) (let ((topic (read ifile nil nil)) name sub-topics) (loop while topic do (setf symbol-package (symbol-package (first topic))) ;;(unless (or (eql the-package symbol-package) ;; (member symbol-package package-use-list)) ;; (format *quail-terminal-io* "~&Topic = ~s" topic) (format *quail-terminal-io* "~&name = ~s" (first topic)) (format *quail-terminal-io* "~&symbol-package = ~s" symbol-package) ;; (format *quail-terminal-io* "~&package-use-list = ~s~%~%" package-use-list) ;; (import (first topic) the-package)) ;;(unless (member symbol-package package-used-by-list) ;; (eval-when (:compile-toplevel :load-toplevel :execute) (export (first topic) the-package))) (setf name (first topic)) (setf sub-topics (second topic)) (setf (doc name :topic) (make-instance 'qk::topic-documentation :name (format nil "~a" name) :sub-topics sub-topics :package (package-name the-package) )) (with-open-file (ofile (funcall ofile-fun name :topic) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~&(setf (doc '~a :topic)~%" name) (write-doc ofile (doc name :topic)) (format ofile "~&)~%")) (setf topic (read ifile nil nil))))))) (defun export-topic-syms (&key (package :quail) symbol-list) "Exports from the specified package (default :quail) ~ either all symbols, or only those appearing in symbol-list, which ~ have topic documentation attached to them." (flet ((topic-p (s) (member :topic (documentable-uses s package)))) (if symbol-list (loop for sym in symbol-list when (topic-p sym) do (unless (eq (find-package package) (symbol-package sym)) (import sym package)) (eval-when (:compile-toplevel :load-toplevel :execute) (export sym package))) (do-all-symbols (sym package) (when (topic-p sym) (when (eq (find-package package) (symbol-package sym)) (import sym package)) (eval-when (:compile-toplevel :load-toplevel :execute) (export sym package)))) )) )
10,104
Common Lisp
.l
241
30.962656
125
0.549657
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f036d5a4f0a0f6b66574fc4be4efc1c253746c7ef0a76e673f67d18084eecf49
33,860
[ -1 ]
33,861
doc-vars.lsp
rwoldford_Quail/source/documentation/doc-vars.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-vars.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; r.w. oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- ;;;---------------------------------------------------------------------------- ;;; ;;; A collection of useful constants and variables. ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (defconstant *CLtL* "Guy L. Steele, Jr. (1990) \"Common Lisp: The Language (second edition).\" ~ Digital Press." "Most recent reference for the language definition of Common Lisp.")
938
Common Lisp
.l
25
33.68
80
0.317127
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a33a4b5bec192710d946458cb45b31d41313e1e0276b3a8f75d166d4512c1610
33,861
[ -1 ]
33,862
doc-type.lsp
rwoldford_Quail/source/documentation/doc-type.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-type.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1991 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991, 1992 ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(quail-doc-types quail-doc-classes doc-type-p))) ;;;--------------------------------------------------------------------------- ;;; ;;; Dictionary functions, for looking up documentation types and classes ;;; based on Common Lisp types. ;;; ;;;--------------------------------------------------------------------------- (defvar *quail-doc-type-to-cl-type* NIL "A variable to store the translation table.") (defun cl-type (type) (unless *quail-doc-type-to-cl-type* (init-quail-doc-type-to-cl-type)) (gethash type *quail-doc-type-to-cl-type*)) (defun init-quail-doc-type-to-cl-type () (setf *quail-doc-type-to-cl-type* (make-hash-table :test #'equal :size 11)) (dolist (type '(:constant :variable :parameter)) (set-quail-to-cl-doc-type type 'variable) ) (dolist (type '(:function :special-form :generic-function :method :macro)) (set-quail-to-cl-doc-type type 'function) ) (dolist (type '(:built-in-class :structure :class)) (set-quail-to-cl-doc-type type 'type) ) *quail-doc-type-to-cl-type*) (defun set-quail-to-cl-doc-type (quail-doc-type cl-type) "Sets quail-doc-type to cl-type in the Quail documentation type ~ to Common Lisp doc-type to the translation table." (unless *quail-doc-type-to-cl-type* (init-quail-doc-type-to-cl-type)) (setf (gethash quail-doc-type *quail-doc-type-to-cl-type*) cl-type) ) ;;; ;;; ;;; (defvar *quail-doc-type-to-doc-class* NIL "A variable to store the translation table.") (defun quail-doc-class (type) (unless *quail-doc-type-to-doc-class* (init-doc-type-to-doc-class)) (gethash type *quail-doc-type-to-doc-class*) ) (defun init-doc-type-to-doc-class () (setf *quail-doc-type-to-doc-class* (make-hash-table :test #'equal :size 15)) (set-doc-type-to-doc-class :constant 'constant-documentation) (set-doc-type-to-doc-class :variable 'variable-documentation) (set-doc-type-to-doc-class :parameter 'parameter-documentation) (set-doc-type-to-doc-class :function 'function-documentation) (set-doc-type-to-doc-class :special-form 'special-form-documentation) (set-doc-type-to-doc-class :macro 'macro-documentation) (set-doc-type-to-doc-class :generic-function 'generic-function-documentation) (set-doc-type-to-doc-class :method 'method-documentation) (set-doc-type-to-doc-class :methods 'methods-documentation) (set-doc-type-to-doc-class :accessor 'accessor-documentation) (set-doc-type-to-doc-class :accessors 'accessors-documentation) (set-doc-type-to-doc-class :built-in-class 'built-in-class-documentation) (set-doc-type-to-doc-class :structure 'structure-documentation) (set-doc-type-to-doc-class :class 'class-documentation) (set-doc-type-to-doc-class :package 'package-documentation) (set-doc-type-to-doc-class :topic 'topic-documentation) (set-doc-type-to-doc-class :slot 'slot-documentation) *quail-doc-type-to-doc-class*) (defun set-doc-type-to-doc-class (doc-type doc-class) "Sets doc-type to correspond to doc-class in the Quail documentation type ~ to Quail documentation-object translation." (unless *quail-doc-type-to-doc-class* (init-doc-type-to-doc-class)) (setf (gethash doc-type *quail-doc-type-to-doc-class*) doc-class) ) (defun quail-doc-types () "Returns a list of Quail doc types that are currently defined ~ and to which there correspond classes of Quail documentation objects. ~ (:see-also quail-doc-classes) ~ (:examples ~ (:files ~ (Starting documentation ~ q:examples;documentation;documentation-example.lisp) ~ (Extending the documentation system ~ q:examples;documentation;defining-new-doc-objects.lisp) ~ ))" (unless *quail-doc-type-to-doc-class* (init-doc-type-to-doc-class)) (let ((result NIL)) (with-hash-table-iterator (next-doc-class *quail-doc-type-to-doc-class*) (labels ((try (got-one? &optional key value) (declare (ignore value)) (when got-one? (push key result) (multiple-value-call #'try (next-doc-class))))) (multiple-value-call #'try (next-doc-class)))) result)) (defun quail-doc-classes () "Returns a list of class names for the currently defined ~ documentation objects that correspond to Quail doc-types. ~ (:see-also quail-doc-types)." (unless *quail-doc-type-to-doc-class* (init-doc-type-to-doc-class)) (let ((result NIL) ) (with-hash-table-iterator (next-doc-class *quail-doc-type-to-doc-class*) (labels ((try (got-one? &optional key value) (declare (ignore key)) (when got-one? (push value result) (multiple-value-call #'try (next-doc-class))))) (multiple-value-call #'try (next-doc-class)))) result)) (defun doc-type-p (thing) "Test whether the argument is a supported documentation type." (cond ((stringp thing) (member thing (quail-doc-types) :test #'equalp)) (T (member thing (quail-doc-types) :test #'eq)))) (defgeneric doc-type (thing) (:documentation "Returns the keyword representing the documentation type ~ of the argument if available.")) (defmethod doc-type ((thing T)) (missing-method 'doc-type thing)) (defmethod doc-type ((thing list)) (cond ((listp (cdr thing)) (cadr thing)) (T (cdr thing)))) (defmethod doc-type ((thing variable-documentation)) :variable) (defmethod doc-type ((thing built-in-class-documentation)) :built-in-class) (defmethod doc-type ((thing constant-documentation)) :constant) (defmethod doc-type ((thing parameter-documentation)) :parameter) (defmethod doc-type ((thing procedure-documentation)) :procedure) (defmethod doc-type ((thing special-form-documentation)) :special-form) (defmethod doc-type ((thing function-documentation)) :function) (defmethod doc-type ((thing macro-documentation)) :macro) (defmethod doc-type ((thing generic-function-documentation)) :generic-function) (defmethod doc-type ((thing method-documentation)) :method) (defmethod doc-type ((thing argument-documentation)) :argument) (defmethod doc-type ((thing class-documentation)) :class) (defmethod doc-type ((thing slot-documentation)) :slot) (defmethod doc-type ((thing dataset-documentation)) :dataset) (defmethod doc-type ((thing topic-documentation)) :topic) (defmethod doc-type ((thing accessor-documentation)) :accessor) (defmethod doc-type ((thing accessors-documentation)) :accessors)
7,466
Common Lisp
.l
180
35.377778
113
0.627361
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c60e24d67972344116a5b5c95553481c789a481c1c7cc600582093830d7ee7e6
33,862
[ -1 ]
33,863
topic.lsp
rwoldford_Quail/source/documentation/topic.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; topic.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1990 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; r.w. oldford 1991. ;;; M.E. LEWIS 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(install-super-topic install-sub-topic uninstall-super-topic uninstall-sub-topic ))) (defun topic (arg) "Returns the documentation object for the topic as given by the argument. ~ The argument may be a symbol or a list of a symbol and a doc-type. ~ If the former then the topic documentation is returned. If the latter, then ~ the quail documentation object of type specified by the second element in the ~ list is returned." (flet ((get-topic-doc (name type) (or (doc name type) (and (eq (cadr arg) :topic) (make-instance 'topic-documentation :name name :doc-capsule (format NIL "No documentation available on this topic.")))))) (cond ((symbolp arg) (doc arg :topic)) ((listp arg) (if (listp (cdr arg)) (get-topic-doc (car arg) (cadr arg)) (get-topic-doc (car arg) (cdr arg)))) ((typep arg 'documentation-object) arg) (T (quail-error "Cannot determine the topic ~ documentation for ~s." arg)) ) )) (defun eq-topic (a b) "True if the two arguments are equivalent expressions for the same topic, ~ NIL otherwise." (or (equal a b) (and (string= (name a) (name b)) (eq (doc-type a) (doc-type b))))) (defgeneric add-super-topic (sub super) (:documentation "Add the second argument to the first argument's list of super-topics.")) (defgeneric add-sub-topic (super sub) (:documentation "Add the second argument to the first argument's list of sub-topics.")) (defgeneric remove-super-topic (sub super) (:documentation "Remove the second argument from the first argument's list of super-topics.")) (defgeneric remove-sub-topic (super sub) (:documentation "Remove the second argument from the first argument's list of sub-topics.")) (defun install-super-topic (super sub) "Establishes the super-topic--sub-topic relationship between the first ~ and second arguments." (add-sub-topic super sub) (add-super-topic sub super)) (defun install-sub-topic (super sub) "Establishes the super-topic--sub-topic relationship between the first ~ and second arguments." (add-sub-topic super sub) (add-super-topic sub super)) (defun uninstall-super-topic (super sub) "Destroys the super-topic--sub-topic relationship between the first ~ and second arguments." (remove-sub-topic super sub) (remove-super-topic sub super)) (defun uninstall-sub-topic (super sub) "Destroys the super-topic--sub-topic relationship between the first ~ and second arguments." (remove-sub-topic super sub) (remove-super-topic sub super)) (defmethod add-super-topic ((sub documentation-object) (super topic-documentation)) (with-accessors ((sub-supers super-topics)) sub (if (not (member super sub-supers :test #'eq-topic)) (push super sub-supers)) ) ) (defmethod add-sub-topic ((super topic-documentation) (sub documentation-object)) (with-accessors ((super-subs sub-topics)) super (if (not (member sub super-subs :test #'eq-topic)) (push sub super-subs)) ) ) (defmethod add-super-topic ((sub T) (super T)) (let ((sub-topic (topic sub)) (super-topic (topic super))) (add-super-topic sub-topic super-topic))) (defmethod add-sub-topic ((sub T) (super T)) (let ((sub-topic (topic sub)) (super-topic (topic super))) (add-sub-topic super-topic sub-topic))) (defmethod initialize-instance :after ((self topic-documentation) &key) ;;(if (sub-topics self) ;; (loop for st in (sub-topics self) do ;; (add-super-topic st self))) ) (defun set-topic (symbol &rest keyword-pairs &key (topic-class 'quail-kernel::topic-documentation) ) "Creates a topic documentation object and installs it." (setf (doc symbol :topic) (apply #'make-instance topic-class :allow-other-keys T keyword-pairs)))
4,808
Common Lisp
.l
122
32.581967
103
0.6
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5e0c9c4bf9fb54de92b11d6740450926f37ca0664d5effd7ef4bbeadc78d8b6e
33,863
[ -1 ]
33,864
documentation-path.lsp
rwoldford_Quail/source/documentation/documentation-path.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; test-documentation-path.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991...1993 ;;; ;;; ;;;---------------------------------------------------------------------------- ;(in-package :make) (in-package :quail-kernel) ;;; until we decide about packages (defun maximum-file-name-length () 31) (defun maximum-doc-ext-length () 5) (defun doc-type-extension (doc-type) (let ((doc-ext (case doc-type (:function "fn") (:generic-function "gf") (:macro "mc") (:arguments "arg") (:built-in-class "bic") (:class "cla") (:dataset "ds") (:constant "cst") (:variable "var") (:structure "strc") (:topic "tpc")))) (concatenate 'string "-" (string-downcase doc-ext)))) ;; from quail-path.lsp (defun system-name-convert (string) "Removes spaces which some file systems cannot handle in a file name." #+:apple string #-:apple (substitute #\_ #\Space string)) ;;; And ;;; START gwb functions for appending pathnames ;;; The possibilities for the two inputs are ;;; real-abs-path, log-abs-path, real-rel-path, log-rel-path ;;; Any abs,rel pair is to return a LOGICAL pathname ;;; Write code to deal with each and then a wrapper to ;;; combine the results depending on the pairing. (defun one-real-abs (pn) "convert one real/ordinary pathname to the start of a logical-pathname." (let ((work NIL)) ; replace all the / with ; (setf work (substitute #\; #\/ (namestring pn))) ; if the position of the first ; is 0, remove it (if (eql 0 (position #\; work)) (setf work (remove-if #'(lambda (x) (eql x #\;)) work :count 1)) work) ; replace the (now) first one with : (setf work (substitute #\: #\; work :count 1)) work ) ) (defun one-real-rel (pn) "convert one real relative pathname to the end of a logical-pathname." (let ((work pn)) (setf work (substitute #\; #\/ (namestring work))) work )) (defun one-log-abs (pn) "we are done as we start" pn ;(pathname (namestring pn)) ) (defun one-log-rel (pn) "we are done as we start" pn;(pathname (namestring pn)) ) (defun append-directories (dir1 dir2) "Generates a logical-pathname for a DIRECTORY from dir1 and dir2 dir1 is assumed to be an absolute name - either ordinary or logical, dir2 is asssumed to be a relative name - either ordinary or logical" (cond ((and (position #\/ dir1) (position #\/ dir2)) ;(pathname (concatenate 'string (one-real-abs dir1) (one-real-rel dir2))) ;) ((and (position #\/ dir1) (position #\; dir2)) ;(pathname (concatenate 'string (one-real-abs dir1) (one-log-rel dir2))) ;) ((and (position #\: dir1) (position #\/ dir2)) ;(pathname (concatenate 'string (one-log-abs dir1) (one-real-rel dir2))) ;) ((and (position #\: dir1) (position #\; dir2)) ;(pathname (concatenate 'string (one-log-abs dir1) (one-log-rel dir2))) ;) (t (format t "~%At least one of ~s and ~s is not either an absolute or a relative path specifier" dir1 dir2)) ) ) ;;; Seems to do what it required using ;;; real-absolute "q/r/s/" real-relative "t/u/v" ;;; logical absolute "q:r;s" logical-relative "t;u;v;" ;;; all 4 possibiities yield #P"Q:R;S;T;U;V;" ;;; (defun force-to-pathname (pathname) "Ensures a pathname that is a legal argument for merge-pathnames, say, ~ is returned. Required by edit-file." ;; Possibly an egregious hack. ... rwo #+:aclpc (cond ((typep pathname 'cl::pathname) pathname) (T (translate-logical-pathname pathname))) #-:aclpc pathname ) (defun doc-merge-pathnames (p1 p2) ;; Possibly an egregious hack. ... rwo ;; It's all ACL's fault. (cond ((and (stringp p1) (stringp p2)) (concatenate 'string p1 p2)) (T (merge-pathnames (force-to-pathname p1) p2)))) (defun path-documentation () (system-name-convert "documentation;")) (defun path-doc-polished () (append-directories (path-quail) (system-name-convert "doc;polished;")) ) (defun path-doc-indices () (append-directories (path-quail) (system-name-convert "doc;indices;")) ) (defun path-doc-out (&optional symbol &aux dir) (setf dir (path-doc-polished)) (if symbol (setf dir (append-directories dir (concatenate 'string (string-downcase (package-name (symbol-package symbol))) ";")))) dir) (defun path-auto-doc-out (&optional symbol &aux dir) (setf dir (append-directories (path-quail) (system-name-convert "doc;auto;"))) (if symbol (setf dir (append-directories dir (concatenate 'string (string-downcase (package-name (symbol-package symbol))) ";")))) dir) (defun path-general-topics-out () (append-directories (path-doc-polished) (concatenate 'string "topics" ";"))) (defun path-doc-tex-out (&optional symbol &aux dir) (setf dir (append-directories (path-quail) (system-name-convert "doc;tex;"))) (if symbol (setf dir (append-directories dir (concatenate 'string (string-downcase (package-name (symbol-package symbol))) ";")))) dir) (defun path-doc-current-symbols-out (&optional directory &aux dir) (setf dir (append-directories (path-quail) (system-name-convert "doc;current-symbols;"))) (if directory (setf dir (append-directories dir (concatenate 'string (string-downcase directory) ";")))) dir) ;;;-------------------------------------------------------------------- ;;; ;;; Need to be able to remove * from file-names since these ;;; are typically wildcard characters in a filing system. ;;; ;;;-------------------------------------------------------------------- (defun string-replace-* (string) "Returns a copy of the input string with every occurrence of ~ the character * by the string ``star''." (setf string (if (stringp string) string (format NIL "~s" string))) (let ((replaced-string "")) (with-input-from-string (ifile string) (do ((next-char (read-char ifile nil nil) (read-char ifile nil nil))) ((null next-char)) (setf replaced-string (concatenate 'string replaced-string (if (char= next-char #\*) "star" (string next-char)))))) replaced-string)) (defun doc-file-name (sym doc-type) (let* ((file-name (string-replace-* (string-downcase (string sym)))) (dt-ext (doc-type-extension doc-type)) (max-len (- (maximum-file-name-length) (length dt-ext) (maximum-doc-ext-length)))) (if (> (length file-name) max-len) (concatenate 'string (subseq file-name 0 max-len) dt-ext) (concatenate 'string file-name dt-ext)))) (defun doc-full-file-name (sym doc-type &optional (extension "lsp")) (concatenate 'string (doc-file-name sym doc-type) "." extension)) (defun doc-path-name (sym doc-type &optional (extension "lsp")) (doc-merge-pathnames (path-doc-out sym) (doc-full-file-name sym doc-type extension))) (defun doc-general-topics-path-name (sym doc-type &optional (extension "lsp")) (doc-merge-pathnames (path-general-topics-out) (doc-full-file-name sym doc-type extension))) (defun doc-auto-path-name (sym doc-type &optional (extension "lsp")) (doc-merge-pathnames (path-auto-doc-out sym) (doc-full-file-name sym doc-type extension))) (defun doc-tex-path-name (sym doc-type &optional (extension "tex")) (doc-merge-pathnames (path-doc-tex-out sym) (doc-full-file-name sym doc-type extension))) (defun doc-current-symbols-path-name (name &key directory (extension "lsp")) (doc-merge-pathnames (path-doc-current-symbols-out directory) (if extension (concatenate 'string (string-downcase name) "." extension) (string-downcase name)))) (defun doc-index-filename (&key package) (doc-merge-pathnames (append-directories (path-doc-indices) (system-name-convert (concatenate 'string (string-downcase (package-name package)) ";"))) "doc-index.lsp" )) (defun doc-auto-topics-path-name (filename &optional (extension "lsp")) (doc-merge-pathnames (path-auto-doc-out) (concatenate 'string (string filename) "." extension)))
10,012
Common Lisp
.l
267
28.359551
118
0.534669
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1fcfd4fb8e3a6cd2c581df3e9ced8e421b3b5103c1743c1b99e938f1dbd896fa
33,864
[ -1 ]
33,865
documentation.lsp
rwoldford_Quail/source/documentation/documentation.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; documentation.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991-94 ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(documentation-object))) ;;;----------------------------------------------------------------------------- ;;; ;;; General class: documentation-object ;;; ;;;----------------------------------------------------------------------------- (defclass documentation-object () ((name :accessor name :initarg :name :initform NIL) (package :accessor package :initarg :package :initform NIL) (symbol :accessor doc-symbol :initarg :symbol :initform NIL) (doc-capsule :accessor doc-capsule :initarg :doc-capsule :initform NIL) (doc-elaboration :accessor doc-elaboration :initarg :doc-elaboration :initform NIL) (examples :accessor examples :initarg :examples :initform NIL) (references :accessor references :initarg :references :initform NIL) (see-also :accessor see-also :initarg :see-also :initform NIL) (super-topics :accessor super-topics :initarg :super-topics :initform NIL) (annote :accessor annote :initarg :annote :initform nil)) (:documentation "An object to store documentation.")) ;;;------------------------------ ;;; ;;; Here we extend the "name" method to return a simple string in general, ;;; and the first item in a list if the argument is a list. ;;; This is useful for topics and subtopics. It doesn't force us to ;;; establish all documentation objects that could reside on sub-topic ;;; and super-topic lists. (defmethod name ((arg T)) "Returns the argument as a string in general." (string arg)) (defmethod name ((arg list)) "Returns the first item in the list argument as a string. This is useful for ~ topics." (string (car arg))) ;;;----------------------------------------------------------------------------- ;;; ;;; Variable documentation ;;; ;;;----------------------------------------------------------------------------- (defclass variable-documentation (documentation-object) ((value :accessor value :initarg :value :initform NIL)) (:documentation "Documentation for defined special variables. ~ That is those defined with defvar.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Built-in-class documentation ;;; ;;;----------------------------------------------------------------------------- (defclass built-in-class-documentation (documentation-object) () (:documentation "Documentation for Common Lisp built in classes.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Structure documentation ;;; ;;;----------------------------------------------------------------------------- (defclass structure-documentation (documentation-object) () (:documentation "Documentation for Common Lisp structures. ~ That is those defined with defstruct.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Constant documentation ;;; ;;;----------------------------------------------------------------------------- (defclass constant-documentation (variable-documentation) () (:documentation "Documentation for defined constants. ~ That is those defined with defconstant.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Parameter documentation ;;; ;;;----------------------------------------------------------------------------- (defclass parameter-documentation (variable-documentation) () (:documentation "Documentation for defined parameters. ~ That is those defined with defparameter.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Procedure-documentation ;;; ;;;----------------------------------------------------------------------------- (defclass procedure-documentation (documentation-object) ((lambda-list :accessor lambda-list :initarg :lambda-list :initform NIL) (arguments :accessor arguments :initarg :arguments :initform NIL) (returns :accessor returns :initarg :returns :initform NIL) (side-effects :accessor side-effects :initarg :side-effects :initform NIL)) (:documentation "A class that contains information on ~ the named procedure.")) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Special Forms ;;; (defclass special-form-documentation (procedure-documentation) () (:documentation "A class that contains information on the named special-form.")) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Functions ;;; (defclass function-documentation (procedure-documentation) () (:documentation "A class that contains information on the named function.")) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Macros ;;; (defclass macro-documentation (procedure-documentation) () (:documentation "A class that contains information on the named macro.")) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Generic Functions ;;; and Methods ;;; (defclass generic-function-documentation (procedure-documentation) ((method-list :initform NIL :accessor method-list :initarg :method-list :documentation "An association list of pairs each of whose key is a list ~ of method-qualifiers and whose value is a ~ list of method objects.")) (:documentation "A class that contains information on the named generic-function.")) (defclass method-documentation (procedure-documentation) ((generic-function :initform NIL :accessor doc-generic-function :initarg :generic-function :documentation "The generic function associated with these ~ method objects.") (method-object :initform NIL :accessor doc-method-object :initarg :method :documentation "The actual method object being documented.") (specializers :initform NIL :accessor doc-method-specializers :initarg :specializers :documentation "A list of the names of the specializers of this method.") (qualifiers :initform NIL :accessor doc-method-qualifiers :initarg :qualifiers :documentation "A list of the names of the qualifiers of this method.") ) (:documentation "A class that contains information on the named method.")) (defclass methods-documentation (generic-function-documentation) ((generic-function :initform NIL :accessor doc-generic-function :initarg :generic-function :documentation "The generic function associated with these ~ method objects.")) (:documentation "A class that contains information on a collection of methods for ~ a single generic function.")) ;;;--------------------------------------------------------------------------- ;;; ;;; Lambda list arguments ;;; ;;;--------------------------------------------------------------------------- (defclass argument-documentation () ((required-args :accessor required-args :initarg :&required :initform NIL) (optional-args :accessor optional-args :initarg :&optional :initform NIL) (rest-args :accessor rest-args :initarg :&rest :initform NIL) (aux-args :accessor aux-args :initarg :&aux :initform NIL) (key-args :accessor key-args :initarg :&key :initform NIL) (body-args :accessor body-args :initarg :&body :initform NIL) (allow-other-keys-args :accessor allow-other-keys-args :initarg :&allow-other-keys :initform NIL) ) (:documentation "A place to hold documentation for the arguments of a procedure.")) (defun arg-info-p (arg-doc) (with-accessors ((required-args qk::required-args) (rest-args qk::rest-args) (key-args qk::key-args) (optional-args qk::optional-args) (aux-args qk::aux-args) (body-args qk::body-args) (allow-other-keys-args qk::allow-other-keys-args)) arg-doc (if (or required-args rest-args key-args body-args optional-args aux-args allow-other-keys-args) (let* ((arg-lists (list required-args rest-args key-args body-args optional-args aux-args allow-other-keys-args)) (n (- (length arg-lists) 1))) (do* ((i 0 (+ i 1)) (items (elt arg-lists i) (elt arg-lists i)) (answer NIL)) ((or answer (= i n)) answer) (loop for item in items do (if (cdr item) (setf answer T)))))) )) ;;;--------------------------------------------------------------------------- ;;; ;;; Classes, Accessors, and slots ;;; ;;;--------------------------------------------------------------------------- (defclass class-documentation (documentation-object) ((class :initarg :class :accessor doc-class-object :initform NIL :documentation "The documented class.") (supers :accessor doc-super-classes :initarg :super-classes :initform NIL :documentation "The super-classes of the documented class.") (class-precedence-list :initarg :class-precedence-list :initform NIL :accessor doc-class-precedence-list :documentation "The class-precedence-list of the documented class, ~ from the class back through its ancestors in order ~ of precedence.") (subs :accessor doc-sub-classes :initarg :sub-classes :initform NIL :documentation "The sub-classes of the documented class.") (slots :accessor doc-slots :initarg :slots :initform NIL :documentation "The slot-definitions of the documented class.") (accessors :accessor doc-accessors :initarg :accessors :initform NIL :documentation "A list of two elements ~ containing the reader and writer methods defined for all slots ~ for this class. ~ The first element of this list is a list whose first element is ~ :reader and whose remaining elements are the reader-methods for ~ all slots on the documented class. ~ Similarily, the second element is a list whose first element is ~ :writer and its remaining elements are the writer-methods for all ~ slots the documented class. ~ ") ) (:documentation "A place to hold documentation on a class.")) ;;; ;;; Accessors-documentation ;;; (defclass accessors-documentation (documentation-object) ((class :initarg :class :accessor doc-class-object :initform NIL :documentation "The class for which these accessors were defined.") (accessors :accessor doc-accessors :initarg :accessors :initform NIL :documentation "The accessors methods, if any, defined for the class. ~ (:see-also collect-accessors)") #| (group? :initarg :group? :accessor doc-group-accessors-p :initform NIL :documentation "A display variable to indicate whether the ~ accessor methods should be grouped when displayed. ~ grouping is by element in the accessors list. No ~ grouping means all the accessor methods are displayed ~ in a single list.") |# ) (:documentation "A class that contains information on a collection of accessors for ~ a single class. (:see-also collect-accessors)")) (defclass accessor-documentation (procedure-documentation) ((class :initarg :class :accessor doc-class-object :initform NIL :documentation "The class for which this accessor was defined.") (accessor-object :initform NIL :accessor doc-accessor-object :initarg :accessor :documentation "The actual accessor method-object being documented.") (type :initform NIL :accessor doc-accessor-type :initarg :accessor :documentation "The accessor type, \:reader or \:writer.") ) (:documentation "A class that contains information on the named accessor.")) ;;; ;;; Slot-documentation ;;; (defclass slot-documentation (documentation-object) ((class :initarg :class :accessor doc-class-object :initform NIL :documentation "The class for which the documentation was requested.") (slot :initarg :slot :accessor doc-slot-descriptor :initform NIL :documentation "The slot-descriptor object being documented.") ) (:documentation "A place to hold documentation on a single slot-descriptor.")) ;;; ;;; Slots-documentation ;;; (defclass slots-documentation (documentation-object) ((class :initarg :class :accessor doc-class-object :initform NIL :documentation "The class for which these slots are defined.") (direct-class-slots :accessor doc-direct-class-slots :initarg :direct-class-slots :initform NIL) (direct-instance-slots :accessor doc-direct-instance-slots :initarg :direct-instance-slots :initform NIL) (class-slots :accessor doc-class-slots :initarg :class-slots :initform NIL) (instance-slots :accessor doc-instance-slots :initarg :instance-slots :initform NIL) ) (:documentation "A class that contains information on all slots of ~ a single class.")) ;;;--------------------------------------------------------------------------- ;;; ;;; Documenting datasets ;;; ;;;--------------------------------------------------------------------------- (defclass dataset-documentation (documentation-object) ()) ;;;--------------------------------------------------------------------------- ;;; ;;; Package-documentation. ;;; ;;;--------------------------------------------------------------------------- (defclass package-documentation (topic-documentation) ((external-symbol-topic :accessor external-symbol-topic :initform NIL :initarg :external-symbol-topic :documentation "A pointer to the topic recording the documentation ~ associated with all external symbols.") (shadowed-symbol-topic :accessor shadowed-symbol-topic :initform NIL :initarg :shadowed-symbol-topic :documentation "A pointer to the topic recording the documentation ~ associated with all symbols ~ that have been declared as shadowing symbols in this ~ package.")) ) (defun nicknames (package-documentation) "Returns the list of nicknames of the package associated with the given~ package-documentation object" (package-nicknames (name package-documentation))) (defun packages-used (package-documentation) "Returns the list of names of packages used by the package associated with the given~ package-documentation object" (loop for p in (package-use-list (name package-documentation)) collect (package-name p))) (defun packages-which-use (package-documentation) "Returns the list of names of packages which use the package associated with the given~ package-documentation object" (loop for p in (package-used-by-list (name package-documentation)) collect (package-name p))) ;;;--------------------------------------------------------------------------- ;;; ;;; Documentation by topic. ;;; ;;;--------------------------------------------------------------------------- (defclass topic-documentation (documentation-object) ((sub-topics :initform NIL :initarg :sub-topics :accessor sub-topics) ) )
17,450
Common Lisp
.l
446
30.959641
90
0.538969
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
474263ac85fa4ead4560ff0d9af7ded4b5b2a1af5a2326218c84cdb9ce806548
33,865
[ -1 ]
33,866
generate-topic.lsp
rwoldford_Quail/source/documentation/generate-topic.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; generate-topic.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(generate-subtopic generate-topic generate-package-topics))) (defun generate-subtopics (&key package symbol-list types (sorted-topics? T)) "Constructs a list of list pairs suitable as sub-topics to a topic-documentation ~% object. The elements of the list are ~% determined by the keyword parameters :package, :symbol-list, and :types. ~% If no sub-topics are found to be appropriate, then no topic is generated. ~% The package specifies the package where the symbols are to be found; if ~% missing the symbols are taken where found. Then all documentable uses ~% of all external symbols of the package are given as sub-topics. ~% The keyword :symbol-list is a list of the symbols to appear as sub-topics; ~% if missing all external symbols of the package argument are used. ~% The keyword :types is a list of the ~% type of symbol usage to be documented (e.g. '(function macro class)); ~% if missing, all documentable uses of each symbol are used. ~% Returns the list of subtopics." (let (sub-topics) (flet ((merge-topic-and-type (topic type-list) (if type-list (loop for type in type-list collect (list topic type)))) (get-types (symbol package type-list) (if type-list (intersection type-list (documentable-uses symbol package)) (documentable-uses symbol package)))) (if symbol-list (setf sub-topics (if package (loop for sym in symbol-list nconc (if (null sym) (merge-topic-and-type sym (get-types sym package types)) (cond ((and (listp sym) (not (null sym)) (setf (first sym )(find-symbol (string (first sym)) package))) (list sym)) ((setf sym (find-symbol (string sym) package)) (merge-topic-and-type sym (get-types sym package types)))))) (loop for sym in symbol-list nconc (if (and (listp sym) (not (null sym))) (list sym) (merge-topic-and-type sym (get-types sym package types)))))) (do-external-symbols (sym package) (setf sub-topics (nconc (if (and (listp sym) (not (null sym))) (list sym) (merge-topic-and-type sym (get-types sym package types))) sub-topics))) )) (if sorted-topics? (setf sub-topics (cl:sort sub-topics #'string< :key #'(lambda (x) (string-upcase (car x)))))) sub-topics) ) (defun generate-topic (name &key package symbol-list types (prompt? T) (sorted-topics? T)) "Constructs a topic documentation called name containing sub-topics as ~% determined by the keyword parameters :package, :symbol-list, and :types. ~% If no sub-topics are found to be appropriate, then no topic is generated. ~% The package specifies the package where the symbols are to be found; if ~% missing the symbols are taken where found. Then all documentable uses ~% of all external symbols of the package are given as sub-topics. ~% The package of the topic-documentation is package or the current package ~% if package is not given. ~% The keyword :symbol-list is a list of the symbols to appear as sub-topics; ~% if missing all external symbols of the package argument are used. ~% The keyword :types is a list of the ~% type of symbol usage to be documented (e.g. '(function macro class)); ~% if missing, all documentable uses of each symbol are used. ~% Returns multiple values: the topic-documentation object and the ~% list of subtopics." ;(declare (special *package*)) ;; violates lock on common-lisp package 19MAR2022 gwb (let (sub-topics result) (setf sub-topics (generate-subtopics :package package :symbol-list symbol-list :types types :sorted-topics? sorted-topics?)) (when sub-topics (if (and prompt? (quail-yes-or-no-p "Do you want to iteractively edit the sub-topics to be included?")) (setf result (setf (doc name :topic) (make-instance 'topic-documentation :name (format nil "~a" name) :sub-topics (loop for st in sub-topics when (quail-y-or-n-p (format nil "Include this topic: ~s?" st)) collect st) :package (or (and package (package-name package)) (package-name *package*)) ))) (setf result (setf (doc name :topic) (make-instance 'topic-documentation :name (format nil "~a" name) :sub-topics sub-topics :package (or (and package (package-name package)) (package-name *package*))))) ) (values result sub-topics)) )) (defun type-as-group-topic (type) (cond ((eq type :all) '(:global-var :procedure :data-structure :data-set)) ((eq type :global-var) '(:constant :variable :parameter)) ((eq type :procedure) '(:function :macro :generic-function :method :special-form)) ((eq type :data-structure) '(:class :structure :built-in-class)) (T NIL))) (defvar *package-topics* '(:all :global-var :constant :variable :parameter :procedure :function :macro :generic-function :method :special-form :data-structure :class :structure :built-in-class :data-set) "List of keywords that can be used to generate package-topics.") (defun produce-symbol-for-type (package-name type interned-package) (if (eq type :all) (intern (string package-name) interned-package) (intern (concatenate 'string (string package-name) "-" (let ((type-name (string-upcase (string type)))) (cond ((or (string-equal type-name "CLASS") (string-equal type-name "BUILT-IN-CLASS")) (concatenate 'string type-name "ES")) (T (concatenate 'string type-name "S"))))) interned-package))) (defun produce-doc-capsule-for-type (package type) (let ((package-name (package-name package))) (if (eq type :all) (format nil "The package ~a. Like all other packages, this is an ~% internally consistent collection of symbols." package-name) (format nil "The set of ~a in the package ~a." (let ((type-name (string-upcase (string type)))) (cond ((or (string-equal type-name "CLASS") (string-equal type-name "BUILT-IN-CLASS")) (concatenate 'string type-name "ES")) (T (concatenate 'string type-name "S")))) package-name)))) (defun generate-package-topics (package &key (type :all) (interned-package *package*)) ; (declare (special *package*)) ;; violates lock on common-lisp package 19MAR2022 gwb ;; Error checking (if (not (member type *package-topics*)) (quail-error "Sorry, don't know how to build topic documentation for ~% this type: ~s" type)) (let* ((package-name (package-name package)) (symbol (produce-symbol-for-type package-name type interned-package)) (sub-topics (type-as-group-topic type))) (cond (sub-topics (if (eq type :all) (setf (doc symbol :package) (make-instance 'package-documentation :name (string symbol) :package (package-name interned-package) :doc-capsule (produce-doc-capsule-for-type package type) :sub-topics (loop for type in sub-topics do (generate-package-topics package :type type) collect (list (produce-symbol-for-type package-name type interned-package) :topic)) )) (setf (doc symbol :topic) (make-instance 'topic-documentation :name (string symbol) :package (package-name interned-package) :doc-capsule (produce-doc-capsule-for-type package type) :sub-topics (loop for type in sub-topics do (generate-package-topics package :type type) collect (list (produce-symbol-for-type package-name type interned-package) :topic)) )))) (T (generate-topic symbol :package package :types (list type) :prompt? NIL)))))
11,319
Common Lisp
.l
244
29.54918
125
0.476005
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d7f801d327bc0844453cfa633e6326610b6a8b36cf32cfc3e35a92a390677cd1
33,866
[ -1 ]
33,867
Test.lsp
rwoldford_Quail/source/documentation/Test.lsp
(setf a (make-doc 'deriv :generic-function)) (qk::method-list a) (setf q::methods (qk::method-list a)) (setf q::symbol 'deriv) (step (make-methods-display-list :symbol q::symbol :title "Methods" :methods q::methods :group? T)) (defun foo () (+ 2 3 4)) (defclass foo () ((a :initform (+ 2 3) :accessor a-of :reader aa-of :writer aa :documentation "This is a." :initarg :a-BIG-a) (b :initform #'foo :reader bb-of :writer bb :documentation "This is b." :initarg :a-BIG-b) (c :initform (foo) :accessor c-of :writer c :documentation "This is c." :initarg :a-BIG-c) )) (defmethod a-of :before ((thing foo)) (print "hi there")) (defclass bat (foo) ((a :initform (+ 2 3) :reader aa-of :writer aa :documentation "This is a." :initarg :a-BIG-bat-a) (c :initform (list 1 2 3) :accessor c-of :writer c :documentation "This is c." :initarg :a-BIG-c) )) (defclass fu (foo) ()) (defclass baz (bat) ((a :initform "baz-a" :reader aa-of :writer aa :documentation "This is baz's a." :initarg :a-BIG-bat-a) (d :initform NIL :accessor d-of :writer d :documentation "This is d." :initarg :a-BIG-d) )) (setf s-f (qk::collect-slot-definitions 'foo)) (qk::collect-accessors 'foo) (qk::collect-accessors 'fu) (help 'deriv) (clear-doc 'foo) (class-name (find-class 'foo)) (clear-doc 'fu) (clear-doc 'bat) (clear-doc 'bar) (help 'foo :class) (inspect 'foo) (inspect (doc 'foo :class)) (defun look-at-slots (class) (loop for s in (qk::collect-slot-definitions class) when (cdr s) do (format *terminal-io* "~&~%CLASS: ~s ~10T slot-type: ~s" (qk::doc-class-object (first (cdr s))) (car s)) (loop for s-d in (cdr s) do (format *terminal-io* "~&~%~5TSlot-name: ~s" (qk::slot-definition-name s-d)) (format *terminal-io* "~&~10TInitargs: ~s" (qk::slot-definition-initargs s-d)) (format *terminal-io* "~&~10TInitform: ~s" (qk::slot-definition-initform s-d)) (format *terminal-io* "~&~15TInitform's value: ~s" (let ((initform (qk::slot-definition-initform s-d))) (cond ((functionp initform) (funcall initform)) ((and (listp initform) (= 1 (length initform))) (car initform)) (T initform)))) (format *terminal-io* "~&~10TInitfunction: ~s" (qk::slot-definition-initfunction s-d)) (format *terminal-io* "~&~10TAllocation: ~s" (qk::slot-definition-allocation s-d)) (format *terminal-io* "~&~10TReaders: ~s" (qk::slot-definition-readers s-d)) (format *terminal-io* "~&~10TWriters: ~s" (qk::slot-definition-writers s-d)))) "done") (look-at-slots 'foo) (look-at-slots 'bat) (look-at-slots 'baz) (look-at-slots 'qk::slot-definition) (class-slots (find-class 'foo)) (defmethod print-em ((x foo) (y bat) (z t)) (print (list x y z))) (setf dm-f (specializer-direct-methods (find-class 'foo))) (inspect dm-f) (setf dm-b (specializer-direct-methods (find-class 'bat))) (inspect dm-b) (setf dm-sd (specializer-direct-methods (find-class 'qk::slot-definition))) (inspect dm-sd) (setf dgf-f (specializer-direct-generic-functions (find-class 'foo))) (inspect dgf-f) (setf dgf-b (specializer-direct-generic-functions (find-class 'bat))) (inspect dgf-b) (setf dgf-sd (specializer-direct-generic-functions (find-class 'qk::slot-definition))) (inspect dgf-sd) (setf r-f (qk::slot-definition-readers (find-class 'foo)))
4,310
Common Lisp
.l
122
24.909836
76
0.51834
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
611208948ecc30d81d10f1f64e0d981a2e77e34faf392eb2a8ea50133f44b295
33,867
[ -1 ]
33,868
help-window.lsp
rwoldford_Quail/source/documentation/help-window.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; help-window.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; R.W. Oldford 1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*help-background-color* *help-foreground-color* set-help-pen-color set-help-background-color))) (defvar *help-background-color* wb::*gray-color* ;;(wb:make-color 9509/32640 5911/8160 49087/65280) "The default background colour for help windows.") (defvar *help-foreground-color* wb::*black-color* "The default foreground or pen colour for help windows.") (defun set-help-pen-color (&optional (color (wb:prompt-user-for-color))) "Sets the foreground or pen colour of the help window to color. ~ If color is not supplied the user is prompted to choose a color." (setf *help-foreground-color* color)) (defun set-help-background-color (&optional (color (wb:prompt-user-for-color))) "Sets the background colour of the help window to color. ~ If color is not supplied the user is prompted to choose a color." (setf *help-background-color* color)) (defclass help-window (view-window) () (:documentation "An empty class to distinguish help-windows from other ~ view-windows. This is especially convenient when closing all ~ view-windows of a particular type.")) (defun make-help-window (&rest initargs &key (title "Help") (left 10) (width 400) (bottom 10) (height 400) (background-color *help-background-color*) (pen-color *help-foreground-color*)) "Creates and returns a help-window." (apply #'make-view-window :view-window-class 'help-window :left left :right (+ left width) :bottom bottom :top (+ bottom height) :title title :background-color background-color :pen-color pen-color initargs)) (defun help-height (thing &optional (body-width 100)) (typecase thing (text-view (* (wb:canvas-font-height NIL :font (draw-style thing :font)) (number-of-text-lines thing body-width)) ) (label (wb:canvas-font-height NIL :font (draw-style thing :font))) (header-box (multiple-value-bind (max-ht max-l) (loop for sv in (sub-views-of thing) for font = (draw-style sv :font) maximize (wb:canvas-font-height NIL :font font) into h maximize (wb:canvas-font-leading NIL :font font) into l finally (return (values h l))) (+ max-ht (* 4 max-l)))) (scrolling-display (let ((scroll-bar-width 40)) (+ scroll-bar-width (* (min 10 (display-length-of (first (scroller-displays-of thing)))) (sub-view-height (first (scroller-displays-of thing))))))) (view-layout (let ((svs (subviews-of thing))) (loop for sv in svs sum (help-height sv)))) )) (defun max-help-key-width (help-view-list) (loop for v in (rest help-view-list) by #'cddr maximize (wb:canvas-string-width NIL (get-text v) :font (draw-style v :font)))) (defun help-window-width (help-view) "Returns the window width necessary to nicely display this help-view." (let* ((help-view-list (sub-views-of help-view)) (header (first help-view-list))) (min (- (wb:screen-width) 30) (max (CL:+ 200 (max-help-key-width help-view-list)) (CL:+ 30 (round (loop for v in (sub-views-of header) for r in (sub-view-locns-of header) sum (/ (wb:canvas-string-width NIL (get-text v) :font (draw-style v :font)) (width-of r) )))))))) (defun help-window-height (help-view) "Returns the window height necessary to nicely display this help-view." (min (- (wb:screen-height) 50) (max 400 (CL:+ 30 (round (loop for sv in (sub-views-of help-view) sum (help-height sv) ))))))
5,064
Common Lisp
.l
116
31.896552
113
0.508747
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ca1fcd2dca45a4e838a3f6ec5615a1971b415a79f23030c86f8fdad6d4f4ced1
33,868
[ -1 ]
33,869
track-new-symbols.lsp
rwoldford_Quail/source/documentation/track-new-symbols.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; track-new-symbols.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(get-new-symbol-uses pp-to-file file-subtopics get-old-subtopics get-deprecated-symbol-uses))) (defun get-new-symbol-uses (old-list &key package symbol-list types (sorted-topics? T)) "Constructs a list of list pairs. The first element in each list pair is ~ a symbol; the second element is the symbol's documentable use. ~ Only new symbols, or new uses of previously identified symbols are ~ constructed. ~ All symbols in either the specified package or the symbol-list are ~ compared to the old-list. ~ The required parameter old-list must be a similar list of list pairs. ~ Returns a list containing the differences." (let ((grand-list (generate-subtopics :package package :symbol-list symbol-list :types types :sorted-topics? sorted-topics?)) result ) (flet ((eq-test (a b) (and (eq (first a) (first b)) (eq (second a) (second b)))) (sort-key (x) (string-upcase (car x)))) (setf result (set-difference grand-list old-list :test #'eq-test)) (if sorted-topics? (cl:sort result #'string< :key #'sort-key) result)))) (defun get-deprecated-symbol-uses (old-list &key package symbol-list types (sorted-topics? T)) "Constructs a list of list pairs. The first element in each list pair is ~ a symbol; the second element is the symbol's documentable use. ~ Only symbols, or uses of previously identified symbols, which no longer ~ appear in the symbol-list are returned. ~ All symbols in either the specified package or the symbol-list are ~ compared to the old-list. ~ The required parameter old-list must be a similar list of list pairs. ~ Returns a list containing the differences." (let ((grand-list (generate-subtopics :package package :symbol-list symbol-list :types types :sorted-topics? sorted-topics?)) result ) (flet ((eq-test (a b) (and (eq (first a) (first b)) (eq (second a) (second b)))) (sort-key (x) (string-upcase (car x)))) (setf result (set-difference old-list grand-list :test #'eq-test)) (if sorted-topics? (cl:sort result #'string< :key #'sort-key) result)))) (defun pp-to-file (thing file &key (if-exists :append)) "Pretty-prints the first argument to the file given by the second ~ argument. The keyword if-exists specifies ~ the action to be taken if the file already exists. ~ The default is to append to the existing file (i.e. :append); ~ other possibilities are :supersede, :error, and others as for ~ the CL with-open-file." (with-open-file (ofile file :direction :output :if-exists if-exists :if-does-not-exist :create) (pprint thing ofile))) (defun file-subtopics (sub-topics &key name directory path (if-exists :append)) "Prints the sub-topics to a specified file. ~ The keyword if-exists specifies ~ the action to be taken if the file already exists. ~ The default is to append to the existing file (i.e. :append); ~ other possibilities are :supersede, :error, and others as for ~ the CL with-open-file. ~ The file is determined by the value of the keyword parameters ~ name, directory, and path. ~ Either the full path name of the file is used as given ~ by the value of the path parameter, or a pathname is constructed using ~ the default doc path for current-symbols, the optional sub-directory ~ given by directory, and the filename given by name." (unless path (unless name (setf name "sub-topic-list")) (setf path (doc-current-symbols-path-name name :directory directory))) (with-open-file (ofile path :direction :output :if-exists if-exists :if-does-not-exist :create) (format ofile "~&(") (loop for st in sub-topics do (format ofile "~&~s" st ) finally (format ofile "~&)"))) NIL) (defun get-old-subtopics (&key name directory path) "Returns the list of sub-topics from a specified file. ~ The file is determined by the value of the keyword parameters ~ name, directory, and path. ~ Either the full path name of the file is used as given ~ by the value of the path parameter, or a pathname is constructed using ~ the default doc path for current-symbols, the optional sub-directory ~ given by directory, and the filename given by name." (unless path (unless name (setf name "sub-topic-list")) (setf path (doc-current-symbols-path-name name :directory directory))) (with-open-file (ofile path :direction :input :if-does-not-exist :error) (read ofile)))
5,906
Common Lisp
.l
131
35.19084
129
0.576524
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1c437d76275af01dbba5e6acf8a36773a8fd80fa126b4b3f2c0f1d67bcdac80c
33,869
[ -1 ]
33,870
tex-doc-symbols.lsp
rwoldford_Quail/source/documentation/tex-doc-symbols.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tex-doc-symbols.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1991 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(tex-doc-symbols make-tex-doc-driver *user-tex-out-path-function*))) ;;;----------------------------------------------------------------------- (defvar *user-tex-out-path-function* NIL "A variable whose value is either NIL or is a function of two arguments, ~ a symbol and a doc-type (e.g. :function :macro :topic, et cetera). ~ When funcalled on a symbol and doc-type, the function must return a complete ~ path name for the output documentation file that will be automatically generated ~ by tex-doc-symbols. ~ If NIL, the path used will be the same as for the quail system tex documentation. ~ This variable allows the user to generate quail documentation for ~ his or her own symbols, or even to override the provided quail documentation." ) (defun tex-doc-by-types (sym &key (package nil) (types nil)) (declare (special *user-tex-out-path-function*)) "Produce TeX commands that ~ document the symbol in the specified (or home) package according to ~ its use in the corresponding list of types." ;; ;; Get the types to be a non-NIL list if possible. ;; (if types (setf types (intersection types (documentable-uses sym package))) (setf types (documentable-uses sym package))) (unless (listp types) (setf types (list types))) ;; ;; Now document it for all the types mentioned. ;; (if types (let ((ofile-fun (if (functionp *user-tex-out-path-function*) *user-tex-out-path-function* #'doc-tex-path-name))) (loop for type in types do (with-open-file (ofile (funcall ofile-fun sym type) :direction :output :if-exists :append :if-does-not-exist :create) (write-tex-doc ofile (doc sym type))))))) (defun tex-doc-symbols (&key package symbol-list types) "Constructs TeX documentation for all external symbols given by the ~ keyword package or only those specified ~ by the keyword symbol-list. If given, types is a list of the ~ type of symbol usage to be documented (e.g. '(function macro class)). ~ Otherwise all documentable types will be constructed." (if symbol-list (if package (loop for sym in symbol-list do (setf sym (find-symbol (string sym) package)) (tex-doc-by-types sym :package package :types types)) (loop for sym in symbol-list do (tex-doc-by-types sym :types types))) (do-external-symbols (sym package) (tex-doc-by-types sym :package package :types types)) )) (defun include-tex-doc-by-types (destination sym &key (package nil) (types nil)) "Produce and write to the destination ~ the TeX \include commands for those files which contain the symbol's~ documentation as determined by the specified (or home) package according to ~ its use in the corresponding list of types." ;; ;; Get the types to be a non-NIL list if possible. ;; (if types (setf types (intersection types (documentable-uses sym package))) (setf types (documentable-uses sym package))) (unless (listp types) (setf types (list types))) ;; ;; Now document it for all the types mentioned. ;; (if types (loop for type in types do (format destination "~&\\include{~a}" (doc-file-name sym type))))) (defun make-tex-doc-driver (destination &key package symbol-list (types '(:function)) (document-type "article") (document-styles '("fullpage")) (point-size 12) (input-files nil)) "Produces a LaTeX file (destination) ~ that can be run to get a .dvi documentation file for the ~ given package's external symbols (or those specified by symbol-list). ~ If supplied, only documentation in the list of types will be produced ~ (e.g. Class, function, macro, etc.).~ Point-size (a single fixnum), document-type (\"default article\"), document-styles ~ (default '(\"fullpage\")), and extra input-files can be specified ~ as the values of those keyword arguments." (declare (special tex-doc-style)) (setf document-styles (concatenate 'list (list (format nil "~apt" point-size)) (if (listp document-styles) document-styles (list document-styles)) (if (listp tex-doc-style) tex-doc-style (list tex-doc-style)))) (with-open-file (ofile destination :direction :output :if-does-not-exist :create) ;; ;; Set up the header of the document. ;; (format ofile "~&\\documentstyle") (write-tex-args ofile document-styles) (format ofile "{~a}" document-type) (format ofile "~&\\begin{document}") ;; ;; Set up the input files ;; (when input-files (if (not (listp input-files)) (setf input-files (list input-files))) (loop for file in input-files do (format ofile "~&\\input{~a}" file))) ;; ;; Now determine the desired documentation, construct the ;; corresponding filename and include it in the ;; driver file (cond (symbol-list (if package (loop for sym in (sort symbol-list #'string< :key #'(lambda (x) (string x))) do (setf sym (find-symbol (string sym) package)) (include-tex-doc-by-types ofile sym :package package :types types)) (loop for sym in (sort symbol-list #'string< :key #'(lambda (x) (string x))) do (include-tex-doc-by-types ofile sym :package package :types types)))) (T (do-external-symbols (sym package) (push sym symbol-list)) (loop for sym in (sort symbol-list #'string< :key #'(lambda (x) (string x))) do (include-tex-doc-by-types ofile sym :package package :types types))) ) ;; ;; And end the file ;; (format ofile "~&\\end{document}")))
7,031
Common Lisp
.l
172
32.069767
100
0.566868
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
845facb79402e9e44619dd1de8fd42138e73051a861af0058093a651971185db
33,870
[ -1 ]
33,871
utility.lsp
rwoldford_Quail/source/documentation/utility.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; utility.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(documentable-uses destring string-downcase-object string-downcase-list string-first-n...))) ;;;--------------------------------------------------------------------------- ;;; ;;; Miscellaneous utility functions for making documentation. ;;; ;;;--------------------------------------------------------------------------- ;;;----------------------------------------------------------------------------- ;;; ;;; Uses of a symbol to be documented. ;;; ;;;----------------------------------------------------------------------------- (defun documentable-uses (sym &optional package) "Returns the list of documentable uses of this symbol in the package ~ (if specified). ~ For example as a variable, a class name, a function, a macro, et cetera." (let ((uses '())) (if sym ;; then process it if we find it (and (setf sym (if package (find-symbol (string sym) package) (find-symbol (string sym)))) (progn (if (eql :function (function-information sym)) (if (generic-function-p (symbol-function sym)) (push :generic-function uses) (push :function uses))) (if (eql :macro (function-information sym)) (push :macro uses)) (if (eql :special-form (function-information sym)) (push :special-form uses)) (if (eql :special-operator (function-information sym)) ;27oct05 (push :special-operator uses)) ;27oct05 (if (and (boundp sym) (constantp sym)) (push :constant uses)) (if (and (boundp sym) (not (constantp sym))) (push :variable uses)) (if (get sym :topic NIL) (push :topic uses)) (if (find-package sym) (push :package uses)) (cond ((structure-p sym) (push :structure uses)) ((built-in-class-p sym) (push :built-in-class uses)) ((find-class sym nil) (push :class uses)))) ) ;; else NIL is a constant (push :constant uses)) uses)) (defun list-names-of-docs (doc-list) "Returns a list of the names of the documents given in the argument doc-list. ~ Duplicates are removed." (if (listp doc-list) (remove-duplicates (loop for d in doc-list collect (name d))) (list (name doc-list)))) (defun symbol-from-doc (doc) "Returns the symbol to which the argument, a quail-documentation object, ~ is attached." (find-symbol (name doc) (package doc))) ;;;------------------------------------------------------------------------------------- ;;; ;;; Some handy string utility functions. ;;; ;;; ;;;------------------------------------------------------------------------------------ (defun destring (string) "Reads and returns the first item in the string." (with-input-from-string (s string) (read s))) (defun string-downcase-object (object) "Returns the downcased string of the argument print name." (string-downcase (format NIL "~a" object))) (defun string-downcase-list (list-of-objects) "Returns a list of the downcased elements of the given list of objects." (loop for object in list-of-objects collect (if (listp object) (string-downcase-list object) (string-downcase-object object)))) (defun string-first-n... (string &optional (n 50)) "Returns a string of characters of length no greater than the value ~ of the second optional argument n. ~ The result is either the value of the input string (if the string ~ has n or fewer characters) or it is a string containing the first ~ n-3 elements of the input string and ... as its last three elements." (if (<= (length string) n) string (concatenate 'string (subseq string 0 (- n 4)) "..."))) ;;;------------------------------------------------------------------------------------
4,635
Common Lisp
.l
109
35.513761
115
0.491968
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6c1cfed113ce3ad45d58dd16f248947cb8a8e368a855f6316e58726ea5c348a5
33,871
[ -1 ]
33,872
doc-pprint.lsp
rwoldford_Quail/source/documentation/doc-pprint.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-pprint.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991. ;;; M.E. Lewis 1991. ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) #| ;; pretty print is part of MCL 2.0 final, distinguished by :cltl2 ;; ... dga 92 10 19 #+(and :ccl-2 (not :cltl2)) (eval-when (load compile) (load "ccl-Library;lisp-package")) #+(and :ccl-2 (not :cltl2)) (eval-when (load compile) (load "ccl-xp;xp")) (defmacro doc-pprint (&rest args) #+(and :ccl-2 (not :cltl2)) `(xp::pprint ,.args) #+(or (and :cltl2 :ccl-2) (not :ccl-2)) `(pprint ,.args) ) |# (defmacro doc-pprint (&rest args))
1,060
Common Lisp
.l
31
29.935484
84
0.391347
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
719ffff355b28638e1ee9ca8a55eb2242714046398a4c80576edcbe2f56efc40
33,872
[ -1 ]
33,873
make-doc.lsp
rwoldford_Quail/source/documentation/make-doc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; make-doc.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-doc))) ;;;--------------------------------------------------------------------------- ;;; ;;; A generic function for constructing the appropriate make-instance form for ;;; various classes of Quail documentation. ;;; ;;;--------------------------------------------------------------------------- (defgeneric make-doc (thing type) (:documentation "Creates and returns a quail documentation object ~ that is appropriate for thing of quail documentation ~ type type. ~ (:see-also quail-doc-classes quail-doc-types) ")) ;;; Add do-nothing FEB 04 1998 ;(defmethod make-doc (thing type) ; (declare (ignorable thing type)) ;(declare (ignore thing type)) ; 30JUL2023 ; (call-next-method)) (defmethod make-doc ((thing T) (type T)) (make-instance (quail-doc-class type) :name (string-downcase (format NIL"~s" thing)) :document (interpret-quail-documentation (documenation thing 'type)) ;(documentation thing)) 05SEP2023 ) ) (defmethod make-doc :around (thing type) (if (quail-doc-class type) (call-next-method) (quail-error "Sorry, I don't know how to produce documentation of type ~s for ~s." type thing))) (defmethod make-doc ((thing symbol) type) (let* ((doc-class (quail-doc-class type)) (doc-type (cl-type type)) (document (interpret-quail-documentation (if doc-type (documentation thing doc-type) (documentation thing 'type) ;(documentation thing) ; 05SEP2023 ))) ) (make-instance doc-class :name (string-downcase (format NIL "~s" thing)) :symbol thing :document document) )) (defmethod make-doc ((thing symbol) (type (eql :package))) (generate-package-topics thing)) (defmethod make-doc ((thing symbol) (type (eql :methods))) (let* ((doc-class (quail-doc-class type)) (doc-type (cl-type :generic-function)) (document (interpret-quail-documentation (documentation thing doc-type))) ) (make-instance doc-class :name (string-downcase (format NIL"~s" thing)) :symbol thing :document document) ) ) (defmethod make-doc ((thing symbol) (type (eql :method))) (declare (ignorable type)) ;(declare (ignore type)) ; 30JUL2023 (make-doc (cons thing (collect-methods thing)) :methods)) (defmethod make-doc ((thing list) (type (eql :method))) "Thing is a list whose first element is the symbol, and second ~ element is a method object." (let* ((doc-class (quail-doc-class type)) (document (interpret-quail-documentation (documentation (second thing)))) ) (make-instance doc-class :symbol (first thing) :document document :method (second thing) ) ) ) (defmethod make-doc ((thing list) (type (eql :methods))) "Thing is a list whose first element is the symbol, and whose ~ remaining elements are each lists whose first element is the ~ qualifier list and whose remaining elements are the method objects. ~ (:see-also collect-methods)" (let* ((doc-class (quail-doc-class type)) (doc-type (cl-type :generic-function)) (document (interpret-quail-documentation (documentation (first thing) doc-type))) ) (make-instance doc-class :symbol (first thing) :document document :method-list (rest thing)) ) ) (defmethod make-doc ((thing list) (type (eql :accessors))) "Thing is a list whose first element is the class, and whose ~ remaining elements are each lists whose first element is either :readers ~ or :writers and whose remaining elements are themselves lists of which the ~ first elements is the qualifier list and whose remaining elements are the ~ method objects. ~ (:see-also collect-accessors)" (let* ((doc-class (quail-doc-class type)) (doc-type (cl-type :class)) (document (interpret-quail-documentation (concatenate 'string (format NIL "Accessor methods for class: ~s. " (class-name (first thing))) (documentation (class-name (first thing)) doc-type))) ) ) (make-instance doc-class :symbol (class-name (first thing)) :class (first thing) :document document :accessors (rest thing)) ) ) (defmethod make-doc ((thing list) (type (eql :accessor))) "Thing is a list whose first element is the class and whose ~ second and remaining element is the method-object that is the accessor." (let* ((doc-class (quail-doc-class type)) (doc-type (cl-type :class)) (document (interpret-quail-documentation (concatenate 'string (format NIL "Accessor methods for class: ~s. " (class-name (first thing))) (documentation (class-name (first thing)) doc-type))) ) (accessor (second thing)) ) (make-instance doc-class :symbol (qk::method-name accessor) :class (first thing) :document document :accessor accessor) ) ) ;;;--------------------------------------------------------------------------- ;;; ;;; All quail documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me documentation-object) &key symbol document) (with-slots ((doc-symbol symbol) name package doc-capsule doc-elaboration examples references see-also super-topics annote) me (unless symbol (cond (doc-symbol (setf symbol doc-symbol)) (name (if package (setf doc-symbol (find-symbol (string-upcase name) package)) (setf doc-symbol (find-symbol (string-upcase name))) ) (setf symbol doc-symbol) ) )) (unless name (if symbol (setf name (string-downcase (symbol-name symbol))))) (unless package (if symbol (setf package (package-name (symbol-package symbol))))) (unless doc-capsule (setf doc-capsule (get-doc-capsule document))) (unless doc-elaboration (setf doc-elaboration (get-doc-elaboration document))) (unless examples (setf examples (get-examples document))) (unless references (setf references (get-references document))) (unless see-also (setf see-also (get-see-also document))) (unless super-topics (setf super-topics (get-super-topics document))) (if (null doc-capsule) (setf doc-capsule (get-narrative document)) (setf annote (get-narrative document)))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Constants, variables and parameters ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me variable-documentation) &key symbol document) (declare (ignore document)) (with-slots (value) me (if (boundp symbol) (setf value (eval symbol)) (setf value "Unbound"))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Functions, special-forms, generic-functions and macros ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me procedure-documentation) &key symbol document) (let* ((lam-list (get-lambda-list symbol)) (u-lam-list (untangle-lambda-list lam-list))) (with-slots (lambda-list arguments returns side-effects) me (unless lambda-list (setf lambda-list lam-list)) (unless arguments (setf arguments (make-instance 'argument-documentation :symbol symbol :document document :lambda-list u-lam-list ))) (unless returns (setf returns (get-returns document))) (unless side-effects (setf side-effects (get-side-effects document))))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; generic-functions ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me generic-function-documentation) &key symbol document) (declare (ignore document)) (unless (method-list me) (setf (method-list me) (collect-methods symbol))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; method ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me method-documentation) &key symbol document) (declare (ignore document)) (let ((mo (doc-method-object me))) (unless (doc-generic-function me) (if symbol (setf (doc-generic-function me) (symbol-function symbol)))) (unless (doc-method-qualifiers me) (setf (doc-method-qualifiers me) (method-qualifiers mo))) (unless (doc-method-specializers me) (setf (doc-method-specializers me) (method-specializers mo)) ) me)) ;;;--------------------------------------------------------------------------- ;;; ;;; Arguments ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me argument-documentation) &key symbol document lambda-list) (declare (ignore symbol)) (flet ((eqname (x y) (cond ((and (listp x) (listp y)) (equal x y)) ((or (listp x) (listp y)) NIL) (T (equalp (string x) (string y))))) (complete-annotated-arglist (arglist commented-arglist key-args test) (let ((result nil)) (dolist (item arglist (nreverse result)) (push (or (find item commented-arglist :test test) item) result))))) (with-slots (required-args optional-args rest-args aux-args key-args allow-other-keys-args body-args) me (let ( ;; (lam-required (mapcar #'list (cdr (assoc 'required-args lambda-list)))) (lam-rest (mapcar #'list (cdr (assoc 'rest-args lambda-list)))) (lam-key (mapcar #'list (cdr (assoc 'key-args lambda-list)))) (lam-optional (mapcar #'list (cdr (assoc 'optional-args lambda-list)))) (lam-aux (mapcar #'list (cdr (assoc 'aux-args lambda-list)))) (lam-body (mapcar #'list (cdr (assoc 'body-args lambda-list)))) (lam-allow-other-keys (cdr (assoc 'allow-other-keys-args lambda-list))) ;; (user-required (get-required-arg document)) (user-rest (get-rest-arg document)) (user-key (get-key-arg document)) (user-optional (get-optional-arg document)) (user-aux (get-aux-arg document)) (user-body (get-body-arg document)) ;; ) (setf required-args (complete-annotated-arglist lam-required user-required :test #'(lambda (x y) (eqname (car x) (car y))))) (setf rest-args (complete-annotated-arglist lam-rest user-rest :test #'(lambda (x y) (eqname (car x) (car y))))) (setf key-args (complete-annotated-arglist lam-key user-key :test #'(lambda (x y) (eqname (car x) (car y))))) (setf optional-args (complete-annotated-arglist lam-optional user-optional :test #'(lambda (x y) (eqname (car x) (car y))))) (setf aux-args (complete-annotated-arglist lam-aux user-aux :test #'(lambda (x y) (eqname (car x) (car y))))) (setf body-args (complete-annotated-arglist lam-body user-body :test #'(lambda (x y) (eqname (car x) (car y)))));; (setf allow-other-keys-args lam-allow-other-keys) ))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Class documentation ;;; ;;;--------------------------------------------------------------------------- (defun make-slots-documentation (class &rest doc-keyword-args) "Creates and makes a slots-documentation object for class if ~ class has any slots otherwise returns NIL." (let* ((slot-defs (collect-slot-definitions class)) (class-slots (cdr (assoc :class-slots slot-defs))) (instance-slots (cdr (assoc :instance-slots slot-defs))) (direct-class-slots (cdr (assoc :direct-class-slots slot-defs))) (direct-instance-slots (cdr (assoc :direct-instance-slots slot-defs))) ) (when (or class-slots instance-slots direct-class-slots direct-instance-slots) (apply #'make-instance 'slots-documentation :symbol (class-name class) :name (string-downcase (format NIL "~a" (class-name class))) :class class :class-slots class-slots :instance-slots instance-slots :direct-class-slots direct-class-slots :direct-instance-slots direct-instance-slots doc-keyword-args) )) ) (defmethod initialize-instance :after ((me class-documentation) &key symbol document) (declare (ignore document)) (with-slots (class supers class-precedence-list subs slots accessors) me (unless class (setf class (find-class symbol))) (unless supers (setf supers (class-direct-superclasses class))) (unless class-precedence-list (setf class-precedence-list (class-precedence-list class))) (unless subs (setf subs (class-direct-subclasses class))) (unless slots (setf slots (make-slots-documentation class :doc-capsule (doc-capsule me)))) (unless accessors (setf accessors (collect-accessors class))) ) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Accessors documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me accessors-documentation) &key symbol document) (declare (ignore document)) (with-slots (class accessors) me (unless class (setf class (find-class symbol))) (unless symbol (setf (slot-value me 'symbol) (class-name class))) (unless accessors (setf accessors (collect-accessors class))) ) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Accessor documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me accessor-documentation) &key symbol document) (declare (ignore symbol document)) (with-slots (class accessor type) me (unless type (setf type (cond ((reader-method-p accessor) :reader) ((writer-method-p accessor) :writer) (T NIL)))) (unless class (setf class (cond ((eq type :reader) (first (method-specializers accessor))) ((eq type :writer) (second (method-specializers accessor))) (T NIL))))) me) ;;;--------------------------------------------------------------------------- ;;; ;;; Slot documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod initialize-instance :after ((me slot-documentation) &key symbol slot) (declare (ignore symbol)) (with-slots (name package doc-capsule) me (unless name (setf name (string (slot-definition-name slot)))) (unless package (setf package (package-name (symbol-package (slot-definition-name slot))))) (unless doc-capsule (setf doc-capsule (documentation slot))) ) me)
18,094
Common Lisp
.l
439
31.063781
109
0.504203
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
06cafec3168c0f7356c4768236edb0baf8e767c31a9402325c2695320dda07bf
33,873
[ -1 ]
33,874
utility-args.lsp
rwoldford_Quail/source/documentation/utility-args.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; utility-args.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1991 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(untangle-lambda-list))) ;;;;;;;;;;;;;;; ;;; ;;; (defun untangle-lambda-list (l-list) "Parses the lambda list into an association list, keyed ~ by the appropriate lambda list keyword." (labels ((set-difference-preserving-order (set1 set2) (cond ((null set2) set1) ((null set1) nil) (t (set-difference-preserving-order (remove (car set2) set1) (cdr set2))))) (up-to-& (a-list) (loop for x in a-list until (member x '(&rest &key &optional &aux)) collect x))) (let ((rest (member '&rest l-list)) (key (member '&key l-list)) (optional (member '&optional l-list)) (aux (member '&aux l-list)) (body (member '&body l-list)) (whole (member '&whole l-list)) (environment (member '&environment l-list)) (allow-other-keys (member '&allow-other-keys l-list)) required result) (setf result (acons '&required (setf required (set-difference-preserving-order l-list (concatenate 'list rest key optional aux body))) result)) (setf result (acons '&rest (up-to-& (cdr rest)) result)) (setf result (acons '&key (up-to-& (cdr key)) result)) (setf result (acons '&optional (up-to-& (cdr optional)) result)) (setf result (acons '&aux (up-to-& (cdr aux)) result)) (setf result (acons '&allow-other-keys (up-to-& (cdr allow-other-keys)) result)) (setf result (acons '&whole (up-to-& (cdr whole)) result)) (setf result (acons '&body (up-to-& (cdr body)) result)) (setf result (acons '&environment (up-to-& (cdr environment)) result)) (setf result (acons '&other-lambda-keys (set-difference-preserving-order l-list (concatenate 'list required rest key optional aux allow-other-keys whole body environment)) result)) result))) ;----- (defgeneric matching-arg-list-p (a b) (:documentation "tests whether lambda-lists match.")) (defmethod matching-arg-list-p (lam-list (f-d function-documentation)) (equal lam-list (lambda-list f-d))) (defmethod matching-arg-list-p ((f-d function-documentation) lam-list) (equal lam-list (lambda-list f-d))) (defmethod matching-arg-list-p ((f-d-1 function-documentation) (f-d-2 function-documentation)) (equal (lambda-list f-d-1) (lambda-list f-d-2)))
3,977
Common Lisp
.l
89
28.41573
89
0.417528
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dd5da35876acc01f59315f7371fea1ee66b50e8f1f6929658986f320cb3385b7
33,874
[ -1 ]
33,875
help-view.lsp
rwoldford_Quail/source/documentation/help-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; help-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; R.W. Oldford 1992,1994. ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(help-view))) (defclass help-view (compound-view) ((help-type :initarg :help-type :initform NIL :documentation "The type of help that was requested in the construction ~ of this help-view.")) ) (defmethod construct-sub-views ((self help-view) &rest args) (declare (ignore args)) (setf (sub-views-of self) (help-sub-views (viewed-object-of self) :type (slot-value self 'help-type)))) (defmethod compute-sub-viewports ((self help-view) &optional viewport junk) (declare (ignore junk)) (loop for vp in (if viewport (list viewport) (viewports-of self)) do (loop for sv in (sub-views-of self) for sv-vp = (or (vw::select-viewport sv vp) (make-viewport (window-of vp))) for new-sv-vp in (construct-viewports (sub-views-of self) vp ) do (setf (bounds-of sv-vp) new-sv-vp) (add-viewport sv sv-vp vp)) )) (defmethod reshape-sub-viewports ((self help-view) viewport &key new-location transform ) (declare (ignore new-location transform)) (map-subviews-to-viewport self viewport)) (defun construct-viewports (help-view-list viewport) "Constructs the necessary viewports for each view in ~ help-view-list to be placed in viewport." (let ((header (first help-view-list)) (paras (rest help-view-list)) (w (window-of viewport)) key-width body-width max-leading viewports current-y) (multiple-value-bind (l r b tp) (bounds-of viewport) (declare (ignore b)) (setf max-leading (or (loop for v in paras when (has-draw-style-p v :font) ;;(typep v 'scrolling-display) maximize (wb:canvas-font-leading (draw-style v :font))) 0)) (setf current-y (- tp (help-height header) max-leading)) (setf viewports (list (make-viewport w l r current-y tp))) (setf key-width (max-help-key-width help-view-list)) (setf body-width (max 100 (max 0 (- r l key-width)))) (append viewports (loop for key in paras by #'cddr for body in (cdr paras) by #'cddr append (list (make-viewport w l (+ l key-width) (- current-y (help-height key)) current-y) (make-viewport w (+ l key-width) (+ l key-width body-width) (- (decf current-y (help-height key)) (help-height body body-width)) current-y)) do (decf current-y (+ (* 2 max-leading) (help-height body body-width))))) )))
3,629
Common Lisp
.l
92
29.054348
86
0.496124
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
73fd801803f1f40cdcfd0bccf8bacab6d8112444682e399532e1dd369e720154
33,875
[ -1 ]
33,876
doc-index.lsp
rwoldford_Quail/source/documentation/doc-index.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; doc-index.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1990 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; e.e. cummings 1933. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-documentation-index make-sorted-documentation-index sort-doc view-doc-index))) (defun view-doc-index (&key package pathname) "Produces a display of the list of symbols found in the file ~% given by the pathname. If no pathname is specified, then the index ~% file for the given package is examined." (cond ((and package pathname) (quail-error "VIEW-DOC-INDEX -- Must supply package ~% or pathname, not both.")) (package (setf pathname (doc-index-filename :package package))) ((null pathname) (quail-error "VIEW-DOC-INDEX -- Must supply one of package ~% or pathname.") ) ) (setf pathname (probe-file pathname)) (if pathname (cond ((string= "As a file." (wb:pick-one '("As a file." "As a help window. (longer)") :prompt-text (format NIL "Choose one.~%~% A help window will take more resources."))) (q:edit-file pathname)) (T (vw:inform-user (format NIL "This may take a little while ~%~% as these indices are very long.")) (q::help (make-instance 'topic-documentation :name (format NIL "~s symbol index" (or package "")) :doc-capsule (format NIL "Here is the index of symbols for ~s." (or package pathname)) :sub-topics (with-open-file (ifile pathname :direction :input :if-does-not-exist nil) (read ifile NIL NIL)) )) ) ) (vw:inform-user (format NIL "Sorry, can't find the index. ~%~% You might try recreating it with ~%~% ~%~5T(make-sorted-documentation-index :package ~s)" (or package :quail))) ) ) (defun process-symbol (sym ofile &optional package) (setf sym (find-symbol (string sym) (or (package-name package) (symbol-package sym)))) (if (eql :function (function-information sym)) (format ofile "~&(~a ~s)" sym :function)) (if (eql :macro (function-information sym)) (format ofile "~&(~a ~s)" sym :macro)) (if (eql :special-form (function-information sym)) (format ofile "~&(~a ~s)" sym :special-form)) (if (eql :special-operator (function-information sym)) ;27oct05 (format ofile "~&(~a ~s)" sym :special-operator)) ;27oct05 (if (and (boundp sym) (constantp sym)) (format ofile "~&(~a ~s)" sym :constant)) (if (and (boundp sym) (not (constantp sym))) (format ofile "~&(~a ~s)" sym :variable)) (if (structure-p sym) (format ofile "~&(~a ~s)" sym :structure)) (if (find-class sym nil) (format ofile "~&(~a ~s)" sym :class))) (defun make-documentation-index (&key package symbol-list) "Constructs documentation index for all external symbols ~% or for those specified in the optional list argument. ~% The result is stored in the doc-index file in the documentation ~% directory." (with-open-file (ofile (doc-index-filename :package package) :direction :output :if-exists :supersede :if-does-not-exist :create) (format ofile "~&~a" (make-string 80 :initial-element #\;)) (format ofile "~&;;;") (format ofile "~&;;;") (format ofile "~&;;;") (if package (format ofile "~5TIndex file for symbols in the ~s package." package) (format ofile "~5TIndex file of symbols") ) (format ofile "~&;;;") (format ofile "~5T~a" (current-date)) (format ofile "~&;;;") (format ofile "~&;;;") (format ofile "~&~a" (make-string 80 :initial-element #\;)) (if symbol-list (loop for sym in symbol-list do (process-symbol sym ofile package)) (if package (do-external-symbols (sym package) (process-symbol sym ofile package)) (error "Must specify at least one of SYMBOL-LIST and PACKAGE ~% -- MAKE-DOCUMENTATION-INDEX"))) )) (defun sort-doc (&key package (symbol-list ())) (let ((filename (doc-index-filename :package package))) (with-open-file (ifile filename :direction :input :if-does-not-exist nil) (do ((pair (read ifile nil nil) (read ifile nil nil)) ) ((null pair) symbol-list) (push pair symbol-list))) (setf symbol-list (sort symbol-list #'string< :key #'(lambda (x) (concatenate 'string (string (first x)) (string (second x)))))) (delete-file filename) (with-open-file (ofile filename :direction :output :if-exists :supersede :if-does-not-exist :create) (format ofile "~&~a" (make-string 80 :initial-element #\;)) (format ofile "~&;;;") (format ofile "~&;;;") (if package (format ofile "~5TIndex file for symbols in the ~s package." package) (format ofile "~5TIndex file of symbols") ) (format ofile "~&;;;") (format ofile "~5TAll symbols sorted in alphabetical order ~% and stored in a list.") (format ofile "~&;;;") (format ofile "~5T~a" (current-date)) (format ofile "~&;;;") (format ofile "~&;;;") (format ofile "~&~a" (make-string 80 :initial-element #\;)) (format ofile "~&~%(") (if package (dolist (item symbol-list) (format ofile "~&~5T(~a:~s ~s)" package (first item) (second item))) (dolist (item symbol-list) (format ofile "~&~5T~s" item)) ) (format ofile "~&)") )) ) (defun make-sorted-documentation-index (&key package (symbol-list ())) "Constructs documentation index for all external symbols ~% or for those specified in the optional list argument. ~% Symbols are sorted first by name ~% and then by name within use (class, function, etc.). ~% The result is stored in a doc-index file in the documentation ~% indices directory for that package." (make-documentation-index :package package :symbol-list symbol-list) (sort-doc :package package) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Some examples ;;; ;;; #| (make-documentation-index :package :window-basics) (sort-doc (mk::doc-index-filename :package :window-basics)) (make-sorted-documentation-index :package :quail-kernel) (loop for p in '(:window-basics :views :quail-kernel :quail :new-math) do (make-sorted-documentation-index :package p)) |#
8,014
Common Lisp
.l
205
28.565854
131
0.505726
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7c49014cdbffcb7a76ec9508e2728731d99eda6288567563a66d2e0e32969d43
33,876
[ -1 ]
33,877
auto-topics.lsp
rwoldford_Quail/source/documentation/auto-topics.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; auto-topics.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(create-topic-info-from-files write-topic-info-to-file topics-list-to-topic-files auto-create-and-file-topics))) (defun pathname-to-file-info (pathname-or-list-of-names) (if (not (listp pathname-or-list-of-names)) (setf pathname-or-list-of-names (list pathname-or-list-of-names))) (loop for pn in pathname-or-list-of-names collect (list (rest (pathname-directory pn)) (pathname-name pn) pn))) (defun files-in-quail () (loop for system in cl-user::*quail-systems* ;*quail-systems* ; 30JUL2023 append (let ((files (files-in-system system))) (loop for fs in files collect (list (rest (pathname-directory fs)) (pathname-name fs) fs))))) (defun find-exported-syms (file-info) (let ((file-path (third file-info)) (form nil) (eof nil) (original-package *package*) (exported-syms NIL)) (prog1 (butlast (with-open-file (in file-path :direction :input) (loop while (not eof) do (prog1 (setf form (read in nil :eof nil)) (setf eof (eq form :eof)) (if (listp form) (cond ((equal (string (first form)) "IN-PACKAGE") (setf *package* (find-package (string (second form))))) ((equal (string (first form)) "EXPORT") (setf exported-syms (union (second (second form)) exported-syms)))))) ))) (setf *package* original-package)) exported-syms )) (defun generate-topics-list-from-files (&optional (file-pathnames NIL)) (let ((exported-syms NIL) (files-info (if file-pathnames (pathname-to-file-info file-pathnames) (files-in-quail)))) (loop for file-info in files-info when (car (last (setf exported-syms (let ((directories (cons "Quail" (rest (first file-info)))) (file-name-sans-.lisp (second file-info))) (list directories file-name-sans-.lisp (find-exported-syms file-info)))))) collect exported-syms))) (defun create-topic-info-from-files (&optional (file-pathnames NIL)) "Reads the source files as identified by the optional argument file-pathnames ~ and constructs a list of topics and sub-topics information that can be parsed ~ to construct topic documentation. Topics and sub-topics are identified with the names of ~ the directories and files as found in the file-pathnames. ~ Each subdirectory will be identified as a sub-topic of its parent directory. ~ At the bottommost level, each file is scanned for symbols appearing in an export ~ statement. Each such symbol found is a subtopic of the topic defined by the name ~ of the file in which it is found; its documentation type is whatever is found as ~ a documentable-use in its home package. ~ (:optional ~ (:arg file-pathnames NIL Either a single pathname of a file or a ~ list of file-pathnames. If absent, all source files of the current ~ Quail system are assumed.)) ~ (:returns An organized list of topic information. Each topic list ~ is itself a list whose first element is a symbol naming the ~ topic and whose second element is a list containing sensible subtopics.) ~ (:see-also (documentable-uses :function))" (let* ((topics-list (generate-topics-list-from-files file-pathnames)) (topics-hash-array (make-hash-table :size (length topics-list) :test #'equalp)) (directories NIL) (remaining-directories NIL) (file-name NIL) (file-contents NIL) (final-list NIL) ) (flet ((add-sub-topic-to (key sub &optional (type :topic)) (unless (and (eq type :topic) (string-equal key (string sub))) (let ((contents (gethash key topics-hash-array)) (sub-topic (list (if (stringp sub) (destring sub) sub) type))) (if contents (unless (member sub-topic contents :test #'equal) (push sub-topic (gethash key topics-hash-array))) (setf (gethash key topics-hash-array) (list sub-topic))))))) (dolist (info topics-list) (setf directories (first info)) (setf remaining-directories directories) (setf file-name (second info)) (setf file-contents (third info)) (dolist (dir directories) (setf remaining-directories (rest remaining-directories)) (when remaining-directories (add-sub-topic-to dir (first remaining-directories)))) (if file-contents (cond ((> (length file-contents) 1) (dolist (sym file-contents) (dolist (use (documentable-uses sym (symbol-package sym))) (add-sub-topic-to file-name sym use))) (add-sub-topic-to (first (last directories)) file-name)) (T (dolist (use (documentable-uses (first file-contents) (symbol-package (first file-contents)))) (add-sub-topic-to (first (last directories)) (first file-contents) use)))) (format *terminal-io* "No file-contents! : ~a" file-name) )) (maphash #'(lambda (key value) (push (list (destring key) (sort value #'(lambda (a b) (string-lessp (string (first a)) (string (first b)))) )) final-list)) topics-hash-array) (sort final-list #'(lambda (a b) (string-lessp (string (first a)) (string (first b)))))))) (defun write-topic-info-to-file (topic-info-list &optional (full-pathname NIL) (outfile "topic-info")) (loop for info in topic-info-list do (with-open-file (ofile (if full-pathname full-pathname (doc-auto-topics-path-name outfile)) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~&(~s ~%~5T(" (first info)) (loop for sub in (second info) do (format ofile "~&~6T~s" sub)) (format ofile "~&~5T))" ) ))) (defun topics-list-to-topic-files (&optional (topics-list NIL)) (declare (special *user-doc-out-path-function*)) (let ((ofile-fun (if (functionp *user-doc-out-path-function*) *user-doc-out-path-function* #'doc-auto-path-name)) sub-topics name) (loop for topic in topics-list do (vw::inform-user (format NIL "~&processing topic ~s" (first topic))) (setf name (first topic)) (setf sub-topics (second topic)) (setf (doc name :topic) (make-instance 'qk::topic-documentation :name (format nil "~a" name) :sub-topics sub-topics :package (package-name (symbol-package (first topic))) )) (with-open-file (ofile (funcall ofile-fun name :topic) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~&(setf (doc '~a :topic)~%" name) (write-doc ofile (doc name :topic)) (format ofile "~&)~%")) ))) (defun auto-create-and-file-topics (&optional (file-pathnames NIL)) "Reads the source files as identified by the optional argument file-pathnames ~ and constructs a list of topics and sub-topics information. ~ This is then parsed to construct topic documentation which is in turn ~ written directly to the files in the doc;auto directory. A different ~ location is effected by setting the value of the symbol ~ *user-doc-out-path-function* to be a function which will return a complete ~ pathname for each topic. That function takes two arguments, the topic name ~ and its doc-type, i.e. :topic. ~%~ Topics and sub-topics are identified with the names of ~ the directories and files as found in the file-pathnames. ~ Each subdirectory will be identified as a sub-topic of its parent directory. ~ At the bottommost level, each file is scanned for symbols appearing in an export ~ statement. Each such symbol found is a subtopic of the topic defined by the name ~ of the file in which it is found; its documentation type is whatever is found as ~ a documentable-use in its home package. ~ (:optional ~ (:arg file-pathnames NIL Either a single pathname of a file or a ~ list of file-pathnames. If absent, all source files of the current ~ Quail system are assumed.)) ~ (:see-also (documentable-uses :function) ~ (*user-doc-out-path-function* :parameter) ~ (write-topic-info-to-file :function) ~ (topics-list-to-topic-files :function))" (topics-list-to-topic-files (create-topic-info-from-files file-pathnames)))
10,577
Common Lisp
.l
223
34.434978
118
0.539715
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cd43b534c4e6f461c2acfd7ce5e448ec8a0c549338d24547a8b180756884fa95
33,877
[ -1 ]
33,878
example-topic.lsp
rwoldford_Quail/source/documentation/example-topic.lsp
(setf (doc 'getting-started :topic) (make-instance 'quail-kernel::topic-documentation :name "getting-started" :doc-capsule "How to get started in Quail." :doc-elaboration nil :examples nil :references nil :see-also nil :sub-topics '((common-lisp :topic) (quail :topic)) :super-topics NIL )) (setf (doc 'topics :topic) (make-instance 'quail-kernel::topic-documentation :name "topics" :doc-capsule "The set of topics documented in Quail." :doc-elaboration nil :examples nil :references nil :see-also nil :sub-topics '((arrays :topic) (numerical :topic) (graphics :topic) (views :topic) (statistics :topic) (quaff :topic)) :super-topics NIL )) (setf (doc 'arrays :topic) (make-instance 'quail-kernel::topic-documentation :name "arrays" :doc-capsule "Arrays in Quail." :doc-elaboration nil :examples nil :references nil :see-also nil :sub-topics '((array :built-in-class) (sequence :built-in-class) (ref :generic-function) (dimensioned-ref-object :class) (ref-array :class) (setf :macro) (setq :special-form)) :super-topics NIL
2,468
Common Lisp
.l
68
14.470588
62
0.315526
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
54269a246d4e55c66650ebdef63d5494a6e466f45d610e92397d87db4b9a2324
33,878
[ -1 ]
33,879
tex-basic.lsp
rwoldford_Quail/source/documentation/tex-basic.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tex-basic.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1990 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;;---------------------------------------------------------------------------- ;;; ;;; Writing lisp values as TeX commands with escapes ;;; for TeX's special characters ;;; ;;;---------------------------------------------------------------------------- (defvar *tex-special-char* '(#\# #\$ #\% #\& #\~ #\_ #\^ #\\ #\{ #\} #\| #\< #\>) "Characters that must be escaped to be understood by TeX.") (defun tex-special-char-p (char) "Test whether argument is a special character in TeX." (declare (special *tex-special-char*)) (if (member char *tex-special-char* :test #'char=) T NIL)) (defun write-tex-value (destination value) "Writes the value to the destination inserting a TeX escape ~ character in front of anything that is a TeX special character." (with-input-from-string (ifile (if (stringp value) value (format NIL "~s" value))) (do ((next-char (read-char ifile nil nil) (read-char ifile nil nil))) ((null next-char)) (cond ((tex-special-char-p next-char) (write-char #\\ destination) (write-char next-char destination)) (t (write-char next-char destination)))))) ;;;------------------------------------------------------------------------------ ;;; ;;; TeX arg lists ;;; ;;;------------------------------------------------------------------------------ (defun write-tex-args (destination &optional (args NIL)) "Writes the second argument as ~ items in a TeX arglist (i.e. as [item-1, item-3, ..., item-n])." (if args (do ((rest-of-args args (cdr rest-of-args)) (char "[" ", ")) ((null rest-of-args) (format destination "]")) (format destination char) (write-tex-value destination (car rest-of-args))) (format destination "[]"))) ;;;------------------------------------------------------------------------------ ;;; ;;; TeX environments ;;; ;;;----------------------------------------------------------------------------- (defun write-tex-begin-env (destination environment) "Writes the TeX commands to destination that are necessary to begin ~ a TeX environment of the specified type." (format destination "~&\\begin{~a} ~%" environment)) (defun write-tex-end-env (destination environment) "Writes the TeX commands to destination that are necessary to begin ~ a TeX environment of the specified type (default itemize)." (format destination "~&\\end{~a} ~%" environment)) ;;;----------------------------------------------------------------------------- ;;; ;;; TeX Lists ;;; ;;;---------------------------------------------------------------------------- (defun write-tex-begin-list (destination &key (type 'itemize)) "Writes the TeX commands to destination that are necessary to begin ~ a TeX list of the specified type (default itemize)." (write-tex-begin-env destination type)) (defun write-tex-end-list (destination &key (type 'itemize)) "Writes the TeX commands to destination that are necessary to begin ~ a TeX list of the specified type (default itemize)." (write-tex-end-env destination type)) (defun write-tex-item (destination item) "Writes the TeX commands to destination that are necessary to produce ~ a single item of a TeX list." (format destination "~&\\item ~%") (write-tex destination item)) (defun write-tex-list (destination &key (type 'itemize) (items nil)) "Writes the TeX commands necessary to produce a TeX list ~ of the given type (default itemize) of items." (write-tex-begin-list destination :type type) (loop for item in items do (write-tex-item destination item)) (write-tex-end-list destination :type type))
4,558
Common Lisp
.l
102
38.343137
82
0.492731
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5c12977244ce61ef565dc73a85a41c93413515ad1a8c3baf45727c05dfe0344f
33,879
[ -1 ]
33,881
header-box.lsp
rwoldford_Quail/source/documentation/header-box.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; header-box.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; R.W. Oldford 1992-4 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(header-box make-view-paragraph header-box-view ;;make-help-views-arg-element ))) (defclass header-box (boxed-view-mixin compound-view) () (:default-initargs :color q::*help-foreground-color* :style-keys '(:color)) ) (defmethod construct-sub-views ((self header-box) &rest args &key (left "") (middle "") (right "") (left-font wb:*help-lisp-title-font*) (middle-font wb:*help-small-title-font*) (right-font wb:*help-normal-title-font*)) (declare (ignore args)) (let ((left-label (label :draw? NIL :justification :left :font left-font :color q::*help-foreground-color*)) (middle-label (label :draw? NIL :justification :centre :font middle-font :color q::*help-foreground-color*)) (right-label (label :draw? NIL :justification :right :font right-font :color q::*help-foreground-color*))) (setf (text-of left-label) (format NIL "~a" left)) (setf (text-of middle-label) (format NIL "~a" middle)) (setf (text-of right-label) (format NIL "~a" right)) (setf (sub-views-of self) (list left-label middle-label right-label)))) (defmethod init-position-subviews ((self header-box) &key (left-xmin 0.05) (left-xmax 0.3) (middle-xmin 0.31) (middle-xmax 0.7) (right-xmin 0.71) (right-xmax 0.95)) (let ((subs (sub-views-of self))) (place-subview self (first subs) (make-region left-xmin left-xmax 0 1)) (place-subview self (second subs) (make-region middle-xmin middle-xmax 0 1)) (place-subview self (third subs) (make-region right-xmin right-xmax 0 1)))) (defun header-box-view (&rest initargs &key (left nil left?) (middle nil middle?) (right nil right?) (left-font wb:*help-lisp-title-font*) (middle-font wb:*help-small-title-font*) (right-font wb:*help-normal-title-font*) &allow-other-keys) "Returns a header-box view ~ with text left left-justified horizontally, middle centred, and right ~ right-justified." (cond ((and left? middle? right?) (apply #'make-instance 'header-box :left left :middle middle :right right :left-font left-font :middle-font middle-font :right-font right-font initargs)) ((and left? right?) (apply #'make-instance 'header-box :left left :right right :left-font left-font :middle-font middle-font :right-font right-font :left-xmax 0.5 :middle-xmin 0.5 :middle-xmax 0.55 :right-xmin 0.55 :right-xmax 0.95 initargs)) ((and left? middle?) (apply #'make-instance 'header-box :left left :middle middle :left-font left-font :middle-font middle-font :right-font right-font :left-xmax 0.45 :middle-xmin 0.50 :middle-xmax 0.95 :right-xmin 0.95 :right-xmax 1.0 initargs)) (left? (apply #'make-instance 'header-box :left left :left-font left-font :middle-font middle-font :right-font right-font :left-xmax 0.95 :middle-xmin 0.95 :middle-xmax 0.97 :right-xmin 0.97 :right-xmax 1.0 initargs)) ((and right? middle?) (apply #'make-instance 'header-box :middle middle :right right :left-font left-font :middle-font middle-font :right-font right-font :left-xmin 0.0 :left-xmax 0.10 :middle-xmin 0.25 :middle-xmax 0.6 :right-xmin 0.6 :right-xmax 0.95 initargs)) (middle? (apply #'make-instance 'header-box :middle middle :left-font left-font :middle-font middle-font :right-font right-font :left-xmin 0.0 :left-xmax 0.10 :middle-xmin 0.15 :middle-xmax 0.85 :right-xmin 0.9 :right-xmax 1.0 initargs)) (right? (apply #'make-instance 'header-box :right right :left-font left-font :middle-font middle-font :right-font right-font :left-xmin 0.0 :left-xmax 0.1 :middle-xmin 0.1 :middle-xmax 0.2 :right-xmin 0.5 :right-xmax 0.95 initargs))) ) (defun make-view-paragraph (&key (title "") (body "") (title-font wb:*help-key-font*) (body-font wb:*help-small-text-font*)) "Produce a help document paragraph ~ having title title and contents body." (let ((title-label (label :draw? NIL :justification '(:left :top) :font title-font :color q::*help-foreground-color*)) (paragraph (text-view :draw? NIL :justification '(:left :top) :font body-font :color q::*help-foreground-color*))) (setf (text-of title-label) (format NIL (format NIL "~a" title))) (setf (text-of paragraph) (format NIL (format NIL "~a" body))) (list title-label paragraph))) #| not used yet (defun make-help-views-arg-element (&key (title NIL title?) (items NIL items?) (title-font wb:*help-key-font*) (items-font wb:*help-small-text-font*)) (let ((title-label (label :draw? NIL :justification '(:left :top) :font title-font :color q::*help-foreground-color*)) (title-description (text-view :draw? NIL :justification '(:left :top) :font items-font :color q::*help-foreground-color*)) (views NIL)) (setf (text-of title-label) (format NIL (format NIL "~a" (if title? title "")))) (setf (text-of title-description) (format NIL (format NIL "~a argument(s):" (if title? title "")))) (setf views (list title-label title-description)) (when items? (loop for i in items do (let ((arg-label (label :draw? NIL :justification '(:left :top) :font items-font :color q::*help-foreground-color*)) (description (text-view :draw? NIL :justification '(:left :top) :font items-font :color q::*help-foreground-color*))) (setf (text-of arg-label) (format NIL (format NIL "~a" (car i)))) (if (cdr i) (if (> (length i) 2) (setf (text-of description) (format NIL (format NIL "Default is ~a. ~a" (second i) (third i)))) (setf (text-of description) (format NIL (format NIL "~a" (second i))))) (setf (text-of description) "")) (nconc views (list arg-label description))))) (setf views (append (list title-label title-description) views)) (format *terminal-io* "~&in make-help-views-arg-element ~%~ views = ~a" views) views) ) |#
9,418
Common Lisp
.l
218
26.990826
112
0.445246
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ffc3e203ad2b1dc19f65596dc0f0e7dceb3c5aa900a65219cd6c31978aa5db3d
33,881
[ -1 ]
33,882
tex-ext.lsp
rwoldford_Quail/source/documentation/tex-ext.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tex-ext.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991, 1994. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defvar tex-doc-style "quail" "The name of the TeX style file containing the TeX style extensions ~% for the documentation system.") ;;;-------------------------------------------------------------------------- ;;; ;;; A header box taking three arguments. ;;; ;;;-------------------------------------------------------------------------- (defun write-tex-header-box (destination &key (left nil left?) (middle nil middle?) (right nil right?)) "Writes the TeX commands which produce a boxed header ~% with left left-justified horizontally, middle centred, and right ~% right-justified." (format destination "~&\\headerbox{") (if left? (write-tex-value destination left)) (format destination "}{") (if middle? (write-tex-value destination middle)) (format destination "}{") (if right? (write-tex-value destination right)) (format destination "}")) ;;;-------------------------------------------------------------------------- ;;; ;;; Write a doc-paragraph ;;; ;;;-------------------------------------------------------------------------- (defun write-tex-doc-paragraph (destination &key (title nil title?) (body nil body?)) "Writes the TeX commands which produce a document paragraph % having title title and contents body." (format destination "~& ~%~% {\\bf ") (if title? (write-tex-value destination title)) (format destination "}~%~% ~%") (if body? (write-tex-value destination (if (stringp body) (format NIL body) body))) (format destination "~&~%")) ;;;------------------------------------------------------------------------- ;;; ;;; Hanging paragraphs ;;; ;;;------------------------------------------------------------------------- (defun write-tex-begin-hang-par (destination &key (title nil title?)) "Writes the TeX commands to destination that are necessary to begin ~% a hanging paragraph. If title is given this is emphasised ~% as the first word in the paragraph." (format destination "~&\\beginhang") (when title? (format destination "~&{\\bf ") (write-tex-value destination title) (format destination "}~% \\hspace{2em}"))) (defun write-tex-end-hang-par (destination) "Writes the TeX commands to destination that are necessary to end ~% a hanging paragraph." (format destination "~& ~% \\endhang")) ;;;------------------------------------------------------------------------------ ;;; ;;; Our titled lists ;;; ;;;----------------------------------------------------------------------------- (defun write-tex-begin-titled-list (destination &key (title nil title?)) "Writes the TeX commands necessary to begin a titled list." (if title? (write-tex-begin-hang-par destination :title title) (write-tex-begin-hang-par destination)) ) (defun write-tex-end-titled-list (destination) "Writes the TeX commands necessary to end a titled list." (write-tex-end-hang-par destination) ) (defun write-tex-titled-list (destination &key (title nil title?) (items nil items?)) "Writes the TeX commands necessary to produce a titled list ~% of items." (if title? (write-tex-begin-titled-list destination :title title) (write-tex-begin-titled-list destination)) (if items? (loop for i in items do (format destination "\\hspace{2em}") (write-tex destination i))) (write-tex-end-titled-list destination)) (defun write-tex-titled-alist (destination &key (title nil title?) (items nil items?)) "Writes the TeX commands necessary to produce a titled list ~% of items." (if title? (write-tex-begin-titled-list destination :title title) (write-tex-begin-titled-list destination)) (if items? (loop for i in items do (if (cdr i) (write-tex-doc-paragraph destination :title (car i) :body (cdr i)) (write-tex-doc-paragraph destination :title (car i))))) (write-tex-end-titled-list destination)) (defun write-tex-arg-element (destination &key (title nil title?) (items nil items?)) "Writes the TeX commands necessary to produce a titled list ~% of items." (if title? (write-tex-begin-titled-list destination :title title) (write-tex-begin-titled-list destination)) (when items? (loop for i in items do (cond ((cdr i) (write-tex-doc-paragraph destination :title (car i) :body (if (> (length i) 2) (format NIL "Default is ~a. ~a" (second i) (third i)) (second i)) ) ) (T (write-tex-doc-paragraph destination :title (car i)))))) (write-tex-end-titled-list destination)) ;;;-------------------------------------------------------------------------- ;;; ;;; Write out examples ;;; ;;;-------------------------------------------------------------------------- (defun write-tex-doc-examples (destination &key (title "Examples") (examples nil)) "Produce a help document string for examples ~% having title title and examples examples." (cond ((and (assoc :root examples) (assoc :text examples)) (write-tex-doc-paragraph destination :title title :body (cdr (assoc :root examples))) (write-tex-doc-paragraph destination :body (cdr (assoc :text examples))) (when (assoc :files examples) (write-tex-doc-paragraph destination :body "See also the following files.") (write-tex-titled-alist destination :items (loop for info in (cdr (assoc :files examples)) collect (cons (car info) (cadr info))) )) ) ((assoc :root examples) (write-tex-doc-paragraph destination :title title :body (cdr (assoc :root examples))) (when (assoc :files examples) (write-tex-doc-paragraph destination :body "See also the following files.") (write-tex-titled-alist destination :items (loop for info in (cdr (assoc :files examples)) collect (cons (car info) (cadr info))) )) ) ((assoc :text examples) (write-tex-doc-paragraph destination :title title :body (cdr (assoc :text examples))) (when (assoc :files examples) (write-tex-doc-paragraph destination :body "See also the following files.") (write-tex-titled-alist destination :items (loop for info in (cdr (assoc :files examples)) collect (cons (car info) (cadr info))) )) ) ((assoc :files examples) (write-tex-titled-alist destination :title title :items (loop for info in (cdr (assoc :files examples)) collect (cons (cadr info) (car info)))) ) ) )
8,698
Common Lisp
.l
220
28.686364
82
0.469239
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bbc3d5efc6238e4abcf9cec4300ad408072c3003ce3fe73d50d53274e77163b1
33,882
[ -1 ]
33,883
edit-file.lsp
rwoldford_Quail/source/documentation/edit-file.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; edit-file.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(edit-file))) (defun edit-file (&optional pathname) "Opens an edit window. If pathname is given, it opens ~ the window to edit the file named by pathname." (let ((fname (qk::force-to-pathname pathname))) ;(force-to-pathname pathname))) (cond ((null fname) (ed)) ((probe-file fname) (ed fname)) (T (vw::inform-user (format NIL "~%Sorry ~s was not found." fname)) ;(inform-user (format NIL "~%Sorry ~s was not found." fname)) ))))
1,066
Common Lisp
.l
27
36.259259
133
0.438409
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
62f4f30725743acbce51389dc996eec8f5e088db27afccaf99df59942aaf5fc4
33,883
[ -1 ]
33,884
write-doc.lsp
rwoldford_Quail/source/documentation/write-doc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; write-doc.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(write-doc))) ;;;----------------------------------------------------------------------------- ;;; ;;; The two driving functions write-doc and get-doc-form ;;; ;;;----------------------------------------------------------------------------- (defgeneric write-doc (destination documentation-object) (:documentation "Writes a form to destination which, when evaluated, sets the ~ Common Lisp documentation of a symbol ~ to correspond to the Quail documentation.")) (defgeneric get-doc-form (documentation-object) (:documentation "Returns a form which, when evaluated, sets the ~ common lisp documentation of a symbol ~ to correspond to the quail documentation.")) ;;;----------------------------------------------------------------------------- ;;; ;;; Methods for write-doc ... a single one should suffice. ;;; ;;;----------------------------------------------------------------------------- (defmethod write-doc (destination (q-d documentation-object)) (pprint (get-doc-form q-d) destination)) ;;;----------------------------------------------------------------------------- ;;; ;;; Methods for get-doc-form ;;; ... specialized for each kind of documentation-object. ;;; ;;;----------------------------------------------------------------------------- ;;;--------------------------------------------------------------------------- ;;; ;;; Quail documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((q-d documentation-object)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics)) q-d `(make-instance 'documentation-object :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics))) ;;;--------------------------------------------------------------------------- ;;; ;;; Built in class documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((bic-d built-in-class-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics)) bic-d `(make-instance 'built-in-class-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics))) ;;;--------------------------------------------------------------------------- ;;; ;;; Structure documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((s-d structure-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics)) s-d `(make-instance 'structure-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics))) ;;;--------------------------------------------------------------------------- ;;; ;;; Constant documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((c-d constant-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (value value)) c-d `(make-instance 'constant-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :value ',value))) ;;;--------------------------------------------------------------------------- ;;; ;;; Variable documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((v-d variable-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (value value)) v-d `(make-instance 'variable-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :value ',value))) ;;;--------------------------------------------------------------------------- ;;; ;;; Parameter documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((p-d parameter-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (value value)) p-d `(make-instance 'parameter-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :value ',value))) ;;;--------------------------------------------------------------------------- ;;; ;;; Function documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((f-d function-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (lam-list lambda-list) (arg arguments)) f-d `(setf (doc ',symbol :function) (make-instance 'function-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :lambda-list ',lam-list :arguments ,(get-doc-form arg))))) ;;;--------------------------------------------------------------------------- ;;; ;;; Macro documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((m-d macro-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (lam-list lambda-list) (arg arguments)) m-d `(setf (doc ',symbol :macro) (make-instance 'macro-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :lambda-list ',lam-list :arguments ,(get-doc-form arg))))) ;;;--------------------------------------------------------------------------- ;;; ;;; Special-form documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((sf-d special-form-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (lam-list lambda-list) (arg arguments)) sf-d `(setf (doc ',symbol :special-form) (make-instance 'special-form-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :lambda-list ',lam-list :arguments ,(get-doc-form arg))))) ;;;--------------------------------------------------------------------------- ;;; ;;; Generic-function documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((gf-d generic-function-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (lam-list lambda-list) (arg arguments)) gf-d `(setf (doc ',symbol :generic-function) (make-instance 'generic-function-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :lambda-list ',lam-list :arguments ,(get-doc-form arg))))) ;;;--------------------------------------------------------------------------- ;;; ;;; Method documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((m-d method-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (lam-list lambda-list) (arg arguments)) m-d `(setf (doc ',symbol :method) (make-instance 'method-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :lambda-list ',lam-list :arguments ,(get-doc-form arg))))) ;;;--------------------------------------------------------------------------- ;;; ;;; Argument documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((a-i argument-documentation)) (with-accessors ((&required &required) (&rest &rest) (&key &key) (&optional &optional) (&aux &aux) (&allow-other-keys &allow-other-keys)) a-i `(make-instance 'argument-documentation :&required ',&required :&rest ',&rest :&key ',&key :&optional ',&optional :&aux ',&aux :&allow-other-keys ',&allow-other-keys))) ;;;--------------------------------------------------------------------------- ;;; ;;; Class documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((c-d class-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (class-object doc-class-object) (super-classes doc-super-classes) (class-precedence-list doc-class-precedence-list) (sub-classes doc-sub-classes) (accessors doc-accessors) (slots doc-slots) ) c-d `(setf (doc ',symbol :class) (make-instance 'class-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :class (find-class ',(class-name class-object)) :super-classes ,(let (result) (setf result (loop for class in super-classes collect (list 'find-class (list 'quote (class-name class))))) (if result (push 'list result)) result) :class-precedence-list ,(let (result) (setf result (loop for class in class-precedence-list collect (list 'find-class (list 'quote (class-name class))))) (if result (push 'list result)) result) :sub-classes ,(let (result) (setf result (loop for class in sub-classes collect (list 'find-class (list 'quote (class-name class))))) (if result (push 'list result)) result) :accessors ',accessors :slots ,(get-doc-form slots) ) ) ) ) ;;;--------------------------------------------------------------------------- ;;; ;;; Slots documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((ss-d slots-documentation)) (with-accessors ((capsule doc-capsule) (class doc-class-object) (name name) (package package) (elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) ) ss-d `(make-slots-documentation (find-class ',(class-name class)) :doc-capsule ,capsule :doc-elaboration ,elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics) ) ) #| ;;;--------------------------------------------------------------------------- ;;; ;;; Slot documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((s-d slot-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (initarg slot-initargs) (initform slot-initform) (reader slot-readers) (writer slot-writers) (type slot-type)) s-d `(setf (doc ',symbol :slot) (make-instance 'slot-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :initargs ,initarg :initform ,initform :readers ,reader :writers ,writer :type ,type)))) |# ;;;--------------------------------------------------------------------------- ;;; ;;; Topic documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((t-d topic-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (super-topics super-topics) (sub-topics sub-topics)) t-d `(make-instance 'topic-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :sub-topics ',sub-topics ))) ;;;--------------------------------------------------------------------------- ;;; ;;; Package documentation ;;; ;;;--------------------------------------------------------------------------- (defmethod get-doc-form ((p-d package-documentation)) (with-accessors ((name name) (package package) (symbol doc-symbol) (doc-capsule doc-capsule) (doc-elaboration doc-elaboration) (examples examples) (references references) (see-also see-also) (sub-topics sub-topics) (super-topics super-topics)) p-d `(make-instance 'package-documentation :name ,name :package ,package :symbol ',symbol :doc-capsule ,doc-capsule :doc-elaboration ,doc-elaboration :examples ',examples :references ,references :see-also ',see-also :super-topics ',super-topics :sub-topics ',sub-topics)))
20,596
Common Lisp
.l
600
25.706667
86
0.459699
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f4ae102ffe1caac282b583d136b6840d0cfe2f7c7ab88da5af076faebd9d899c
33,884
[ -1 ]
33,885
documentation-string.lsp
rwoldford_Quail/source/documentation/documentation-string.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; documentation-string.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1994 ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) ;;;; GLOBAL VARIABLE (defvar *doc-keywords* NIL "Adding to this list allows for flexibility in ~ the documentation system.") (setf *doc-keywords* (list ":root" ":capsule" ":elaboration" (list ":examples" ":files" ":text") ":references" ":see-also" #|(list ":see-also" ":constant" ":variable" ":parameter" ":function" ":special-form" ":macro" ":generic-function" ":method" ":built-in-class" ":structure" ":class" ":package") |# ":super-topics" ":topics" ":sub-topics" ":returns" ":side-effects" ":package" ":name" (list ":required" ":arg") (list ":optional" ":arg") (list ":rest" ":arg") (list ":key" ":arg") (list ":aux" ":arg") (list ":body" ":arg") )) ;;;; MAIN FUNCTION (defun interpret-quail-documentation (doc) (declare (special *doc-keywords*)) (if (null doc) NIL ;;(interpret-quail-documentation "(:capsule No description available.)") (let ((doc-tree (make-key-tree *doc-keywords*))) (decorate doc-tree (root-tree doc-tree) (root-pedigree doc-tree) (protect-parenthetical-phrases (read-string (protect-macro-characters doc))))))) ;;;; READING AND WRITING (defun read-string (str) (let (#+(not :aclpc) (read-case (readtable-case *readtable*)) ) (tree-apply #'(lambda (x) (cond ((symbolp x) (if (equalp (package-name (symbol-package x)) "keyword") (concatenate 'string ":" (string x)) (string x))) (t x))) (unwind-protect (progn #+(not :aclpc) (setf (readtable-case *readtable*) :preserve) (with-input-from-string (s str) (do ((token (read s NIL NIL) (read s NIL NIL)) (result nil (push token result))) ((null token) (nreverse result)) () ))) #+(not :aclpc) (setf (readtable-case *readtable*) read-case) )))) ;;;; MISCELLANEOUS FUNCTIONS (defun protect-macro-characters (str &aux result) (let ((str (format nil str))) (concatenate 'string (dotimes (i (length str) (nreverse result)) (let ((ch (elt str i))) (cond ((member ch '(#\Newline #\Space) :test #'char=) (push ch result)) ((member ch '(#\) #\() :test #'char=) (push #\Space result) (push ch result) (push #\Space result)) ((not (alphanumericp ch)) (push #\\ result) (push ch result)) (t (push ch result)))))))) (defun protect-parenthetical-phrases (seq) (labels ((ppp (item) (let ((keywords (flatten *doc-keywords*))) (cond ((null item) nil) ((atom item) (list item)) ((and (stringp (car item)) (find (car item) keywords :test #'string=)) (list (mapcan #'ppp item))) (t (append (list "(") (mapcan #'ppp item) (list ")"))) )))) (mapcan #'ppp seq)))
4,344
Common Lisp
.l
113
24.725664
87
0.408173
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6e06d5a6b2dabf3d6db9aa805ffed097a6eb02bfc897d242ad7eeeb24a84532b
33,885
[ -1 ]
33,886
inform-user.lsp
rwoldford_Quail/source/documentation/inform-user.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; inform-user.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(inform-user inform-user-busy *info-background-color* *info-foreground-color* set-info-pen-color set-info-background-color))) (defvar *info-window* NIL "Information window for user.") (defvar *info-text* NIL "Information for user.") (defvar *info-background-color* wb::*gray-color* "The default background colour for info windows.") (defvar *info-foreground-color* wb::*black-color* "The default foreground or pen colour for info windows.") (defclass info-window (view-window) () (:documentation "An empty class to distinguish the information window from other ~ view-windows. This is especially convenient when closing all ~ view-windows of a particular type.")) ;;; added 28FEB2024 in response to error on right-click highlighted points in THE plot under full Allegro #+:aclpc(acl-mop::finalize-inheritance (find-class 'vw::info-window)) (defun info-window () "Returns the information window. Creates it if it didn't already exist." (declare (special *info-window*)) (unless *info-window* (setf *info-window* (make-view-window :left 10 :right 500 :bottom (- (wb::screen-height) 300) :top (- (wb::screen-height) 50) :view-window-class 'info-window ;;:window-show NIL :background-color *info-background-color* :pen-color *info-foreground-color* :title "Information"))) *info-window*) (defun set-info-pen-color (&optional (color (wb:prompt-user-for-color))) "Sets the foreground or pen colour of the information window to color. ~ If color is not supplied the user is prompted to choose a color." (when (wb::canvas-p *info-window*) (wb:set-pen-color *info-window* color)) (when *info-text* (set-drawing-style *info-text* :color color)) (setf *info-foreground-color* color)) (defun set-info-background-color (&optional (color (wb:prompt-user-for-color))) "Sets the background colour of the information window to color. ~ If color is not supplied the user is prompted to choose a color." (when (wb::canvas-p *info-window*) (wb::canvas-set-background-color *info-window* color)) (setf *info-background-color* color)) (defun info-text-view () (declare (special *info-text* wb::*help-normal-text-font*)) (unless (view-p *info-text*) (setf *info-text* (text-view :draw? NIL :justification '(:left :top) :font wb::*help-normal-text-font* :color *info-foreground-color*)) ) *info-text*) (defun info-window-alive-p () (let ((i-w (info-window))) (and (wb::canvas-p i-w) (wb::canvas-visible-p i-w)) )) (defun inform-user (message) "Informs the user about the message. ~ (:required (:arg message String to be displayed to the user.)) ~ (:returns No value.)" (let ((i-t (info-text-view)) (i-w (info-window))) (setf (text-of i-t) (format NIL "~a" (format NIL "~%~a" message))) (cond ((info-window-alive-p) (wb::canvas-clear i-w) (wb::canvas-to-top i-w) (if (viewports-of i-t) (draw-view i-t) (draw-view i-t :viewport (make-viewport i-w)))) (T (setf *info-window* NIL) (setf (viewports-of i-t) NIL) ;;(loop for vp in (viewports-of i-t) ;; do (remove-view i-t :viewport vp)) (setf i-w (info-window)) (draw-view i-t :viewport (make-viewport i-w)))))) (let ((i 0)) (defun inform-user-busy () "A signal to the user that something is happening. ~ Repeated calls will show something changing on the screen." (setf i (mod (+ i 1) 10)) (cond ((zerop i) (vw::inform-user "***")) ((= i 1) (vw::inform-user " ***")) ((= i 2) (vw::inform-user " ***")) ((= i 3) (vw::inform-user " ***")) ((= i 4) (vw::inform-user " ***")) ((= i 5) (vw::inform-user " ***")) ((= i 6) (vw::inform-user " ***")) ((= i 7) (vw::inform-user " ***")) ((= i 8) (vw::inform-user " ***")) ((= i 9) (vw::inform-user " ***")))))
4,971
Common Lisp
.l
115
35.521739
106
0.542394
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0f6be778c4dc65240fbbce6bcb8277d1e894ede44948a32475509baf7be8b02b
33,886
[ -1 ]
33,887
document-symbols.lsp
rwoldford_Quail/source/documentation/document-symbols.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; document-symbols.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1991 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(document-symbols *user-doc-out-path-function*))) (defvar *user-doc-out-path-function* NIL "A variable whose value is either NIL or is a function of two arguments, ~ a symbol and a doc-type (e.g. :function :macro :topic, et cetera). ~ When funcalled on a symbol and doc-type, the function must return a complete ~ path name for the output documentation file that will be automatically generated ~ by document-symbols. ~ If NIL, the path used will be the same as for the quail system documentation. ~ This variable allows the user to generate quail documentation for ~ his or her own symbols, or even to override the provided quail documentation." ) (defun doc-by-types (sym &key (package nil) (types nil)) "Document the symbol in the specified (or home) package according to ~ its use in the corresponding list of types." (declare (special *user-doc-out-path-function*)) ;; ;; Get the types to be a non-NIL list if possible. ;; (if types (setf types (intersection types (documentable-uses sym package))) (setf types (documentable-uses sym package))) (unless (listp types) (setf types (list types))) ;; ;; Now document it for all the types mentioned. ;; (if types (let ((ofile-fun (if (functionp *user-doc-out-path-function*) *user-doc-out-path-function* #'doc-auto-path-name))) (loop for type in types do (with-open-file (ofile (funcall ofile-fun sym type) :direction :output :if-exists :append :if-does-not-exist :create) (write-doc ofile (doc sym type))))))) ;;;----------------------------------------------------------------------------------------------- ;;; ;;; Produce document files for all symbols in a list or all symbols ;;; in a package. ;;; ;;;----------------------------------------------------------------------------------------------- (defun document-symbols (&key package symbol-list types) "Constructs documentation for all external symbols given by ~ package or only those specified ~ by symbol-list. If given, types is a list of the ~ type of symbol usage to be documented (e.g. '(function macro class)). ~ Otherwise all documentable types will be constructed." (if symbol-list (if package (loop for sym in symbol-list do (if (null sym) (doc-by-types sym :types types) (if (setf sym (find-symbol (string sym) package)) (doc-by-types sym :package package :types types)))) (loop for sym in symbol-list do (doc-by-types sym :types types))) (do-external-symbols (sym package) (doc-by-types sym :package package :types types)) ))
3,590
Common Lisp
.l
82
35.780488
114
0.530512
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b9e9e1bdc7da0e81cdf2fef98b58fdfe12c146a4d3f997dcca52347ca7588bc8
33,887
[ -1 ]
33,888
document-topics.lsp
rwoldford_Quail/source/documentation/document-topics.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; document-topics.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1991 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; m.e. lewis 1991. ;;; r.w. oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(document-topics))) (defun document-topics (package) "Document-topics interactively produces topic-documentation for the given package. ~ All external symbols of the named package are looped over and the user prompted ~ to assign each to one topic at a time (as named by the user). ~ Many passes through the list of symbols and their documentation type are made. ~ At each iteration the list is reduced to the list of those symbols which have not ~ yet been assigned. ~ Iteration stops when either the list or the user is exhausted. ~ Returns multiple values: either the topmost topic-documentation object or a list ~ of the topic-documentation objects that were created, ~ the list of sub-topics that were considered, and the list of sub-topics that ~ remain unassigned." (let (first-doc-obj sub-topics all-topics) (multiple-value-setq (first-doc-obj sub-topics) (generate-topic (quail-query "~&Please give a name for the first topic: ") :package package :prompt? T)) (let (current-doc-obj (remaining-topics (set-difference sub-topics (sub-topics first-doc-obj)))) (setf all-topics (append (list first-doc-obj) (loop for i from 1 until (or (not (quail-yes-or-no-p "~&Do you want to assign any of the remaining subtopics to ~ a new topic?")) (null remaining-topics)) do (setf current-doc-obj (generate-topic (quail-query "~&Please give a name for the next topic: ") :symbol-list remaining-topics :package package :prompt? T)) (setf remaining-topics (set-difference remaining-topics (sub-topics current-doc-obj))) collect current-doc-obj))) (if (quail-yes-or-no-p "~&Should all of the topic-documentation objects constructed here ~ be stored as sub-topics of some larger topic?") ;;then (let* ((top-doc-sym (quail-query "~&Please give a name for this larger topic: ")) (top-doc-obj (doc top-doc-sym :topic))) (if top-doc-obj ;;then (if (quail-yes-or-no-p "~&A topic documentation of this name (~a) already exists. ~ Should I just add the new topics to it?" top-doc-sym) ;;then (progn (loop for st in all-topics do (install-sub-topic top-doc-obj st)) (values top-doc-obj sub-topics remaining-topics)) ;;else (if (quail-yes-or-no-p "~&Should I clear the old topic documentation for ~a and ~ install a new one in its place?" top-doc-sym) ;;then (progn (setf top-doc-obj (make-doc top-doc-sym :topic)) (setf (doc top-doc-sym :topic) top-doc-obj) (loop for st in all-topics do (install-sub-topic top-doc-obj st)) (values top-doc-obj sub-topics remaining-topics)) ;;else (values all-topics sub-topics remaining-topics))) ;;else (progn (setf top-doc-obj (make-doc top-doc-sym :topic)) (setf (doc top-doc-sym :topic) top-doc-obj) (loop for st in all-topics do (install-sub-topic top-doc-obj st)) (values top-doc-obj sub-topics remaining-topics)))) ;;else (values all-topics sub-topics remaining-topics)) )))
4,820
Common Lisp
.l
102
32.029412
95
0.495171
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
66d37717c3c8840bb1414588fe7344f16a61a682a1b62bbd116c2aafe172bc01
33,888
[ -1 ]