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,889
write-tex.lsp
rwoldford_Quail/source/documentation/write-tex.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; write-tex.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 '(write-tex))) ;;;---------------------------------------------------------------------------- ;;; ;;; The generic TeX write function: ;;; ;;; write-tex ;;; ;;;--------------------------------------------------------------------------- (defgeneric write-tex (destination-file thing) (:documentation "Writes TeX commands to the destination-file ~ to produce a TeX version of the second argument.")) ;;;--------------------------------------------------------------------------- ;;; ;;; The default case: T ;;; ;;; Just produces the printed representation of the argument. ;;; ;;;--------------------------------------------------------------------------- (defmethod write-tex (destination-file doc) (write-tex-value destination-file doc))
1,420
Common Lisp
.l
37
34.27027
80
0.348786
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1379019a195af4b8c60b2249481b12aaa42cb29505563ec8b30867ff75939fe9
33,889
[ -1 ]
33,890
help-display.lsp
rwoldford_Quail/source/documentation/help-display.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; help-display.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-display))) (defgeneric help-display (thing &optional help-type) (:documentation "Displays in an interactive window ~% help information of type help-type on thing.")) ;;;-------------------------------------------------------------------------- ;;; ;;; T ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display (thing &optional help-type) (declare (ignore help-type)) (inform-user (format NIL "Sorry, no help is yet available for:~% ~s ." thing))) ;;;-------------------------------------------------------------------------- ;;; ;;; Numbers ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display ((thing number) &optional help-type) (declare (ignore help-type)) (inform-user (format NIL "Sorry, not much help here.~% ~s is simply a number." thing))) ;;;-------------------------------------------------------------------------- ;;; ;;; lists ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display ((items list) &optional (help-type NIL)) "If help-type is non-NIL, then help is called repeatedly on the items ~% in the list with the given help-type. If help-type is NIL and there ~% are exactly two items in the items list and the second item is a legitimate ~% doc-type, then the ~% second item in the list is taken to be the help type. ~% Otherwise help is called ~% on each item in the list with no type specified. ~% (:see-also doc-type-p quail-doc-types)" (cond (help-type (loop for i in items do (help i help-type))) ((= (length items) 2) (if (qk::doc-type-p (second items)) (help (first items) (second items)) (loop for i in items do (help i)))) (T (loop for i in items do (help i))))) ;;;-------------------------------------------------------------------------- ;;; ;;; strings ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display ((thing string) &optional (help-type NIL)) (help-display (destring thing) help-type)) ;;;-------------------------------------------------------------------------- ;;; ;;; Symbols ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display ((sym symbol) &optional (help-type NIL)) (let ((help-types (if help-type (list help-type) (qk::help-types sym (symbol-package sym))))) (if help-types ;;then (if (> (length help-types) 1) ;; then (let ((selected-help-type (wb::pick-one (cons :none help-types) :prompt-text (format NIL "Help is available on ~s for the following types:~%~% Please specify which one you would like (or :NONE to cancel ~% request). " sym) ))) (if (and selected-help-type (not (eq selected-help-type :NONE))) ;; then (let ((doc-object (doc sym selected-help-type))) (if doc-object ;; then (help-display doc-object) ;; else (inform-user (format NIL "Sorry, the symbol - ~s - has no help available for help-type ~s." sym selected-help-type)))) ;; else do nothing )) ;; else (let ((doc-object (doc sym (car help-types)))) (if doc-object ;; then (help-display doc-object) ;; else (inform-user (format NIL "Sorry, the symbol - ~s - has no help available for help-type ~s." sym help-type)))) ) ;;else see if there is a general topic corresponding to this symbol (let ((general-topic? (doc sym :topic))) (if general-topic? (help-display general-topic?) (inform-user (format NIL "Sorry, the symbol - ~s - has no help available." sym)))))) ) ;;;-------------------------------------------------------------------------- ;;; ;;; documentation-object ;;; ;;;-------------------------------------------------------------------------- (defmethod help-display ((thing qk::documentation-object) &optional (help-type NIL)) (let* ((h-v (make-instance 'help-view :viewed-object thing :help-type (or help-type (qk::doc-type thing)))) (vw (make-help-window :width (help-window-width h-v) :height (help-window-height h-v))) (vp (make-viewport vw))) (draw-view h-v :viewport vp) h-v))
6,029
Common Lisp
.l
144
31.069444
104
0.396919
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c99852e84d68e008047f7704f3753442d4f0c9a56e0b82bc22fd0688115d6709
33,890
[ -1 ]
33,891
doc.lsp
rwoldford_Quail/source/documentation/doc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; 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 '(doc clear-doc *user-doc-path-functions*))) ;;;----------------------------------------------------------------------------- ;;;----------------------------------------------------------------------------- ;;; ;;; THE routines for accessing and setting the documentation. ;;; ;;;----------------------------------------------------------------------------- (defun set-doc (thing doc-type documentation-object) (setf (get thing doc-type) documentation-object)) (defsetf doc set-doc) (defvar *user-doc-path-functions* NIL "A variable whose value is either NIL or is a list of functions of two arguments, ~ a symbol and a doc-type (e.g. :function :macro :topic, et cetera). ~ If non-NIL this list of functions will be used on a symbol and a doc-type ~ to determine the complete path name ~ where the documentation can be found. ~ Each function is tried from the beginning to the end of the list until ~ a file is found. ~ If either the list is NIL (the default), or no function on it ~ produces an existing file, then the quail system functions are tried. ~ This variable allows the user to access quail documentation for ~ his or her own symbols, or even to override the provided quail~ documentation.") (defun set-doc-from-file (symbol doc-type) (declare (special *user-doc-path-functions*)) (let* ((quail-file-functions ;; The default quail doc path functions (if (eq doc-type :topic) ;; topics are symbols that may not yet be in any package (list #'doc-general-topics-path-name #'doc-path-name #'doc-auto-path-name) (list #'doc-path-name #'doc-auto-path-name))) (file-functions (if (and *user-doc-path-functions* (listp *user-doc-path-functions*)) (append *user-doc-path-functions* quail-file-functions) quail-file-functions))) (if ;; Is there documentation available on file? (loop for f in file-functions when ;; If successful, the following load attaches the documentation ;; to the symbol (load (funcall f symbol doc-type) :if-does-not-exist nil) return T) ;; Then use it (get symbol doc-type) ;; Else return NIL NIL))) (defun clear-doc (thing &optional doc-type) "Clears the Quail documentation for its first argument ~ of type given by its second argument. If doc-type is missing, ~ then all Quail documentation is cleared." (if doc-type (remprop thing doc-type) (loop for dt in (quail-doc-types) do (remprop thing dt)))) (defun doc (thing doc-type) "Accesses the quail documentation for its first argument ~ of type given by its second argument." (if (symbolp thing) (or (get thing doc-type) (and (set-doc-from-file thing doc-type) (get thing doc-type)) (and ;; Don't want to make new topics on the fly. (not (eq doc-type :topic)) (setf (doc thing doc-type) (make-doc thing doc-type)))) (make-doc thing doc-type)))
3,742
Common Lisp
.l
91
35.076923
107
0.550673
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a0b4e9a496ab482841161baab7687b8b336c7dc58457700de3b4bfe4ba5b5fde
33,891
[ -1 ]
33,892
browser-menu.lsp
rwoldford_Quail/source/browser/browser-menu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser-menu.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; ;;; it contains the functions peculiar to menus created by browsers ;;; (in-package :quail) ;;; the following is intimately related to the design of menus in window-basics ;;; and to using a global variable for the *current-canvas* that is updated ;;; for canvases (eval-when (:compile-toplevel :load-toplevel :execute) (export '(browser-when-held-fn browser-title-when-selected-fn browser-body-when-selected-fn ))) (defun browser-when-held-fn (item menu key) "What to do when the menu item is held." (declare (ignore menu key)) (when (listp item) (quail-print (third item)))) (defun browser-body-when-selected-fn (item menu mouse-button) "Special selection function that calls the function in the menu ~ on the value of *current-canvas*." (wb::default-when-selected-fn item menu mouse-button)) (defun browser-title-when-selected-fn (item menu mouse-button) "Special selection function that calls the function in the menu ~ on the value of *current-canvas*." (wb::default-when-selected-fn item menu mouse-button)) (defun return-item-when-selected-fn (item menu mouse-button) "Special selection function that returns the item if it's not a list ~ or the second element in item if it is a list." (declare (ignore menu mouse-button)) (if (and (typep item 'sequence) (>= (length item) 2)) (second item) item))
1,972
Common Lisp
.l
49
36.081633
86
0.581799
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c1a851db8013408ac46e9d9e382c564adc5f224708d09b68e1d357091605e875
33,892
[ -1 ]
33,893
browser-package.lsp
rwoldford_Quail/source/browser/browser-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- #+:cl-2 (defpackage "BROWSER" (:use "WINDOW-BASICS" "COMMON-LISP" #+:ccl "CCL" ) (:import-from "QUAIL" "QUAIL-PRINT" "QUAIL-ERROR") (:import-from "QUAIL-KERNEL" "GENERIC-FUNCTION-P" "DIRECT-SUBCLASSES" "CLASS-P" "PRECEDENCE-LIST") ) #-:cl-2 (in-package "BROWSER" :use '(grapher window-basics pcl lisp ) )
1,008
Common Lisp
.l
37
19.351351
84
0.319545
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cd2e852bbdf806718c25923296259f309a3da211b503b423250b8ce86efbc9d7
33,893
[ -1 ]
33,894
browser.lsp
rwoldford_Quail/source/browser/browser.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*graph-format-choices* *horiz-lattice* *horiz-tree* *vertical-lattice* *vertical-tree* bad-list cache-menu-p copies-only graph-format label-cache bad-list-of good-list-of starting-list-of graph-format-of label-cache-of lattice left-button-items left-button-items-of left-title-items left-title-items-of local-commands menu-cache middle-button-items middle-title-items middle-title-items-of right-title-items-of shift-left-button-items shift-middle-button-items starting-list title vertical))) ;;; ;;; variables definition ;;; (defvar *horiz-lattice* (list 'lattice)) (defvar *horiz-tree* (list 'copies-only)) (defvar *vertical-lattice* (list 'reverse 'vertical 'lattice)) (defvar *vertical-tree* (list 'reverse 'vertical 'copies-only)) (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *graph-format-choices* (list '("horizontal lattice" (lattice)) '("vertical lattice" (reverse vertical lattice)) '("horizontal tree" (copies-only)) '("vertical tree" (reverse vertical copies-only))))) ;;; ;;; Class definition ;;; (defclass browser (wb::canvas) ((icon :initarg :icon :accessor icon-of :initform nil) (icon-w :initarg :icon-w :accessor icon-w-of :initform nil) (selected-nodes :initarg :selected-nodes :accessor selected-nodes-of :initform nil) (box-line-width :initform 1 :allocation :class) (local-commands :initform (list #'recompute #'add-root) :allocation :class :accessor local-commands-of) (left-button-items :initform (list (list "Flash node" #'flash-node "Flashes the selected node.")) :allocation :class :accessor left-button-items-of) (shift-left-button-items :initform nil :allocation :class :accessor shift-left-button-items-of) (middle-button-items :initform (list (list "Inspect" #'inspect "Inspect selected node.")) :allocation :class :accessor middle-button-items-of) (shift-middle-button-items :initform nil :allocation :class :accessor shift-middle-button-items-of) (right-button-items :initform nil :allocation :class :accessor right-button-items-of) (graph-format-choices :initform *graph-format-choices* :accessor graph-format-choices-of :allocation :class) (cache-menu? :initform t :accessor cache-menu-p) (menu-cache :initform nil :accessor menu-cache-of) (top-align :initform t :accessor top-align-p) (starting-list :initform nil :accessor starting-list-of) (good-list :initform nil :accessor good-list-of) (bad-list :initform nil :accessor bad-list-of) (label-cache :initform nil :accessor label-cache-of) (graph-format :initform *horiz-lattice* :accessor graph-format-of)) (:default-initargs :middle-title-items (list (list "Add Root" #'add-root "Add named item to starting list for browser.") (list "Recompute" #'recompute "Recompute Lattice from starting list objects." :sub-items (list (list "Recompute" #'recompute "Recompute Lattice from starting list objects.") (list "Recompute labels" #'recompute-labels "Recompute the labels.") (list "In place" #'recompute-in-place "Recompute keeping current view in window.") (list "Shape to hold" #'shape-to-hold "Make window large or small enough to just hold graph.") ;; Commented out until fixed. ;;(list "Change Format" #'change-format ;; "Change format between Lattice and Tree.") ))))) (defun browser-redisplay (canvas) (wb::canvas-clear canvas) (redisplay-graph canvas)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; make-browser ;;; (defun make-browser (&rest initargs &key (color? NIL color-supplied?) (browser-class 'browser) left right bottom top region font (title "browser")) "Creates a new window. Region is a list (left bottom width height) ~ the dimensions are those of the content region of the window." (unless (stringp title) (setf title (format nil "~a" title))) (when (wb::region-p region) (multiple-value-setq (left right bottom top) (wb::region-bounds region))) (let ((canvas (if (and left right bottom top) (apply #'wb:make-canvas :canvas-class browser-class :title title :left left :bottom bottom :font (or font *graph-default-node-font*) :width (1+ (- right left)) :height (1+ (- top bottom)) :color? (if color-supplied? color? (wb:color-device-p)) initargs) (apply #'wb:make-canvas :canvas-class browser-class :title title :left 10 :bottom (max 10 (- (wb::screen-height) 350)) :width 400 :height (min 300 (- (wb::screen-height) 10)) :color? (if color-supplied? color? (wb:color-device-p)) :font (or font *graph-default-node-font*) initargs)))) (wb::set-left-button-fn canvas #'*browser-left-button-fn*) (wb::set-middle-button-fn canvas #'*browser-middle-button-fn*) (wb::set-right-button-fn canvas #'*browser-right-button-fn*) (wb::set-ctrl-left-button-fn canvas #'*browser-ctrl-left-button-fn*) (wb::set-ctrl-middle-button-fn canvas #'*browser-ctrl-middle-button-fn*) (wb::set-ctrl-right-button-fn canvas #'*browser-ctrl-right-button-fn*) (wb::set-shift-left-button-fn canvas #'*browser-shift-left-button-fn*) (wb::set-shift-middle-button-fn canvas #'*browser-shift-middle-button-fn*) (wb::set-shift-right-button-fn canvas #'*browser-shift-right-button-fn*) (wb::set-redisplay-fn canvas #'browser-redisplay) (wb::show-canvas canvas) canvas))
7,603
Common Lisp
.l
214
25.579439
88
0.53592
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
57fcad371903b3c85aded9d009d91eea661558d0f71bf5751720532e6c62ded5
33,894
[ -1 ]
33,895
hacks.lsp
rwoldford_Quail/source/browser/hacks.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; window-basics-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(compute-window-height compute-window-width))) (defun compute-window-height (height title-height) (declare (ignore title-height)) (+ height 30)) (defun compute-window-width (width title) (declare (ignore title)) (- width 15))
807
Common Lisp
.l
23
32.130435
111
0.433766
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e2378ec445839e03b48d84015fa14fde840259720a0aab55d6b1ca42a08ee457
33,895
[ -1 ]
33,896
grapher-draw.lsp
rwoldford_Quail/source/browser/grapher-draw.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher-draw.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; J.R. MacPhail 1995 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This file is that part of the old "grapher.lisp" to do with drawing a whole graph. ;;; Drawing of individual nodes and links is in graph-node.lisp and graph-link.lisp (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(show-graph move-node))) ;; This display-graph ALWAYS calls adjust-graph-positions (why?). ;; Also notice that highlighted nodes are drawn twice, which is crude. -- jrm (defun display-graph (graph window clipping-region &optional line-width) "Displays graph on WINDOW. ~ Draws links first, then labels so that lattices don't have lines through ~ the labels." (wb:with-focused-canvas window (let* ((gr (graph-region graph)) (g-top (wb:region-top gr)) (g-left (wb:region-left gr)) (c-region (wb:canvas-region window)) (c-top (wb:region-top c-region)) (c-left (wb:region-left c-region)) (y-adjust (if (> g-top c-top) (- c-top g-top) 0)) (x-adjust (if (< g-left c-left) (- c-left g-left) 0))) (adjust-graph-positions graph x-adjust y-adjust) (dolist (n (graph-node-lst graph)) (display-node-links n window graph t line-width)) (dolist (n (graph-node-lst graph)) (print-display-node n window clipping-region)) (let ((nodes (selected-nodes-of window))) (if nodes (dolist (node nodes) (flip-node node window))))))) (defun redisplay-graph (window &rest rest) "Displays the graph that is in a window." (declare (ignore rest)) (wb:canvas-clear window) (when (wb:display-of window) (display-graph (wb:display-of window) window ;;(wb:canvas-region window) (wb:clipping-region-of window)))) ;; Largely rewritten. I took out the calls that resized the window four times. ;; It is still necessary to fix this so TOP-JUSTIFY-FLAG is properly heeded. -- jrm (defun size-graph-window (graph window-or-title &optional (top-justify-flg T)) "Returns a window sized to fit the given graph. WINDOW-OR-TITLE can be ~ either a window to be printed in or a title of a window to be created.If ~ TOP-JUSTIFY-FLG is T, scrolls so top of graph is at top of window, else ~ puts bottom of graph at bottom of window." (declare (special *min-width-graph* *min-height-graph*) (ignore TOP-JUSTIFY-FLG)) (prog ((window)) (cond ((wb:canvas-p window-or-title) (setq window window-or-title) (wb:canvas-to-top window-or-title)) (t (setq window (make-browser :title (or window-or-title "Network display"))))) (wb:shape-canvas window (max (wb:region-width (graph-region graph)) *min-width-graph*) (max (wb:region-height (graph-region graph)) *min-height-graph*)) (return window))) (defun show-graph (&optional graph window top-justify-flg) "Puts the graph in a new window, creating a graph if none is given." (setq window (size-graph-window (or graph (setq graph (make-graph))) window top-justify-flg)) (setf (wb:display-of window) graph) (redisplay-graph window) window) (defun move-node-to (node to-pos window &optional clipping-region) (wb:with-focused-canvas window (let* ((graph (wb:display-of window))) (erase-node-links node window graph) (erase-node-label node window) (set-node-centre node to-pos) (display-node-links node window graph) (print-display-node node window clipping-region) ;; Bizarrely, the code seems to work when this flip is removed. Why? -- jrm ;; (flip-node node window) ))) (defun relative-move-node-to (node dx dy window &optional clipping-region) (let ((current-pos (get-node-centre node))) (move-node-to node (wb:make-position (+ (wb:position-x current-pos) dx) (+ (wb:position-y current-pos) dy)) window clipping-region))) (defun move-nodes (node-list current-position canvas &optional clipping-region) "Dynamically moves all nodes of node-list in the graph of the window canvas." (wb:with-focused-canvas canvas (let ((old-pos current-position) (new-pos current-position) dx dy) (loop while (wb:mouse-down-p) do (setf new-pos (wb:mouse-position canvas)) (unless (and (= (wb:position-x new-pos) (wb:position-x old-pos)) (= (wb:position-y new-pos) (wb:position-y old-pos))) (loop for node in node-list do (setf dx (- (wb:position-x new-pos) (wb:position-x old-pos))) (setf dy (- (wb:position-y new-pos) (wb:position-y old-pos))) (relative-move-node-to node dx dy canvas clipping-region)) (setf old-pos new-pos))) (unless (and (= (wb:position-x new-pos) (wb:position-x current-position)) (= (wb:position-y new-pos) (wb:position-y current-position))) (if clipping-region (wb:canvas-clear canvas :canvas-left (wb:region-left clipping-region) :canvas-bottom (wb:region-bottom clipping-region) :width (wb:region-width clipping-region) :height (wb:region-height clipping-region)) (wb:canvas-clear canvas)) (display-graph (wb:display-of canvas) canvas clipping-region))))) (defun move-node (node current-position canvas &optional clipping-region) "Dynamically moves the node in the graph of the canvas." (wb:with-focused-canvas canvas (let ((old-pos current-position) (new-pos current-position)) (loop while (wb:mouse-down-p) do (setf new-pos (wb:mouse-position canvas)) (unless (and (= (wb:position-x new-pos) (wb:position-x old-pos)) (= (wb:position-y new-pos) (wb:position-y old-pos))) (move-node-to node new-pos canvas clipping-region) (setf old-pos new-pos))) (unless (and (= (wb:position-x new-pos) (wb:position-x current-position)) (= (wb:position-y new-pos) (wb:position-y current-position))) (if clipping-region (wb:canvas-clear canvas :canvas-left (wb:region-left clipping-region) :canvas-bottom (wb:region-bottom clipping-region) :width (wb:region-width clipping-region) :height (wb:region-height clipping-region)) (wb:canvas-clear canvas)) (display-graph (wb:display-of canvas) canvas clipping-region)))))
7,894
Common Lisp
.l
166
35.96988
87
0.55259
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c90a4288c302fc724e0f43d0d18761caaa52ad81fd4ca35dbd86742f29071198
33,896
[ -1 ]
33,897
grapher-link.lsp
rwoldford_Quail/source/browser/grapher-link.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher-link.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; R.W. Oldford 1988-1992 ;;; J.R. MacPhail 1995 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This file, split off from grapher.lisp, defines operations on links. ;;; Links logically use nodes, and grapher depends on both. (in-package :quail) (defun display-link (from-nodes to-nodes window g &optional line-width operation) "Draws a link from FROM-NODES to TO-NODES." (wb:with-focused-canvas window (if (graph-side-flg g) (cond ( ;; in a horizontal case of LATTICE, always draw from right ;; to left (or (graph-directed-flg g) (> (gn-left to-nodes) (gn-right from-nodes))) (display-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (display-link-lr from-nodes to-nodes line-width operation window)) ((> (gn-bottom from-nodes) (gn-top to-nodes)) (display-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (display-link-tb from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ) (cond ((or (graph-directed-flg g) (> (gn-bottom from-nodes) (gn-top to-nodes))) (display-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (display-link-tb from-nodes to-nodes line-width operation window)) ((> (gn-left to-nodes) (gn-right from-nodes)) (display-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (display-link-lr from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw )))) (defun erase-link (from-nodes to-nodes window g &optional line-width operation) "Erases a link from from-nodes to to-nodes." (wb:with-focused-canvas window (if (graph-side-flg g) (cond ( ;; in a horizontal case of LATTICE, always draw from right ;; to left (or (graph-directed-flg g) (> (gn-left to-nodes) (gn-right from-nodes))) (erase-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (erase-link-lr from-nodes to-nodes line-width operation window)) ((> (gn-bottom from-nodes) (gn-top to-nodes)) (erase-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (erase-link-tb from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ) (cond ((or (graph-directed-flg g) (> (gn-bottom from-nodes) (gn-top to-nodes))) (erase-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (erase-link-tb from-nodes to-nodes line-width operation window)) ((> (gn-left to-nodes) (gn-right from-nodes)) (erase-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (erase-link-lr from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw )))) (defun display-link-bt (gnb gnt width operation window) "Draws a line from the bottom edge of GNB to the top edge of GNT." (wb:canvas-draw-line window (wb:position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) (wb:position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) :width width :operation operation)) (defun erase-link-bt (gnb gnt width operation window) "Erases a line from the bottom edge of GNB to the top edge of GNT translated ~ by TRANS." (wb:canvas-erase-line window (wb:position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) (wb:position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) :width width :operation operation)) (defun display-link-lr (gnl gnr width operation window) "Draws a line from the left edge of GNL to the right edge of GNR." (wb:canvas-draw-line window (- (gn-left gnl) 1) (wb:position-y (graph-node-position gnl)) (+ (gn-right gnr) 1) (wb:position-y (graph-node-position gnr)) :width width :operation operation)) (defun erase-link-lr (gnl gnr width operation window) window "Erase a line from the left edge of GNL to the right edge of GNR." (wb:canvas-erase-line window (- (gn-left gnl) 1) (wb:position-y (graph-node-position gnl)) (+ (gn-right gnr) 1) (wb:position-y (graph-node-position gnr)) :width width :operation operation)) (defun display-link-rl (gnr gnl width operation window) window "Draws a link from the right edge of GNR to the left edge of GNL." (wb:canvas-draw-line window (+ (gn-right gnr) 1) (wb:position-y (graph-node-position gnr)) (- (gn-left gnl) 1) (wb:position-y (graph-node-position gnl)) :width width :operation operation)) (defun erase-link-rl (gnr gnl width operation window) window "Erase a link from the right edge of GNR to the left edge of GNL." (wb:canvas-erase-line window (+ (gn-right gnr) 1) (wb:position-y (graph-node-position gnr)) (- (gn-left gnl) 1) (wb:position-y (graph-node-position gnl)) :width width :operation operation)) (defun display-link-tb (gnt gnb width operation window) "Draws a line from the top edge of GNT to the bottom edge of GNR." (wb:canvas-draw-line window (wb:position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) (wb:position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) :width width :operation operation)) (defun erase-link-tb (gnt gnb width operation window) "Erase a line from the top edge of GNT to the bottom edge of GNR." (wb:canvas-erase-line window (wb:position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) (wb:position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) :width width :operation operation)) (defun display-node-links (node window g &optional to-s-only line-width operation) "Displays node links. If to-s-only is not NIL , draws only the to links." (wb:with-focused-canvas window (prog ((node-lst (graph-node-lst g))) (dolist (to-node-id (to-links node)) (display-link node (get-node-from-id to-node-id node-lst) window g line-width operation)) (or to-s-only (dolist (from-node-id (from-links node)) (display-link (get-node-from-id from-node-id node-lst) node window g line-width operation))))) ) (defun erase-node-links (node window g &optional to-s-only line-width operation) "Erase node links. If to-s-only is not NIL, erases only the to links." (wb:with-focused-canvas window (prog ((node-lst (graph-node-lst g))) (dolist (to-node-id (to-links node)) (erase-link node (get-node-from-id to-node-id node-lst) window g line-width operation)) (or to-s-only (dolist (from-node-id (from-links node)) (erase-link (get-node-from-id from-node-id node-lst) node window g line-width operation))))) )
9,353
Common Lisp
.l
231
28.874459
86
0.518878
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
97f6749768b2db135891b59f5f6f853a6a8eb46a320ca488b2f1ded6da9a6dfc
33,897
[ -1 ]
33,898
button-fns.lsp
rwoldford_Quail/source/browser/button-fns.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; button-fns.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defun *browser-left-button-fn* (canvas mouse-pos) (let ((node (find-graph-node canvas mouse-pos)) (already-selected-nodes (selected-nodes-of canvas))) (cond (node (cond ((member node already-selected-nodes) NIL) (T (loop for n in already-selected-nodes do (flip-node n canvas)) (setf (selected-nodes-of canvas) (list node)) (flip-node node canvas))) (move-node node mouse-pos canvas)) (T (loop for n in already-selected-nodes do (flip-node n canvas)) (setf (selected-nodes-of canvas) NIL))))) (defun *browser-shift-left-button-fn* (canvas mouse-pos) (let ((node (find-graph-node canvas mouse-pos)) (already-selected-nodes (selected-nodes-of canvas))) (cond (node (cond ((member node already-selected-nodes) (flip-node node canvas) (setf (selected-nodes-of canvas) (remove node already-selected-nodes))) (T (push node (selected-nodes-of canvas)) (flip-node node canvas))) (move-nodes (selected-nodes-of canvas) mouse-pos canvas)) (T (if (selected-nodes-of canvas) (move-nodes (selected-nodes-of canvas) mouse-pos canvas)))))) (defun *browser-ctrl-left-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-middle-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-shift-middle-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-ctrl-middle-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-right-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-shift-right-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos)) (defun *browser-ctrl-right-button-fn* (canvas mouse-pos) (*browser-left-button-fn* canvas mouse-pos))
2,640
Common Lisp
.l
67
33.208955
86
0.568334
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
725967e42f4ef830a318376e3a0b508ac901ec017be024b151c2eea65fc803d6
33,898
[ -1 ]
33,899
grapher-var.lsp
rwoldford_Quail/source/browser/grapher-var.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher-var.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; some global variables must be customised to the machine ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*max-height-graph* *max-width-graph* *min-height-graph* *min-width-graph*))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; global variable definitions ;;; (defvar *graph-cache-node-labels* nil) (defvar *graph-default-node-border* nil) (defvar *graph-default-node-font* wb::*small-graphics-font* "Default font used in displaying graphs (i.e. networks).") (defvar *graph-default-node-label-shade* nil) (defvar *max-height-graph* NIL) (defun max-height-graph () (if *max-height-graph* *max-height-graph* (setf *max-height-graph* (- (wb:screen-height) 30)))) (defvar *max-width-graph* NIL) (defun max-width-graph () (if *max-width-graph* *max-width-graph* (setf *max-width-graph* (- (wb:screen-width) 30)))) (defvar *min-height-graph* 200) (defvar *min-width-graph* 200)
1,631
Common Lisp
.l
46
31.73913
86
0.474121
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
eb37b5d722e2370f49ccf4d31a32b96dfebfbc537f94c5cdcca83e541722e170
33,899
[ -1 ]
33,900
browser-methods.lsp
rwoldford_Quail/source/browser/browser-methods.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser-methods.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(sub-items understands))) (defmethod add-root ((self browser) &optional new-item) "Add a named item to the starting list of browser." (prog nil (or (objectp (setf new-item (new-item self new-item))) (return (prompt-print self "Nothing added to Browser."))) (when (has-object self new-item) (return new-item)) (push new-item (starting-list-of self)) (when (good-list-of self) (push new-item (good-list-of self))) (setf (bad-list-of self) (remove new-item (bad-list-of self))) (recompute self) (return new-item))) (defmethod browse ((self browser) &optional browse-list window-or-title good-list position) "Call show-browser and then Shape to Hold and move for first time." (show-browser self browse-list window-or-title good-list) (if position (wb::move-canvas self position))) (defmethod browser-objects ((self browser)) "Return a list of all the objects shown in the Browser." (let (result node-id) (dolist (node (graph-node-lst (wb::display-of self))) (when (not (listp (setf node-id (graph-node-id node)))) (push node-id result))) result)) (defmethod change-format ((self browser) &optional format) "Change format between Lattice and Tree." (cond ((and format (listp format)) (setf (graph-format-of self) format)) (T (setf format (wb::pick-one (graph-format-choices-of self) :item-print-function #'(lambda (i stream) (format stream (first i))))) (setf (graph-format-of self) format))) (recompute self)) (defmethod choice-menu ((self browser) item-cv) "Create a menu and cache it in slot menu-cache." (prog ((menu (getf (menu-cache-of self) item-cv)) items) (cond ((wb::menu-p menu) (return menu)) ((not (listp (setf items (slot-value self item-cv)))) (return nil))) (setf menu (wb::make-menu :items items :when-held-fn #'browser-when-held-fn :when-selected-fn #'browser-body-when-selected-fn :change-offset-fn t)) (when (cache-menu-p self) (setf (getf (menu-cache-of self) item-cv) menu)) (return menu))) (defmethod clear-label-cache ((self browser) objects) "Delete the Cached label for the Objects." (if (listp objects) (dolist (object objects) (clear-label-cache self object)) (if (eq objects t) ;; Delete the whole cache (setf (label-cache-of self) nil) (let ((cached-label (assoc objects (label-cache-of self)))) (when cached-label (setf (label-cache-of self) (remove cached-label (label-cache-of self)))))))) (defmethod do-selected-command ((self browser) command obj) "Does the selected command or forwards it to the object." (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))) (return (if (and (not (member command (local-commands-of self))) (understands obj command)) (browser-funcall command obj args) (if obj (browser-funcall command self obj args) (browser-funcall command self args)))))) (defmethod flash-node ((self browser) node &optional n flash-time leave-flipped?) "Flashes the selected node." (let* ((node (get-node-from-id node (graph-node-lst (wb::display-of self))))) (when node (dotimes (i (or n 3)) (flip-node node self) (sleep (or flash-time 0.3)) (flip-node node self) (sleep (or flash-time 0.3)))) (when leave-flipped? (flip-node node self)))) (defmethod get-display-label ((self browser) object) "Get the display label. Use the Cache if it provides the answer; If not, ~ and Max-label-width is set, use it to compute the appropriate Bitmap and ~ then cache the result." (let ((cached-label (assoc object (label-cache-of self)))) (if cached-label (cdr cached-label) (let ((new-label (get-label self object))) (if (listp new-label) (setf new-label (format nil "~S" new-label))) (push (cons object new-label) (label-cache-of self)) new-label)))) (defmethod get-label ((self browser) object) "Get a label for an object to be displayed in the browser." (if (quail::class-p object) (class-name object) (class-name (class-of object)))) (defmethod get-node-list ((self browser) browse-list) "Compute the node data structures of the tree starting at BROWSE-LIST. If ~ GOOD-LIST is given, only includes elements of it." (prog* ((graph (wb::display-of self)) (old-nodes (if graph (graph-node-lst graph))) obj-list node obj) ;;; ;;; First make Obj-list which is a list of pairs (Object . Obj-Name). Obj-Name ;;; will be used as a title for a node in the browser. This structure will be ;;; replaced by a Graph-Node when it is processed. The node ID of the ;;; Graph-node will be the Object and the label will be the name ;;; (declare (special obj-list)) (dolist (obj-or-name browse-list) (add-in-obj-list self obj-or-name)) (do ((pair obj-list (cdr pair))) ((null pair)) (setf node (or (get-node-from-id (setf obj (caar pair)) old-nodes t) (make-graph-node :id obj))) (setf (graph-node-to-nodes node) (cddar pair)) (setf (graph-node-label-symbol node) (cadar pair)) (setf (graph-node-font node) *graph-default-node-font*) (setf (graph-node-height node) nil) (setf (graph-node-width node) nil) (setf (first pair) node)) (return obj-list))) (defmethod get-links ((self browser) object &key (reverse? NIL)) (declare (ignore reverse?)) "Gets a set of subs from an object for browsing." (class-direct-subclasses object)) (defmethod has-object ((self browser) object) "Check Object in Graph-Nodes and return if it is one of them." (if (wb::display-of self) (member object (browser-objects self)) NIL)) (defmethod left-choice ((self browser)) "Make a selection from the menu build using Left-Button-Items or ~ Shift-left-Button-Items." (prog (menu) (setf menu (if (wb::shift-key-p) (if (shift-left-button-items-of self) (choice-menu self 'shift-left-button-items) (if (understands self 'left-shift-select) (prog nil (left-shift-select self) (return nil)) (choice-menu self 'left-button-items))) (choice-menu self 'left-button-items))) (return (and menu (wb::select-in-menu menu))))) (defmethod left-selection ((self browser) obj) "choose an item from the Left button items and apply it." (declare (special object)) (setf object obj) (prog (selector) (setf selector (or (left-choice self) (return nil))) (do-selected-command self selector object))) (defmethod left-shift-select ((self browser)) (declare (special object)) (push-in-buffer object)) (defmethod middle-choice ((self browser)) "Make a selection from the menu build using Middle-Button-Items or ~ Shift-middle-Button-Items." (prog (menu) (setf menu (if (wb::shift-key-p) (if (shift-middle-button-items-of self) (choice-menu self 'shift-middle-button-items) (if (understands self 'middle-shift-select) (prog nil (middle-shift-select self) (return nil)) (choice-menu self 'middle-button-items))) (choice-menu self 'middle-button-items))) (return (and menu (wb::select-in-menu menu))))) (defmethod middle-selection ((self browser) obj) "choose an item from the Middle button items and apply it." (declare (special object)) (setf object obj) (prog (selector) (setf selector (or (middle-choice self) (return nil))) (do-selected-command self selector object))) (defmethod middle-shift-select ((self browser)) (declare (special object)) (push-in-buffer object)) (defmethod new-item ((self browser) &optional new-item) "Return Object, Prompt for it if needed." (find-class (or new-item (wb::prompt-user :prompt-string "Give name of item to be added : " :read-type :read :type 'symbol)))) (defmethod obj-name-pair ((self browser) obj-or-name) "make a pair (Object . (Obj-Name . NIL)) where Obj-Name is label to be ~ used in browser." (prog (obj name) (unless obj-or-name (return nil)) (setf obj obj-or-name) (setf name (get-display-label self obj-or-name)) (return (if (and (good-list-of self) (not (member obj (good-list-of self)))) nil (if (member obj (bad-list-of self)) nil (cons obj (cons name nil))))))) (defmethod prompt-print ((self browser) prompt) "Prints out the prompt in the prompt-window." (vw::inform-user prompt)) (defmethod recompute ((self browser) &optional dont-reshape-flg) "Recomputes the graph in the same window." (show-browser self (starting-list-of self) self) (unless dont-reshape-flg (shape-to-hold self)) ) (defmethod recompute-in-place ((self browser)) "Recompute the graph maintaining the current position." (recompute self t) ) (defmethod recompute-labels ((self browser)) "Recompute the graph including the labels." (clear-label-cache self t) (recompute self t)) (defmethod shape-to-hold ((self browser)) "Reshape the window (if necessary) to just hold the nodes of the browser." (declare (special *min-width-graph* *min-height-graph* )) (prog* ((old-reg (wb::canvas-screen-region self)) ;; Old-Reg is the previous size of the window (new-reg (graph-region (wb::display-of self))) ;; New-Reg is a list representing the region used by ;; the graph ) ;; we update the new height and width of the window (setf (wb::region-width old-reg) (min (max (wb::region-width new-reg) *min-width-graph*) (max-width-graph))) (setf (wb::region-height old-reg) (min (max (wb::region-height new-reg) *min-height-graph*) (max-height-graph))) ;; and then reshape it (wb::shape-canvas self old-reg) )) (defmethod show-browser ((self browser) &optional browse-list window-or-title good-list) "Show the items and their subs on a browse window ~ If WINDOW-OR-TITLE is not a window it will be used as a title for the ~ window which will be created." (prog (node-lst) (unless window-or-title (setf window-or-title (wb::canvas-title self))) (if (not (wb::canvas-p window-or-title)) (setf (wb::canvas-title self) window-or-title)) (when (and browse-list (not (listp browse-list))) (setf browse-list (list browse-list))) (setf (starting-list-of self) nil) (setf (good-list-of self) nil) (dolist (c browse-list) (push c (starting-list-of self))) (setf (starting-list-of self) (nreverse (starting-list-of self))) (and good-list (dolist (c good-list t) (push c (good-list-of self))) (setf (good-list-of self) (nreverse (good-list-of self)))) ;;(setf (slot-value self 'window) (show-graph (when (and (starting-list-of self) (setf node-lst (get-node-list self (starting-list-of self)))) (layout-graph node-lst (tree-roots node-lst) (graph-format-of self) (wb::canvas-font self))) self (top-align-p self)) ;;) (return self))) (defmethod title-left-choice ((self browser)) "Make a selection from the menu build using Left-Title-Items." (prog (menu) (setf menu (if (wb::shift-key-p) (if (understands self 'title-left-shift-select) (prog nil (title-left-shift-select self) (return nil)) (choice-menu self 'left-title-items)) (choice-menu self 'left-title-items))) (return (and menu (wb::select-in-menu menu))))) (defmethod title-left-selection ((self browser)) "choose an item from the Left title items and apply it." (prog (selector) (setf selector (or (title-left-choice self) (return nil))) ;; added NIL ... do-selected.. needs 3 args. (do-selected-command self selector NIL))) (defmethod title-left-shift-select ((self browser)) (push-in-buffer self)) (defmethod title-middle-choice ((self browser)) "Make a selection from the menu build using Middle-Title-Items." (prog (menu) (setf menu (if (wb::shift-key-p) (if (understands self 'title-middle-shift-select) (prog nil (title-middle-shift-select self) (return nil)) (choice-menu self 'middle-title-items)) (choice-menu self 'middle-title-items))) (return (and menu (wb::select-in-menu menu))))) (defmethod title-middle-selection ((self browser)) "choose an item from the Middle button items and apply it." (prog (selector) (setf selector (or (title-middle-choice self) (return nil))) ;; added NIL ... do-selected.. needs 3 args. (do-selected-command self selector NIL))) (defmethod unread ((self browser) &optional object) "Unread Object into system buffer." (push-in-buffer object)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; functions definitions ;;; (defun add-in-obj-list (self new-element) (declare (special obj-list)) (let (pair) (and (setf pair (obj-name-pair self new-element)) (not (assoc (first pair) obj-list)) (push pair obj-list) (dolist (sub (get-links self (first pair))) (add-in-obj-list self sub) (push sub (cddr pair)))))) (defun browser-funcall (command obj &optional (args nil) (more-args nil)) (if (null more-args) (if (null args) (funcall command obj) (funcall command obj args)) (funcall command obj args more-args))) (defun node-object (node) "Determines the object represented by a node on the graph ~ the problem is that the node-id of node can be a list if the object is ~ represented more than once on the graph." (let ((node-id (graph-node-id node))) (loop (if (listp node-id) (setf node-id (first node-id)) (return))) node-id)) (defun left-browser-fn (node window) "What to do when we left-select a node." (left-selection window (node-object node))) (defun middle-browser-fn (node window) "What to do when we middle-select a node." (middle-selection window (node-object node))) (defun title-left-browser-fn (window) "What to do if we left-select the title." (title-left-selection window)) (defun title-middle-browser-fn (window) "What to do if we middle-select the title." (title-middle-selection window)) (defun tree-roots (node-lst) "Computes the set of Root nodes for a lattice - Those with no connections ~ TO them in list of nodes." (let ((first-element (graph-node-id (first node-lst))) root-lst) (dolist (n node-lst) (push (graph-node-id n) root-lst)) (dolist (n node-lst) (dolist (d (to-links n)) (setf root-lst (remove d root-lst)))) (or root-lst (list first-element)))) (defun understands (self selector &rest args) "Returns NIL if SELF doesn't understand the method SELECTOR, T otherwise." (if (and (generic-function-p selector) (objectp self)) (compute-applicable-methods selector (append self args)))) #| (defun understands (self selector &rest args) "Returns NIL if SELF doesn't understand the method SELECTOR, T otherwise." (if (and (generic-function-p selector) (objectp self)) (let ((arg-classes (make-list (length args) :initial-element (find-class t)))) (dolist (super (class-precedence-list (class-of self)) nil) (when (member (get-method (symbol-function selector) nil (append (list super) arg-classes) nil) (return t)))) nil))) |#
18,727
Common Lisp
.l
435
33.016092
90
0.578977
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fdde7152f145b4107be00b9c375c7fbbf19671c30fecb98973d2e4be9469783a
33,900
[ -1 ]
33,902
class-browse.lsp
rwoldford_Quail/source/browser/class-browse.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; window-basics-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-browse))) (defun class-browse (class-name &rest more-class-names) "Produces a graphical browser of the network of classes and their subclasses ~ rooted at class-name and more-class-names, if more are given." (let* ((classes (loop for c-n in (if more-class-names (cons class-name more-class-names) (list class-name)) collect (find-class c-n)))) (browse (make-browser) classes)))
1,049
Common Lisp
.l
28
32
81
0.447291
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0fc5848eddcf6a5bffeb3ef542df97cfe6b48bef21cf139cb9bda61b24aec4d1
33,902
[ -1 ]
33,903
grapher-layout.lsp
rwoldford_Quail/source/browser/grapher-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; J.R. MacPhail 1995 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This file is the part of old "grapher.lisp" that lays it out. -- jrm (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(layout-graph))) (defun brh-layout (n x y mom-lst gn) "X and Y are the lower left corner of the box that will surround the tree ~ headed by the browsenode N. MOM-LST isa the mother node inside a cons ~ cell. GN is the graphnode for nodeid N. It is crucial that the ~ node position be set before recursion because this marks that the node has ~ been (is being) laid out already. BRH-OFFSET is used to raise the ~ daughters in those rare cases where the label is bigger than the ~ daughters." (declare (special mother-d personal-d the-node-lst)) (prog ((ds (graph-node-to-nodes gn)) (width (graph-node-width gn)) (y-height (+ personal-d (graph-node-height gn))) d-height) (setf (graph-node-from-nodes gn) mom-lst) (setf (graph-node-position gn) (wb:make-position (+ x (half width)) nil)) (cond ((null ds)) ((> y-height (setq d-height (brh-layout-daughters ds (+ x width mother-d) y (list n)))) (brh-offset ds (half (- y-height d-height)))) (t (setq y-height d-height))) (setf (wb:position-y (graph-node-position gn)) (+ y (half y-height))) (return y-height))) (defun brh-layout-daughters (ds x y mom-lst) "DS are the daughters of (CAR MOM-LST). X is where the left edge of their ~ label will be, and Y is the bottom of the mother's box. Returns the height ~ of the mother's box. Tests to see if a node has been layout already. If ~ so, side effecting the graph-node structure." (declare (special the-node-lst)) (let ((the-floor y)) (dolist (d ds) (setq the-floor (+ the-floor (brh-layout d x the-floor mom-lst (get-node-from-id d the-node-lst))))) (- the-floor y))) (defun brh-offset (node-ids y-inc) (declare (special the-node-lst)) (dolist (n node-ids) (setq n (get-node-from-id n the-node-lst)) (setf (wb:position-y (graph-node-position n)) (+ (wb:position-y (graph-node-position n)) y-inc)) (brh-offset (graph-node-to-nodes n) y-inc))) (defun brhc-intertree-space (ttc btc) "Given the top transition chain of the old daughter and the bottom ~ transition chain of the new daughter, where BTC is sitting on the bottom ~ of the box, calculate how much the bottom must be raised so that it just ~ clears the TTC. OP is the top left corner of some label. NP is the bottom ~ left corner." (let ((raise -1000) (np (pop btc)) (op (pop ttc)) dist) (loop (setq dist (- (wb:position-y op) (wb:position-y np))) (and (> dist raise) (setq raise dist)) (cond ((null btc) (return raise)) ((null ttc) (return raise)) ((eq (wb:position-x (first btc)) (wb:position-x (first ttc))) (setq np (pop btc)) (setq op (pop ttc))) ((< (wb:position-x (first btc)) (wb:position-x (first ttc))) (setq np (pop btc))) (t (setq op (pop ttc))))))) (defun brhc-layout (n x mom-lst gn) "See documentation on BRH-LAYOUT. Instead of keeping only the graphnode in layed ~ out node's position field, keep the offset as well. The offset is how much ~ this nodes box must be raised relative to the enclosing box. Uses two free ~ variables to return transition chains. RETURN-TTC is the top left corner ~ of all the labels. RETURN-BTC is the bottom left corners." (declare (special personal-d return-ttc return-btc)) (prog ((daughters (graph-node-to-nodes gn)) (w (graph-node-width gn)) (h (graph-node-height gn)) y-center x-sw h/2) (setq h/2 (half h)) (setq x-sw (+ x w)) (setf (graph-node-from-nodes gn) mom-lst) (setf (graph-node-position gn) (list 0)) (setq y-center (if daughters (brhc-layout-daughters daughters x-sw (list n)) (brhc-layout-terminal gn x-sw))) (setf (graph-node-position gn) (wb:make-position (+ x (half w)) y-center)) (push (wb:make-position x (+ personal-d (- y-center h/2) h)) return-ttc) (push (wb:make-position x (- y-center h/2)) return-btc) (return y-center))) (defun brhc-layout-daughters (ds x-sw mom-lst) "See documentation on BRH-LAYOUT-DAUGHTERS. First daughter is always laid out on ~ the bottom of the box. Subsequent daughters have the amount that they are ~ to be raised calculated by comparing the top edge of the old daughter (in ~ TTC) with the bottom edge of the new daughter (in RETURN-BTC). TTC is ~ update by adding the new daughter's transition chain to the front, because ~ the new daughter's front is guaranteed to be higher than the old ~ daughter's front. Conversely, BTC is updated by adding the new daughter's ~ transition chain to the back, because the old daughter's front is ~ guaranteed to be lower." (declare (special mother-d family-d the-node-lst return-ttc return-btc)) (let (gn btc ttc first-d-y-center last-d-y-center (offset 0) (x (+ x-sw mother-d))) (dolist (d ds) (setq gn (get-node-from-id d the-node-lst)) (setq last-d-y-center (brhc-layout d x mom-lst gn)) (cond ((null ttc) ; first daughter (setq first-d-y-center last-d-y-center) (setq ttc return-ttc) (setq btc return-btc)) (t (setq offset (brhc-intertree-space ttc return-btc)) (brhc-offset d offset) (setq ttc (extend-transition-chain ( raise-transition-chain return-ttc offset) ttc)) (setq btc (extend-transition-chain btc (raise-transition-chain return-btc offset)))))) ;; ;; finally, add a mythical top left corner at the height of the ;; highest daughter because diagonal links are getting clobbered. ;; Move lowest daughter's bottom left corner to the left for the ;; same reason. (setq return-ttc (cons (wb:make-position x-sw (wb:position-y (first ttc))) ttc)) (setf (wb:position-x (first btc)) x-sw) (setf (wb:position-y (first ttc)) (+ (wb:position-y (first ttc)) family-d)) (setq return-btc btc) ;; ;; Center of mother is half way between first and last daughter's ;; label centers using fact that offset of first daughter is zero ;; and last daughter's offset is OFFSET (half (+ first-d-y-center last-d-y-center offset)))) (defun brhc-layout-terminal (gn x-sw) "Initializes the transition chains to the right edge of the node label, and ~ returns the label's center." (declare (special return-ttc return-btc)) (setq return-ttc (list (wb:make-position x-sw 0))) (setq return-btc (list (wb:make-position x-sw (graph-node-height gn)))) (half (graph-node-height gn))) (defun brhc-offset (n absy) "Adds in all the offsets. see comment on BHRC-LAYOUT-DAUGHTERS." (declare (special the-node-lst)) (prog ((gn (get-node-from-id n the-node-lst))) (setf (wb:position-y (graph-node-position gn)) (+ absy (wb:position-y (graph-node-position gn)))) (dolist (d (graph-node-to-nodes gn)) (brhc-offset d absy)))) (defun brhl-layout (n x y mom-lst gn) "X and Y are the lower left corner of the box that will surround the tree ~ headed by the browse node N. MOM-LST is the mother node inside a cons ~ cell. GN is the graphnode for the nodeid N. It is crucial that the ~ nodeposition be set before recursion because this marks that the node has ~ been laid out already. If in addition, the YCOORD is NIL, the the node is ~ still in the process of being laid out. BRHL-LAYOUT-DAUGHTERS uses this ~ fact to break loops by inserting boxed nodes." (declare (special mother-d personal-d the-node-lst)) (if (graph-node-position gn) ;; this case only occures if the node has been put in the roots ;; list, and has already been visited by recursion. Value won't be ;; used 0 ; (prog ((ds (graph-node-to-nodes gn)) (width (graph-node-width gn)) (y-height (+ personal-d (graph-node-height gn)))) (setf (graph-node-from-nodes gn) mom-lst) ; this is first time for ; layout, so set FROM-NODES (setf (graph-node-position gn) (wb:make-position (+ x (half width)) (list n))) (and ds (setq y-height (max (brhl-layout-daughters ds (+ x width mother-d) y (list n)) y-height))) (setf (wb:position-y (graph-node-position gn)) (+ y (half y-height))) (return y-height)))) (defun brhl-layout-daughters (ds x y mom-lst) "DS are the daughters of (CAR MOM-LST). X is where the left edge of their ~ label will be, and y is the bottom of the mother's box. Returns the height ~ of the mother's box. Tests to see if a node has been laid out already. if ~ so, it sees if the node is far enought to the right; if not it moves the ~ node and its daughters." (declare (special the-node-lst y-height)) (let (d gn np (the-floor y)) (do ((d-tail ds (cdr d-tail))) ((null d-tail)) (setq gn (get-node-from-id (setq d (first d-tail)) the-node-lst)) (cond ((setq np (graph-node-position gn)) (cond ((null (wb:position-y np)) (setq gn (new-instance-of-graph-node gn)) (setf (first d-tail) (graph-node-id gn)) (setq the-floor (+ the-floor (brhl-layout (graph-node-id gn) x the-floor mom-lst gn)))) (t (brhl-move-right gn x nil) (push (first mom-lst) ; Add its mother to the ; from-links (graph-node-from-nodes gn))))) (t (setq the-floor (+ the-floor (brhl-layout d x the-floor mom-lst gn )))))) (- the-floor y))) (defun brhl-move-right (gn x stack) "Move this node and its children right." (declare (special mother-d the-node-lst)) (prog ((width (graph-node-width gn)) (np (graph-node-position gn))) (and (member gn stack) (quail-error "Loop caught in BRHL-MOVE-RIGHT at ~S" (graph-node-label-symbol gn))) (when (< x (- (wb:position-x np) (half width))) (return)) (let ((new-x (+ x width mother-d)) (new-stack (cons gn stack))) (dolist (d (to-links gn)) (brhl-move-right (get-node-from-id d the-node-lst) new-x new-stack))) (setf (wb:position-x np) (+ x (half width))))) (defun browse-layout-horiz (root-ids) "Each subtree is given a box centered vertically on its label. Sister boxes ~ a but do not intrude as they do in the compacting version." (declare (special the-node-lst)) (let ((y 0)) (dolist (n root-ids) (setq y (+ y (brh-layout n 0 y nil (get-node-from-id n the-node-lst))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil))) (defun browse-layout-horiz-compactly (roots) "See documentation on BRH-LAYOUT and BRH-LAYOUT-DAUGHTERS first. This differs in ~ that it keeps on the stack a representation of the shape of the tree that ~ fills the node's box. The representation is a list of positions. If one ~ starts drawing a line from left to right starting at the CAR, each point ~ is a step in the line, and the point begins a new plateau (or valley). The ~ last point is where the line would turn around and head back to the left. ~ Builds dummy top node for ROOTS if necessary, and adjusts the horizontal ~ distance accordingly." (declare (special the-node-lst mother-d)) (prog (return-ttc return-btc) (declare (special return-ttc return-btc)) (cond ((not (listp roots)) (brhc-layout roots 0 nil (get-node-from-id roots the-node-lst)) (brhc-offset roots 0)) ((null (cdr roots)) (brhc-layout (first roots) 0 nil (get-node-from-id (first roots) the-node-lst)) (brhc-offset (first roots) 0)) (t (prog ((gn (make-graph-node :label-symbol (make-symbol "") :id (cons nil nil) :to-nodes roots :width 0 :height 0)) top-node) (push gn the-node-lst) (setq top-node (graph-node-id gn)) (brhc-layout top-node (- mother-d) nil gn) (brhc-offset top-node 0) (let (rn) (dolist (n roots) (setq rn (get-node-from-id n the-node-lst)) (setf (graph-node-from-nodes rn) (remove top-node (graph-node-from-nodes rn))))) (setq the-node-lst (remove gn the-node-lst)))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil)) (defun browse-layout-lattice (node-lst) "Almost the same as BROWSE-LAYOUT-HORIZ, except that ot doesn't box nodes ~ unless there are cycles. Instead, a single node is placed at the rightmost ~ of the positions that would be laid out by for all of its (boxed) ~ occurences by BROWSE-LAYOUT-HORIZ." (declare (special the-node-lst)) (let ((y 0)) (dolist (n node-lst) (setq y (+ y (brhl-layout n 0 y nil (get-node-from-id n the-node-lst))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil))) (defun extend-transition-chain (ltc rtc) "Extends the left transition chain by appending the part of the right ~ transition chain that is to the right of the end of the left transition ~ chain. End point of left transition chain is changed to intersect right ~ transition chain." (let ((l-tail ltc) (r-tail rtc) lx rx) (loop (cond ((null (cdr r-tail)) (setf (wb:position-y (first (last l-tail))) (wb:position-y (first r-tail))) (return ltc)) ((null (cdr l-tail)) (rplacd l-tail (cdr r-tail)) (setf (wb:position-y (first l-tail)) (wb:position-y (first r-tail))) (return ltc)) ((eq (setq lx (wb:position-x (second l-tail))) (setq rx (wb:position-x (second r-tail)))) (setq l-tail (cdr l-tail)) (setq r-tail (cdr r-tail))) ((< lx rx) (setq l-tail (cdr l-tail))) (t (setq r-tail (cdr r-tail))))))) (defun forest-break-cycles (node) "Breaks any cycle by inserting new nodes and boxing." (declare (special the-node-lst)) (setf (graph-node-position node) t) (let (dn) (do ((d-tail (graph-node-to-nodes node) (cdr d-tail))) ((null d-tail)) ; (setq dn (get-node-from-id (first d-tail) the-node-lst)) (cond ((graph-node-position dn) ; we've seen this before (setq dn (new-instance-of-graph-node dn)) (setf (first d-tail) (graph-node-id dn))) (t (forest-break-cycles dn)))))) (defun lattice-break-cycles (node stack) (declare (special the-node-lst)) (setf (graph-node-position node) t) (let (d gn) (do ((d-tail (graph-node-to-nodes node) (cdr d-tail))) ((null d-tail)) ; (setq gn (get-node-from-id (setq d (first d-tail)) the-node-lst)) (cond ((member d stack) (setq gn (new-instance-of-graph-node gn)) (setf (first d-tail) (graph-node-id gn))) ((null (graph-node-position gn)) (lattice-break-cycles gn (cons d stack))))))) (defun layout (graph) "Layout in lattice for tests" (let (roots) (dolist (node (graph-node-lst graph)) (unless (dolist (link (graph-node-from-nodes node)) (when (get-node-from-id link (graph-node-lst graph)) (return t))) (push (graph-node-id node) roots))) (show-graph (layout-graph (graph-node-lst graph) roots 'lattice nil nil nil nil)))) (defun layout-graph (the-node-lst root-ids format font &optional mother-d personal-d family-d) "Takes a list of Graph-node records and a list node ids for the top level ~ nodes, where the graph-nodes have only the NODE-ID, NODE-LABEL and ~ TO-NODES fields filled in. It fills in the other fields approprietly ~ according the format switch and the boxing switch so that the graph ~ becomes a forest. If there are loops in the graph they are snapped and the ~ NODE-LST is extended with push this function returns a graph record with ~ the display slots filled in appropriately." (declare (special the-node-lst mother-d personal-d family-d)) (prog ((box-both-flg t) (box-leaves-flg t) (border-for-marking t) (label-shade-for-marking 'dont) g) (declare (special box-both-flg box-leaves-flg border-for-marking label-shade-for-marking)) (or (and root-ids (listp root-ids)) (quail-error "LAYOUT-GRAPH needs a LIST of root node ids")) (dolist (r root-ids) ; the nodes of ROOT-IDS must be ; in THE-NODE-LST (unless (dolist (node the-node-lst nil) (when (eq r (graph-node-id node)) (return t))) (quail-error "~S is in ROOT-IDS but no GRAPH-NODE for it in THE-NODE-LST" r))) (setq font (if (wb:canvas-font-p font) font *graph-default-node-font*)) (or mother-d (setq mother-d (wb:canvas-string-width NIL "AAAAAA" :font font))) (or personal-d (setq personal-d (if (eq-or-member 'vertical format ) (wb:canvas-string-width NIL "AA" :font font) 0))) (or family-d (setq family-d (half (wb:canvas-font-ascent font)))) (interpret-mark-format format) (init-nodes-for-layout the-node-lst format root-ids font) (and (eq-or-member 'vertical format) (switch-node-height-width the-node-lst)) (setq g (cond ((eq-or-member 'lattice format) (browse-layout-lattice root-ids)) ((eq-or-member 'fast format) (browse-layout-horiz root-ids)) (t (browse-layout-horiz-compactly root-ids)))) (dolist (n the-node-lst) (or (wb:position-p (graph-node-position n)) (quail-error "Disconnected graph. Root(s) didn't connect to : ~S" (graph-node-label-symbol n)))) (offset-to-origin the-node-lst) (cond ((eq-or-member 'vertical format) (switch-node-height-width the-node-lst) (reflect-graph-diagonally g) (and (eq-or-member 'reverse format) (reflect-graph-vertically g)) (and (eq-or-member 'reverse-daughters format) (reflect-graph-horizontally g))) (t (and (eq-or-member 'reverse format) (reflect-graph-horizontally g)) (and (eq-or-member 'reverse-daughters format) (reflect-graph-vertically g)))) (return g))) (defun layout-s-expr (tree &optional format boxing font mother-d personal-d family-d) "Assumes CAR of Tree is Node label, CDR is daughter trees." (if tree (prog (result) (declare (special result)) (layout-s-expr-1 tree) ;; Result contains a list of node corresponding to Tree which ;; label and to-nodes link are updated (return (layout-graph result (list tree) (append (if (listp format) format (list format)) boxing) font mother-d personal-d family-d))) (quail-error "Cannot layout NIL as S-EXPRESSION"))) (defun layout-s-expr-1 (tree) (declare (special result)) (cond ((dolist (r result nil) ; If Tree is already in result nothing is done (when (eq tree (graph-node-id r)) (return t)))) ((not (listp tree)) ; if Tree is a simple node it is added in result (push (make-graph-node :id tree :label-symbol tree) result)) ; otherwise Tree is a node with subnodes which are recursively added to result (t (push (make-graph-node :id tree :label-symbol (first tree) :to-nodes (append (cdr tree))) result) (dolist (d (cdr tree)) (layout-s-expr-1 d))))) (defun raise-transition-chain (tc raise) "Raises a daughter's transition chain by adding in the offset of the ~ daughter's box relative to the mother's box." (dolist (p tc tc) (setf (wb:position-y p) (+ (wb:position-y p) raise))))
25,659
Common Lisp
.l
499
35.072144
91
0.503648
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b81687a48d171f9a3fc2600ef7525619781032c1f35f8083692b6a36a6f54541
33,903
[ -1 ]
33,904
grapher.lsp
rwoldford_Quail/source/browser/grapher.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; J.R. MacPhail 1995 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This is what remains of the old "grapher.lisp" after factoring out ;;; "grapher-node.lisp", "grapher-links.lisp", "grapher-layout-lisp" and ;;; "grapher-draw.lisp". (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(graph-node-lst find-graph-node get-node-from-id graph-region reverse))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Structure definition : ;;; (defstruct graph node-lst side-flg directed-flg) ;; Change this to a defmethod, with graph and position arguments. -- jrm (defun find-graph-node (canvas position) "Return the node hit, NIL if position not in a node." (let* ((graph (wb:display-of canvas)) (node-lst (if graph (graph-node-lst graph)))) (if node-lst (node-lst-as-menu node-lst position) NIL))) ;; This is only used by find-graph-node. Clean it up to use gn-top and friends, ;; and then put it into find-graph-node. -- jrm (defun node-lst-as-menu (node-lst position) "Find the node that is closest to position and returns it ~ the node N of Node-lst is returned if position is inside the region it ~ occupies in the window otherwise NIL is returned." (let ((x (wb:position-x position)) (y (wb:position-y position)) t1 t2) (dolist (n node-lst nil) (when (and (< (- (setq t1 (wb:position-y (graph-node-position n))) (setq t2 (half (graph-node-height n)))) y) (< y (+ t1 t2)) (< (- (setq t1 (wb:position-x (graph-node-position n))) (setq t2 (half (graph-node-width n)))) x) (< x (+ t1 t2))) (return n))))) ;; The somewhat bizarre comment seems rather irrelevant. The only point is ;; that the id argument may be a list. -- jrm (defun get-node-from-id (id node-lst &optional no-err-flg) "Returns node associated to ID." (or (dolist (node node-lst nil) (when (eq id (graph-node-id node)) (return node))) (and id (listp id) ; the nodes created when we ; break cycles have the same ; name than the original node ; in a list, so both node name ; should return the same graph ; node (get-node-from-id (first id) node-lst)) (if no-err-flg nil (quail-error "No graphnode for ID : ~S" id)))) ;; The max-min family can all be made cleaner by using mapcar. ;; For speed, the node lists could be sorted to find the x, y minima fastest. -- jrm (defun max-right (node-lst) "Returns the largest right position of nodes in Node-lst." (let ((largest (gn-right (car node-lst)))) (dolist (node node-lst) (when (> (gn-right node) largest) (setq largest (gn-right node)))) largest)) (defun max-top (node-lst) "Returns the largest Top position of nodes in Node-Lst." (let ((largest (gn-top (car node-lst)))) (dolist (node node-lst) (when (> (gn-top node) largest) (setq largest (gn-top node)))) largest)) (defun min-bottom (node-lst) "Returns the smallest bottom position of nodes in Node-Lst." (let ((smallest (gn-bottom (car node-lst)))) (dolist (node node-lst) (when (< (gn-bottom node) smallest) (setq smallest (gn-bottom node)))) smallest)) (defun min-left (node-lst) "Returns the smallest left position of nodes in Node-lst." (let ((smallest (gn-left (car node-lst)))) (dolist (node node-lst) (when (< (gn-left node) smallest) (setq smallest (gn-left node)))) smallest)) ;; Notice that this function adjusts the nodes to get min-left = min-bottom = 0. ;; Suspicion: everything probably gets recomputed every time we add a node. -- jrm (defun offset-to-origin (node-lst) "After layout, the computed positions can be negative, which can be a problem ~ on some environments. To avoid this, we systematically offset the graph so ~ that each position is positive." (let ((inf-x (min-left node-lst)) (inf-y (min-bottom node-lst)) pos) (unless (and (eq 0 inf-x) (eq 0 inf-y)) (dolist (node node-lst) (setq pos (graph-node-position node)) (setf (wb:position-x pos) (- (wb:position-x pos) inf-x)) (setf (wb:position-y pos) (- (wb:position-y pos) inf-y)))))) (defun adjust-graph-positions (graph x-adjust y-adjust) "Destructively ~ adds x-adjust to all x-positions and y-adjust to all y-positions in graph. ~ Returns graph." (cond ((zerop x-adjust) (if (zerop y-adjust) graph (dolist (n (graph-node-lst graph)) (setf (wb:position-y (graph-node-position n)) (+ y-adjust (wb:position-y (graph-node-position n))))))) ((zerop y-adjust) (dolist (n (graph-node-lst graph)) (setf (wb:position-x (graph-node-position n)) (+ x-adjust (wb:position-x (graph-node-position n)))))) (T (dolist (n (graph-node-lst graph)) (setf (wb:position-x (graph-node-position n)) (+ x-adjust (wb:position-x (graph-node-position n)))) (setf (wb:position-y (graph-node-position n)) (+ y-adjust (wb:position-y (graph-node-position n)))))))) (defun eq-or-member (item atom-or-list) "Returns T if item EQ Atom-or-list or if item is a member of Atom-or-list." (or (eq item atom-or-list) (and (listp atom-or-list) (member item atom-or-list :test #'eq)))) (defun init-nodes-for-layout (ns format root-ids font) (declare (special the-node-lst)) (dolist (gn ns) (setf (graph-node-position gn) ;; T indicate prior visitation. Roots are already visited (not (not (member (graph-node-id gn) root-ids :test #'eq)))) (or (graph-node-font gn) (setf (graph-node-font gn) font))) (dolist (r root-ids) (if (eq-or-member 'lattice format) (lattice-break-cycles (get-node-from-id r the-node-lst) nil) (forest-break-cycles (get-node-from-id r the-node-lst)))) (dolist (gn the-node-lst) (setf (graph-node-position gn) nil) (set-label-size gn))) (defun interpret-mark-format (format) "Sets special variables for new-instance-of-graph-node and mark-graph-node." (declare (special box-both-flg box-leaves-flg border-for-marking label-shade-for-marking)) (prog (pl) (and (eq-or-member 'copies-only format) (setq box-both-flg nil)) (and (eq-or-member 'not-leaves format) (setq box-leaves-flg nil)) (cond ((not (listp format)) (return)) ((eq (car format) 'mark) (setq pl (cdr format))) (t (return))) (if (member 'border pl :test #'eq) (setq border-for-marking (getf pl 'border)) (setq border-for-marking 'dont)) (if (member 'label-shade pl :test #'eq) (setq label-shade-for-marking (getf pl 'label-shade)) (setq label-shade-for-marking 'dont)))) ;;; Reflection routines, really used by grapher-layout.lisp -- jrm (defun reflect-graph-diagonally (graph) (setf (graph-side-flg graph) (not (graph-side-flg graph))) (let (yn) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setq yn (wb:position-y n)) (setf (wb:position-y n) (wb:position-x n)) (setf (wb:position-x n) yn)))) (defun reflect-graph-horizontally (graph) (let ((w (+ (max-right (graph-node-lst graph)) (min-left (graph-node-lst graph))))) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setf (wb:position-x n) (- w (wb:position-x n)))))) (defun reflect-graph-vertically (graph) (let ((h (+ (max-top (graph-node-lst graph)) (min-bottom (graph-node-lst graph))))) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setf (wb:position-y n) (- h (wb:position-y n)))))) (defun switch-node-height-width (node-lst) (let (wn) (dolist (n node-lst) (setq wn (graph-node-width n)) (setf (graph-node-width n) (graph-node-height n)) (setf (graph-node-height n) wn)))) ;;; Region stuff. (defun graph-region (graph) "Return the minimum region containing the graph." (if graph (prog (left-offset bottom-offset (node-lst (graph-node-lst graph))) (return (cond (node-lst (dolist (n node-lst) (measure-graph-node n)) (wb:make-region (setq left-offset (min-left node-lst)) (setq bottom-offset (min-bottom node-lst)) (+ 1 (- (max-right node-lst) left-offset)) (+ 1 (- (max-top node-lst) bottom-offset)))) (t (wb:make-region 0 0 0 0))))) (wb:make-region 0 0 0 0))) (defun intersect-regionp-lbwh (left bottom width height reg) "Like intersect regions, but without requiring the consing." (not (or (> (wb:region-bottom reg) (+ bottom height)) (< (+ (wb:region-left reg) (wb:region-width reg)) left) (> (wb:region-left reg) (+ left width)) (< (+ (wb:region-bottom reg) (wb:region-height reg)) bottom))))
11,502
Common Lisp
.l
259
31.567568
86
0.504146
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5a55aa2df4c9340c536abbb0d6b8f26f49f36e6751f3ec201226259bb343c576
33,904
[ -1 ]
33,905
cl-extensions.lsp
rwoldford_Quail/source/browser/cl-extensions.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; cl-extensions.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; ;;; Common Lisp Extensions ;;; ;;; (in-package :cl) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;;generic-function-p objectp ;;inspect-object ;;inspect ))) #| (defun generic-function-p (symbol) "True if symbol names a generic-function, NIL otherwise." (if (and (fboundp symbol) (typep (symbol-function symbol) 'standard-generic-function)) t nil)) |# (defun objectp (object) "Return T if object is of type standard-object." (typep object 'standard-object)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Make inspect behave analogously to CL's describe by ;;; having it call the generic function inspect-object. ;;; Should be shadowed elsewhere. ;;; #| (setf (symbol-function 'CL-inspect) (symbol-function 'inspect)) (setf (symbol-function 'inspect) (function (lambda (thing) "Calls the generic function inspect-object on its argument." (inspect-object thing)))) (defgeneric inspect-object (thing) (:documentation "Used to provide an interactive inspector to examine ~ and potentially modify the contents of the argument.")) (defmethod inspect-object ((thing t)) (CL-inspect thing)) |#
1,864
Common Lisp
.l
55
28.945455
86
0.508087
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2a27d622fef464fbaa25298bc1ab55125dc3fb7bb71ece558e75d7df3a84eb9a
33,905
[ -1 ]
33,906
browser-generics.lsp
rwoldford_Quail/source/browser/browser-generics.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser-generics.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(add-root browse change-format choice-menu do-selected-command flash-node get-display-label get-label get-links left-choice left-shift-select middle-choice middle-shift-select new-item prompt-print recompute recompute-in-place recompute-labels set-up-title-menus shape-to-hold show-browser title-left-shift-select unread))) (defgeneric add-root (browser &optional new-item) (:documentation "Add a named item to the starting list of browser.")) (defgeneric browse (browser &optional browse-list window-or-title good-list position) (:documentation "Call show-browser and then Shape to Hold and move for first time.")) (defgeneric browser-objects (browser) (:documentation "Return a list of all the objects shown in the Browser.")) (defgeneric change-format (browser &optional format) (:documentation "Change format between Lattice and Tree.")) (defgeneric choice-menu (browser item-cv) (:documentation "Create a menu and cache it in slot menu-cache.")) (defgeneric clear-label-cache (browser objects) (:documentation "Delete the Cached label for the Objects.")) (defgeneric do-selected-command (browser command obj) (:documentation "Does the selected command or forwards it to the object.")) (defgeneric flash-node (browser node &optional n flash-time leave-flipped?) (:documentation "Flashes the selected node.")) (defgeneric get-display-label (browser object) (:documentation "Get the display label. Use the Cache if it provides the answer; If not, ~ and Max-label-width is set, use it to compute the appropriate Bitmap and ~ then cache the result.")) (defgeneric get-label (browser object) (:documentation "Get a label for an object to be displayed in the browser.")) (defgeneric get-node-list (browser browse-list) (:documentation "Compute the node data structures of the tree starting at BROWSE-LIST. If ~ GOOD-LIST is given, only includes elements of it.")) (defgeneric get-links (browser object &key reverse?) (:documentation "Gets a set of subs from an object for browsing.")) (defgeneric has-object (browser object) (:documentation "Check Object in Graph-Nodes and return if it is one of them.")) (defgeneric left-choice (browser) (:documentation "Make a selection from the menu build using Left-Button-Items or ~ Shift-left-Button-Items.")) (defgeneric left-selection (browser obj) (:documentation "Choose an item from the Left button items and apply it.")) (defgeneric left-shift-select (browser) ) (defgeneric middle-choice (browser) (:documentation "Make a selection from the menu build using Middle-Button-Items or ~ Shift-middle-Button-Items.")) (defgeneric middle-selection (browser obj) (:documentation "choose an item from the Middle button items and apply it.")) (defgeneric middle-shift-select (browser) ) (defgeneric new-item (browser &optional new-item) (:documentation "Return object; prompt for it if needed.")) (defgeneric obj-name-pair (browser obj-or-name) (:documentation "Make a pair (Object . (Obj-Name . NIL)) where Obj-Name is label to be ~ used in browser.")) (defgeneric prompt-print (browser prompt) (:documentation "Prints out the prompt in the prompt-window.")) (defgeneric recompute (browser &optional dont-reshape-flg) (:documentation "Recomputes the browser's network from the starting list of objects.")) (defgeneric recompute-in-place (browser) (:documentation "Recompute the graph maintaining the current position.")) (defgeneric recompute-labels (browser) (:documentation "Recompute the graph including the labels.")) (defgeneric shape-to-hold (browser) (:documentation "Reshape the window to just hold the nodes of the browser.")) (defgeneric set-up-title-menus (browser) (:documentation "Sets up title menus by calling install-title-menus with the ~ appropriate menu type.")) (defgeneric show-browser (browser &optional browse-list window-or-title good-list) (:documentation "Show the items and their subs on a browse window ~ If WINDOW-OR-TITLE is not a window it will be used as a title for the ~ window which will be created.")) (defgeneric title-left-choice (browser) (:documentation "Make a selection from the menu build using Left-Title-Items.")) (defgeneric title-left-shift-select (browser) ) (defgeneric title-middle-choice (browser) (:documentation "Make a selection from the menu built using Middle-Title-Items.")) (defgeneric title-middle-shift-select (browser) (:documentation "No documentation available.")) (defgeneric unread (browser &optional object) (:documentation "Unread Object into system buffer.")) (defgeneric title-middle-selection (browser) (:documentation "Choose an item from the Middle button items and apply it."))
5,905
Common Lisp
.l
151
33.350993
86
0.664951
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8ad1e6d673b41fe435020915100c8e29202af09ab27dd81d5773e24d929e76cb
33,906
[ -1 ]
33,907
browser-pc.lsp
rwoldford_Quail/source/browser/browser-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; browser-pc.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; ;; (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(push-in-buffer select-in-menu ))) ;;; ;;; function definitions ;;; (defun get-active-region (window) "Return the inside region of the window. ~ As the height and width of the clipping region are the inside dimensions ~ of the window, we use it and the origin position of the window which is ~ given by the outside region of the window to built the inside region." (let ((reg-1 (wb::clipping-region-of window)) (reg-2 (wb::canvas-screen-region window))) (setf (wb::region-left reg-1) (wb::region-left reg-2)) (setf (wb::region-bottom reg-1) (wb::region-bottom reg-2)) (setf (wb::region-width reg-1) (- (wb::region-width reg-1) 24)) (setf (wb::region-height reg-1) (- (wb::region-height reg-1) 16)) reg-1)) (defun push-in-buffer (text) (print "push-in-buffer needs to be fixed.") (format *terminal-io* "Push-in-buffer called with ~s" text) #| (ccl:set-window-layer (ccl:front-window) 1) (or (stringp text) (setq text (format nil "~s" text))) (dotimes (k (length text)) (#_PostEvent :errchk :a0 3 :d0 (char text k) :d0) (#_PostEvent :errchk :a0 4 :d0 (char text k) :d0) (event-dispatch)) (#_PostEvent :errchk :a0 3 :d0 #\NewLine :d0) (#_PostEvent :errchk :a0 4 :d0 #\NewLine :d0) |# )
2,066
Common Lisp
.l
56
30.732143
86
0.496997
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b7f9cb5d5ee0f2ee7a52b04640487e548960941b9cb488adb6253740b46fa784
33,907
[ -1 ]
33,909
grapher-node.lsp
rwoldford_Quail/source/browser/grapher-node.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher-node.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; J.R. MacPhail 1995 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This file, split off from grapher.lisp, defines graph-node, operations on ;;; graph-node, and operations on lists of graph-node. (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(graph-node-position graph-node-height graph-node-width graph-node-font graph-node-label-symbol graph-node-to-nodes graph-node-id gn-bottom gn-left make-graph-node to-links flip-node))) ;; This structure should become a class. Subclasses will probably make the last ;; three slots into class variables. Add instance variable selected-p. -- jrm (defstruct graph-node id position label-bitmap width height to-nodes from-nodes label-symbol (label-shade *graph-default-node-label-shade*) (font *graph-default-node-font*) (border *graph-default-node-border*)) ;; Make accessors for the node "position" (defun get-node-centre (node) (graph-node-position node)) (defun set-node-centre (node value) (setf (graph-node-position node) value)) ;; The accessors from-links and to-links will go into the defclass. (defun from-links (node) (graph-node-from-nodes node)) (defun to-links (node) (graph-node-to-nodes node)) ;; Define a half function, safer than the macro which looks messy if x<0. ;; The function can claim integer-p if we think we can prove it. ;; Other than this file, only grapher-layout.lisp calls this half. (defun half (x) "Integer division by 2, rounded down." (when x (/ (if (oddp x) (1- x) x) 2))) (defun set-layout-position (node position) "Sets a node position." (setf (wb:position-x (graph-node-position node)) (wb:position-x position)) (setf (wb:position-y (graph-node-position node)) (wb:position-y position))) ;; Beware that graph-layout uses NIL graph-node-position, ;; and also uses NIL position-x, position-y within it. -- jrm (defun gn-bottom (node &aux (pos (graph-node-position node))) "Determines the bottom position of a Graph-Node." (if pos (- (or (wb:position-y pos) 0) (half (or (graph-node-height node) 0))) 0)) (defun gn-left (node &aux (pos (graph-node-position node))) "Determines the left position of a Graph-Node." (if pos (- (or (wb:position-x pos) 0) (half (or (graph-node-width node) 0))) 0)) (defun gn-right (node &aux (pos (graph-node-position node))) "Determines the right position of a Graph-Node." (if pos (+ (or (wb:position-x pos) 0) (- (half (+ 1 (or (graph-node-width node) 0))) 1)) 0)) (defun gn-top (node &aux (pos (graph-node-position node))) "Determines the top position of a Graph-Node." (if pos (+ (or (wb:position-y pos) 0) (- (half (+ 1 (or (graph-node-height node) 0))) 1)) 0)) (defun graph-node-border-width (border) "Returns a non-negative integer giving the border width." (cond ((null border) 0) ((eq border t) 1) ((integerp border) (abs border)) ((and (listp border) (integerp (first border)) (>= (first border) 0)) (first border)) (t (quail-error "Illegal border : ~S" border)))) (defun mark-graph-node (node) "Changes appearance of graph node to indicate that a link has been snapped." (declare (special border-for-marking label-shade-for-marking)) (or (eq border-for-marking 'dont) (setf (graph-node-border node) border-for-marking)) (or (eq label-shade-for-marking 'dont) (setf (graph-node-label-shade node) label-shade-for-marking))) (defun measure-graph-node (node &optional (reset-flg nil)) "Measure the node label image." (set-label-size node reset-flg) ;; This is redundant! ;;(set-layout-position node (or (graph-node-position node) ;; (quail-error ;; "This Graph node has not been given a position : ~S" ;; node))) ) ;; Wow, look at how the node gets cloned. -- jrm (defun new-instance-of-graph-node (node) "Returns a second instance of the graph-node, boxing it." (declare (special the-node-lst box-leaves-flg box-both-flg)) (prog ((new (make-graph-node :id (list (graph-node-id node)) :label-symbol (graph-node-label-symbol node) :font (graph-node-font node) :width (graph-node-width node) :height (graph-node-height node) :border (graph-node-border node) :label-shade (graph-node-label-shade node)))) (push new the-node-lst) (when (or box-leaves-flg (graph-node-to-nodes node)) ; in the original version, the node are boxed when they are ; duplicated. we remove this so that every node seems identical ; on the map ;(mark-graph-node new) ;(when box-both-flg (mark-graph-node node)) ) (return new))) ;; print-display-node has two callers: display-graph and move-node-to. ;; Trouble seems to occur because callers somehow set clip-reg incorrectly. ;; In both cases, the callers got clip-reg from their callers. ;; In the case of display-graph, its caller redisplay-graph sends a ;; clipping 'region' gotten by (wb:clipping-region-of window). One caller ;; of redisplay-graph is show-graph, an exported function. -- jrm (defun print-display-node (node window &optional clip-reg operation) "Prints a node at its position. Takes the operation from ~ the stream so that when editor has set the operation to :invert, this may ~ erase as well as draw; but when the operation is :paint, then nodes obliterate ~ any link lines that they are drawn over." (declare (special *graph-cache-node-labels*)) (setf operation (case operation (:invert boole-xor) (:paint :default) (T NIL))) (unless (eq 0 (graph-node-height node)) (prog ((left (gn-left node)) (bottom (gn-bottom node)) (width (graph-node-width node)) (height (graph-node-height node)) (font (graph-node-font node)) (nbw (graph-node-border-width (graph-node-border node)))) ; This when command must be wrong -- either bad logic or using bad data -- jrm #| (when (and clip-reg (not (intersect-regionp-lbwh left bottom width height clip-reg))) (return node)) |# node (cond ((wb:bitmap-p (graph-node-label-bitmap node)) (wb:canvas-bitblt (graph-node-label-bitmap node) window :canvas-left left :canvas-bottom bottom :width width :height height :operation operation)) ((wb:bitmap-p (graph-node-label-symbol node)) (cond ((eq 0 nbw) (wb:canvas-bitblt (graph-node-label-symbol node) window :canvas-left left :canvas-bottom bottom :width width :height height :operation operation)) (t (draw-graph-node-border (graph-node-border node) left bottom width height window) (wb:canvas-bitblt (graph-node-label-symbol node) window :canvas-left (+ left nbw) :canvas-bottom (+ bottom nbw) :width width :height height :operation operation)))) (t (or (wb:canvas-font-p font) (setf (graph-node-font node) (setq font (wb:canvas-font window)))) (if (not (eq nbw 0)) (draw-graph-node-border (graph-node-border node) left bottom width height window)) (wb:canvas-draw-string window (graph-node-label-symbol node) :left left :bottom bottom :width width :height height :font font) (if (graph-node-label-shade node) (fill-graph-node-label (graph-node-label-shade node) left bottom width height nbw window)) (when (and *graph-cache-node-labels* clip-reg (intersect-regionp-lbwh left bottom width height clip-reg)) (setf (graph-node-label-bitmap node) (wb:make-bitmap :width width :height height)) (wb:copy-canvas-region-to-bitmap window left bottom (graph-node-label-bitmap node) width height)))) (return node)))) (defun draw-graph-node-border (border left bottom width height stream &key color operation dashing) "Interprets and draws the node border." (let ((x1 left) (y1 bottom) (x2 (+ left width)) (y2 (+ bottom height)) (border-width (cond ((eq border t) 1) ((and (integerp border) (> border 0)) border) ((listp border) (setf dashing (second border)) (first border)) (t (quail-error "Illegal border : ~S" border))))) (when border (wb:canvas-draw-rectangle stream x1 x2 y1 y2 :width border-width :color color :dashing dashing :operation operation)))) (defun fill-graph-node-label (shade left bottom width height border window) (declare (ignore shade)) ;; ;; border must be subtracted from the node's region ;; (wb:canvas-invert window ;<----- Better as a draw-filled? :canvas-left (+ left border) ; ... rwo :canvas-bottom (+ bottom border) :width (- width border border) :height (- height border border))) (defun erase-node-label (node canvas) "Erases the label of the node in the canvas" (wb:with-focused-canvas canvas (unless (eq 0 (graph-node-height node)) (let ((left (+ (gn-left node) -1)) (bottom (+ (gn-bottom node) -1)) (width (+ (graph-node-width node) 2 )) (height (+ (graph-node-height node) 2))) (wb:canvas-clear canvas :canvas-left left :canvas-bottom bottom :width width :height height))))) (defun flip-node (node window) "Flip the region around the node." (wb:canvas-invert window :canvas-left (+ (gn-left node) -1) :canvas-bottom (+ (gn-bottom node) -1) :width (+ (graph-node-width node) 2) :height (+ (graph-node-height node) 2))) (defun set-label-size (node &optional reset-flg) (declare (special *graph-default-node-font*)) ;;; ;;; the SHADE and null font stuff is for ZOOM-GRAPH ;;; (or (and (not reset-flg) (integerp (graph-node-height node)) (integerp (graph-node-width node))) (prog ((font (graph-node-font node)) (lab (graph-node-label-symbol node)) (nbw (graph-node-border-width (graph-node-border node))) width height) (cond ((wb:bitmap-p lab) (setq width (wb:bitmap-width lab)) (setq height (wb:bitmap-height lab))) (t (or (stringp lab) (if (symbolp lab) (setq lab (symbol-name lab)) (setq lab (format nil "~s" lab))) ) (or (wb:canvas-font-p font) (setf (graph-node-font node) (setq font *graph-default-node-font*))) (setq width (wb:canvas-string-width NIL lab :font font)) (setq height (+ (wb:canvas-font-height font) (wb:canvas-font-descent font))))) (or (and (not reset-flg) (integerp (graph-node-width node))) (setf (graph-node-width node) (+ width nbw nbw))) (or (and (not reset-flg) (integerp (graph-node-height node))) (setf (graph-node-height node) (+ height nbw nbw))) (return node))))
14,117
Common Lisp
.l
316
31.696203
91
0.518852
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3e1db9c9138e986e4cf47e76d3eb558bd8ef04d37f6c0bfb15ec02b69ef131cf
33,909
[ -1 ]
33,910
old-grapher.lsp
rwoldford_Quail/source/browser/old-grapher.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grapher.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(graph-node-height graph-node-width graph-node-font graph-node-label graph-node-to-nodes graph-node-id graph-node-lst find-node flip-node get-node-from-id gn-bottom gn-left graph-region layout-graph make-graph-node reverse show-graph to-links move-node))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Structures definitions : ;;; (defstruct graph-node id position label-bitmap width height to-nodes from-nodes label (label-shade *graph-default-node-label-shade*) (font *graph-default-node-font*) (border *graph-default-node-border*)) (defstruct graph node-lst side-flg directed-flg) (defmacro half (x) "Divides by 2 ." `(and ,x (ash ,x -1))) (defun find-node (canvas position) "Finds the closest node to position in canvas and returns it. ~ The node is returned if position is inside the region it ~ occupies in the canvas otherwise NIL is returned." (let* ((graph (wb::display-of canvas)) (node-lst (if graph (graph-node-lst graph)))) (if node-lst (node-lst-as-menu node-lst position) NIL))) (defun brh-layout (n x y mom-lst gn) "X and Y are the lower left corner of the box that will surround the tree ~ headed by the browsenode N. MOM-LST isa the mother node inside a cons ~ cell. GN is the graphnode for nodeid N. It is crucial that the ~ node position be set before recursion because this marks that the node has ~ been (is being) laid out already. BRH-OFFSET is used to raise the ~ daughters in those rare cases where the label is bigger than the ~ daughters." (declare (special mother-d personal-d the-node-lst)) (prog ((ds (graph-node-to-nodes gn)) (width (graph-node-width gn)) (y-height (+ personal-d (graph-node-height gn))) d-height) (setf (graph-node-from-nodes gn) mom-lst) (setf (graph-node-position gn) (wb::make-position (+ x (half width)) nil)) (cond ((null ds)) ((> y-height (setq d-height (brh-layout-daughters ds (+ x width mother-d) y (list n)))) (brh-offset ds (half (- y-height d-height)))) (t (setq y-height d-height))) (setf (wb::position-y (graph-node-position gn)) (+ y (half y-height))) (return y-height))) (defun brh-layout-daughters (ds x y mom-lst) "DS are the daughters of (CAR MOM-LST). X is where the left edge of their ~ label will be, and Y is the bottom of the mother's box. Returns the height ~ of the mother's box. Tests to see if a node has been layout already. If ~ so, side effecting the graph-node structure." (declare (special the-node-lst)) (let ((the-floor y)) (dolist (d ds) (setq the-floor (+ the-floor (brh-layout d x the-floor mom-lst (get-node-from-id d the-node-lst))))) (- the-floor y))) (defun brh-offset (node-ids y-inc) ;;; ;;; (declare (special the-node-lst)) (dolist (n node-ids) (setq n (get-node-from-id n the-node-lst)) (setf (wb::position-y (graph-node-position n)) (+ (wb::position-y (graph-node-position n)) y-inc)) (brh-offset (graph-node-to-nodes n) y-inc))) (defun brhc-intertree-space (ttc btc) "Given the top transition chain of the old daughter and the bottom ~ transition chain of the new daughter, where BTC is sitting on the bottom ~ of the box, calculate how much the bottom must be raised so that it just ~ clears the TTC. OP is the top left corner of some label. NP is the bottom ~ left corner." (let ((raise -1000) (np (pop btc)) (op (pop ttc)) dist) (loop (setq dist (- (wb::position-y op) (wb::position-y np))) (and (> dist raise) (setq raise dist)) (cond ((null btc) (return raise)) ((null ttc) (return raise)) ((eq (wb::position-x (first btc)) (wb::position-x (first ttc))) (setq np (pop btc)) (setq op (pop ttc))) ((< (wb::position-x (first btc)) (wb::position-x (first ttc))) (setq np (pop btc))) (t (setq op (pop ttc))))))) (defun brhc-layout (n x mom-lst gn) "See documentation on BRH-LAYOUT. Instead of keeping only the graphnode in layed ~ out node's position field, keep the offset as well. The offset is how much ~ this nodes box must be raised relative to the enclosing box. Uses two free ~ variables to return transition chains. RETURN-TTC is the top left corner ~ of all the labels. RETURN-BTC is the bottom left corners." (declare (special personal-d return-ttc return-btc)) (prog ((daughters (graph-node-to-nodes gn)) (w (graph-node-width gn)) (h (graph-node-height gn)) y-center x-sw h/2) (setq h/2 (half h)) (setq x-sw (+ x w)) (setf (graph-node-from-nodes gn) mom-lst) (setf (graph-node-position gn) (list 0)) (setq y-center (if daughters (brhc-layout-daughters daughters x-sw (list n)) (brhc-layout-terminal gn x-sw))) (setf (graph-node-position gn) (wb::make-position (+ x (half w)) y-center)) (push (wb::make-position x (+ personal-d (- y-center h/2) h)) return-ttc) (push (wb::make-position x (- y-center h/2)) return-btc) (return y-center))) (defun brhc-layout-daughters (ds x-sw mom-lst) "See documentation on BRH-LAYOUT-DAUGHTERS. First daughter is always laid out on ~ the bottom of the box. Subsequent daughters have the amount that they are ~ to be raised calculated by comparing the top edge of the old daughter (in ~ TTC) with the bottom edge of the new daughter (in RETURN-BTC). TTC is ~ update by adding the new daughter's transition chain to the front, because ~ the new daughter's front is guaranteed to be higher than the old ~ daughter's front. Conversely, BTC is updated by adding the new daughter's ~ transition chain to the back, because the old daughter's front is ~ guaranteed to be lower." (declare (special mother-d family-d the-node-lst return-ttc return-btc)) (let (gn btc ttc first-d-y-center last-d-y-center (offset 0) (x (+ x-sw mother-d))) (dolist (d ds) (setq gn (get-node-from-id d the-node-lst)) (setq last-d-y-center (brhc-layout d x mom-lst gn)) (cond ((null ttc) ; first daughter (setq first-d-y-center last-d-y-center) (setq ttc return-ttc) (setq btc return-btc)) (t (setq offset (brhc-intertree-space ttc return-btc)) (brhc-offset d offset) (setq ttc (extend-transition-chain ( raise-transition-chain return-ttc offset) ttc)) (setq btc (extend-transition-chain btc (raise-transition-chain return-btc offset)))))) ;; ;; finally, add a mythical top left corner at the height of the ;; highest daughter because diagonal links are getting clobbered. ;; Move lowest daughter's bottom left corner to the left for the ;; same reason. (setq return-ttc (cons (wb::make-position x-sw (wb::position-y (first ttc))) ttc)) (setf (wb::position-x (first btc)) x-sw) (setf (wb::position-y (first ttc)) (+ (wb::position-y (first ttc)) family-d)) (setq return-btc btc) ;; ;; Center of mother is half way between first and last daughter's ;; label centers using fact that offset of first daughter is zero ;; and last daughter's offset is OFFSET (half (+ first-d-y-center last-d-y-center offset)))) (defun brhc-layout-terminal (gn x-sw) "Initializes the transition chains to the right edge of the node label, and ~ returns the label's center." (declare (special return-ttc return-btc)) (setq return-ttc (list (wb::make-position x-sw 0))) (setq return-btc (list (wb::make-position x-sw (graph-node-height gn)))) (half (graph-node-height gn))) (defun brhc-offset (n absy) "Adds in all the offsets. see comment on BHRC-LAYOUT-DAUGHTERS." (declare (special the-node-lst)) (prog ((gn (get-node-from-id n the-node-lst))) (setf (wb::position-y (graph-node-position gn)) (+ absy (wb::position-y (graph-node-position gn)))) (dolist (d (graph-node-to-nodes gn)) (brhc-offset d absy)))) (defun brhl-layout (n x y mom-lst gn) "X and Y are the lower left corner of the box that will surround the tree ~ headed by the browse node N. MOM-LST is the mother node inside a cons ~ cell. GN is the graphnode for the nodeid N. It is crucial that the ~ nodeposition be set before recursion because this marks that the node has ~ been laid out already. If in addition, the YCOORD is NIL, the the node is ~ still in the process of being laid out. BRHL-LAYOUT-DAUGHTERS uses this ~ fact to break loops by inserting boxed nodes." (declare (special mother-d personal-d the-node-lst)) (if (graph-node-position gn) ;; this case only occures if the node has been put in the roots ;; list, and has already been visited by recursion. Value won't be ;; used 0 ; (prog ((ds (graph-node-to-nodes gn)) (width (graph-node-width gn)) (y-height (+ personal-d (graph-node-height gn)))) (setf (graph-node-from-nodes gn) mom-lst) ; this is first time for ; layout, so set FROM-NODES (setf (graph-node-position gn) (wb::make-position (+ x (half width)) (list n))) (and ds (setq y-height (max (brhl-layout-daughters ds (+ x width mother-d) y (list n)) y-height))) (setf (wb::position-y (graph-node-position gn)) (+ y (half y-height))) (return y-height)))) (defun brhl-layout-daughters (ds x y mom-lst) "DS are the daughters of (CAR MOM-LST). X is where the left edge of their ~ label will be, and y is the bottom of the mother's box. Returns the height ~ of the mother's box. Tests to see if a node has been laid out already. if ~ so, it sees if the node is far enought to the right; if not it moves the ~ node and its daughters." (declare (special the-node-lst y-height)) (let (d gn np (the-floor y)) (do ((d-tail ds (cdr d-tail))) ((null d-tail)) (setq gn (get-node-from-id (setq d (first d-tail)) the-node-lst)) (cond ((setq np (graph-node-position gn)) (cond ((null (wb::position-y np)) (setq gn (new-instance-of-graph-node gn)) (setf (first d-tail) (graph-node-id gn)) (setq the-floor (+ the-floor (brhl-layout (graph-node-id gn) x the-floor mom-lst gn))) ) (t (brhl-move-right gn x nil) (push (first mom-lst) ; Add its mother to the ; from-links (graph-node-from-nodes gn))))) (t (setq the-floor (+ the-floor (brhl-layout d x the-floor mom-lst gn )))))) (- the-floor y))) (defun brhl-move-right (gn x stack) "Move this node and its children right." (declare (special mother-d the-node-lst)) (prog ((width (graph-node-width gn)) (np (graph-node-position gn))) (and (member gn stack) (quail-error "Loop caught in BRHL-MOVE-RIGHT at ~S" ( graph-node-label gn))) (when (< x (- (wb::position-x np) (half width))) (return)) (let ((new-x (+ x width mother-d)) (new-stack (cons gn stack))) (dolist (d (to-links gn)) (brhl-move-right (get-node-from-id d the-node-lst) new-x new-stack))) (setf (wb::position-x np) (+ x (half width))))) (defun browse-layout-horiz (root-ids) "Each subtree is given a box centered vertically on its label. Sister boxes ~ a but do not intrude as they do in the compacting version." (declare (special the-node-lst)) (let ((y 0)) (dolist (n root-ids) (setq y (+ y (brh-layout n 0 y nil (get-node-from-id n the-node-lst))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil))) (defun browse-layout-horiz-compactly (roots) "See documentation on BRH-LAYOUT and BRH-LAYOUT-DAUGHTERS first. This differs in ~ that it keeps on the stack a representation of the shape of the tree that ~ fills the node's box. The representation is a list of positions. If one ~ starts drawing a line from left to right starting at the CAR, each point ~ is a step in the line, and the point begins a new plateau (or valley). The ~ last point is where the line would turn around and head back to the left. ~ Builds dummy top node for ROOTS if necessary, and adjusts the horizontal ~ distance accordingly." (declare (special the-node-lst mother-d)) (prog (return-ttc return-btc) (declare (special return-ttc return-btc)) (cond ((not (listp roots)) (brhc-layout roots 0 nil (get-node-from-id roots the-node-lst)) (brhc-offset roots 0)) ((null (cdr roots)) (brhc-layout (first roots) 0 nil (get-node-from-id (first roots) the-node-lst)) (brhc-offset (first roots) 0)) (t (prog ((gn (make-graph-node :label (make-symbol "") :id (cons nil nil) :to-nodes roots :width 0 :height 0)) top-node) (push gn the-node-lst) (setq top-node (graph-node-id gn)) (brhc-layout top-node (- mother-d) nil gn) (brhc-offset top-node 0) (let (rn) (dolist (n roots) (setq rn (get-node-from-id n the-node-lst) ) (setf (graph-node-from-nodes rn) (remove top-node ( graph-node-from-nodes rn))))) (setq the-node-lst (remove gn the-node-lst)))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil)) (defun browse-layout-lattice (node-lst) "Almost the same as BROWSE-LAYOUT-HORIZ, except that ot doesn't box nodes ~ unless there are cycles. Instead, a single node is placed at the rightmost ~ of the positions that would be laid out by for all of its (boxed) ~ occurences by BROWSE-LAYOUT-HORIZ." (declare (special the-node-lst)) (let ((y 0)) (dolist (n node-lst) (setq y (+ y (brhl-layout n 0 y nil (get-node-from-id n the-node-lst))))) (make-graph :node-lst the-node-lst :side-flg t :directed-flg nil))) (defun display-link (from-nodes to-nodes window g &optional line-width operation) "Draws a link from FROM-NODES to TO-NODES." (if (graph-side-flg g) (cond ( ;; in a horizontal case of LATTICE, always draw from right ;; to left (or (graph-directed-flg g) (> (gn-left to-nodes) (gn-right from-nodes))) (display-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (display-link-lr from-nodes to-nodes line-width operation window)) ((> (gn-bottom from-nodes) (gn-top to-nodes)) (display-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (display-link-tb from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ) (cond ((or (graph-directed-flg g) (> (gn-bottom from-nodes) (gn-top to-nodes))) (display-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (display-link-tb from-nodes to-nodes line-width operation window)) ((> (gn-left to-nodes) (gn-right from-nodes)) (display-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (display-link-lr from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ))) (defun erase-link (from-nodes to-nodes window g &optional line-width operation) "Erases a link from from-nodes to to-nodes." (if (graph-side-flg g) (cond ( ;; in a horizontal case of LATTICE, always draw from right ;; to left (or (graph-directed-flg g) (> (gn-left to-nodes) (gn-right from-nodes))) (erase-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (erase-link-lr from-nodes to-nodes line-width operation window)) ((> (gn-bottom from-nodes) (gn-top to-nodes)) (erase-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (erase-link-tb from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ) (cond ((or (graph-directed-flg g) (> (gn-bottom from-nodes) (gn-top to-nodes))) (erase-link-bt from-nodes to-nodes line-width operation window)) ((> (gn-bottom to-nodes) (gn-top from-nodes)) (erase-link-tb from-nodes to-nodes line-width operation window)) ((> (gn-left to-nodes) (gn-right from-nodes)) (erase-link-rl from-nodes to-nodes line-width operation window)) ((> (gn-left from-nodes) (gn-right to-nodes)) (erase-link-lr from-nodes to-nodes line-width operation window)) (t nil) ; if on top of each other don't ; draw ))) (defun display-link-bt (gnb gnt width operation window) "Draws a line from the bottom edge of GNB to the top edge of GNT." (wb::canvas-draw-line (wb::position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) (wb::position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) window :width width :operation operation)) (defun erase-link-bt (gnb gnt width operation window) "Erases a line from the bottom edge of GNB to the top edge of GNT translated ~ by TRANS." (wb::canvas-erase-line (wb::position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) (wb::position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) window :width width :operation operation)) (defun display-link-lr (gnl gnr width operation window) "Draws a line from the left edge of GNL to the right edge of GNR." (wb::canvas-draw-line (- (gn-left gnl) 1) (wb::position-y (graph-node-position gnl)) (+ (gn-right gnr) 1) (wb::position-y (graph-node-position gnr)) window :width width :operation operation)) (defun erase-link-lr (gnl gnr width operation window) "Erase a line from the left edge of GNL to the right edge of GNR." (wb::canvas-erase-line (- (gn-left gnl) 1) (wb::position-y (graph-node-position gnl)) (+ (gn-right gnr) 1) (wb::position-y (graph-node-position gnr)) window :width width :operation operation)) (defun display-link-rl (gnr gnl width operation window) "Draws a link from the right edge of GNR to the left edge of GNL." (wb::canvas-draw-line (+ (gn-right gnr) 1) (wb::position-y (graph-node-position gnr)) (- (gn-left gnl) 1) (wb::position-y (graph-node-position gnl)) window :width width :operation operation)) (defun erase-link-rl (gnr gnl width operation window) "Erase a link from the right edge of GNR to the left edge of GNL." (wb::canvas-erase-line (+ (gn-right gnr) 1) (wb::position-y (graph-node-position gnr)) (- (gn-left gnl) 1) (wb::position-y (graph-node-position gnl)) window :width width :operation operation)) (defun display-link-tb (gnt gnb width operation window) "Draws a line from the top edge of GNT to the bottom edge of GNR." (wb::canvas-draw-line (wb::position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) (wb::position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) window :width width :operation operation)) (defun erase-link-tb (gnt gnb width operation window) "Erase a line from the top edge of GNT to the bottom edge of GNR." (wb::canvas-erase-line (wb::position-x (graph-node-position gnt)) (+ (gn-top gnt) 1) (wb::position-x (graph-node-position gnb)) (- (gn-bottom gnb) 1) window :width width :operation operation)) (defun display-node-links (node window g &optional to-s-only line-width operation) "Displays node links. If to-s-only is not NIL , draws only the to links." (prog ((node-lst (graph-node-lst g))) (dolist (to-node-id (to-links node)) (display-link node (get-node-from-id to-node-id node-lst) window g line-width operation)) (or to-s-only (dolist (from-node-id (from-links node)) (display-link (get-node-from-id from-node-id node-lst) node window g line-width operation))))) (defun erase-node-links (node window g &optional to-s-only line-width operation) "Erase node links. If to-s-only is not NIL, erases only the to links." (prog ((node-lst (graph-node-lst g))) (dolist (to-node-id (to-links node)) (erase-link node (get-node-from-id to-node-id node-lst) window g line-width operation)) (or to-s-only (dolist (from-node-id (from-links node)) (erase-link (get-node-from-id from-node-id node-lst) node window g line-width operation))))) (defun display-graph (graph window clipping-region &optional line-width) "Displays graph on WINDOW. ~ Draws links first, then labels so that lattices don't have lines through ~ the labels." (dolist (n (graph-node-lst graph)) (display-node-links n window graph t line-width)) (dolist (n (graph-node-lst graph)) (print-display-node n window clipping-region)) (let ((nodes (selected-nodes-of window))) (if nodes (dolist (node nodes) (flip-node node window))))) (defun draw-graph-node-border (border left bottom width height stream &key color operation dashing) "Interprets and draws the node border." (let ((x1 left) (y1 bottom) (x2 (+ left width)) (y2 (+ bottom height)) (border-width (cond ((eq border t) 1) ((and (integerp border) (> border 0)) border) ((listp border) (setf dashing (second border)) (first border)) (t (quail-error "Illegal border : ~S" border))))) (when border (wb::canvas-draw-rectangle x1 x2 y1 y2 stream :width border-width :color color :dashing dashing :operation operation)))) (defmacro eq-or-member (item atom-or-list) "Returns T if item EQ Atom-or-list or if item is a member of Atom-or-list." `(or (eq ,item ,atom-or-list) (and (listp ,atom-or-list) (member ,item ,atom-or-list :test #'eq)))) (defun extend-transition-chain (ltc rtc) "Extends the left transition chain by appending the part of the right ~ transition chain that is to the right of the end of the left transition ~ chain. End point of left transition chain is changed to intersect right ~ transition chain." (let ((l-tail ltc) (r-tail rtc) lx rx) (loop (cond ((null (cdr r-tail)) (setf (wb::position-y (first (last l-tail))) (wb::position-y (first r-tail))) (return ltc)) ((null (cdr l-tail)) (rplacd l-tail (cdr r-tail)) (setf (wb::position-y (first l-tail)) (wb::position-y (first r-tail))) (return ltc)) ((eq (setq lx (wb::position-x (second l-tail))) (setq rx (wb::position-x (second r-tail)))) (setq l-tail (cdr l-tail)) (setq r-tail (cdr r-tail))) ((< lx rx) (setq l-tail (cdr l-tail))) (t (setq r-tail (cdr r-tail))))))) (defun fill-graph-node-label (shade left bottom width height border window) (declare (ignore shade)) ;; ;; border must be subtracted from the node's region ;; (wb::canvas-invert window ;<----- Better as a draw-filled? :canvas-left (+ left border) ; ... rwo :canvas-bottom (+ bottom border) :width (- width border border) :height (- height border border))) (defun flip-node (node window) "Flip the region around the node." (wb::canvas-invert window :canvas-left (+ (gn-left node) -1) :canvas-bottom (+ (gn-bottom node) -1) :width (+ (graph-node-width node) 2) :height (+ (graph-node-height node) 2))) (defun from-links (node) (graph-node-from-nodes node)) (defun forest-break-cycles (node) "Breaks any cycle by inserting new nodes and boxing." (declare (special the-node-lst)) (setf (graph-node-position node) t) (let (dn) (do ((d-tail (graph-node-to-nodes node) (cdr d-tail))) ((null d-tail)) ; (setq dn (get-node-from-id (first d-tail) the-node-lst)) (cond ((graph-node-position dn) ; we've seen this before (setq dn (new-instance-of-graph-node dn)) (setf (first d-tail) (graph-node-id dn))) (t (forest-break-cycles dn)))))) (defun get-node-from-id (id node-lst &optional no-err-flg) "Returns node associated to ID." (or (dolist (node node-lst nil) (when (eq id (graph-node-id node)) (return node))) (and id (listp id) ; the nodes created when we ; break cycles have the same ; name than the original node ; in a list, so both node name ; should return the same graph ; node (get-node-from-id (first id) node-lst)) (if no-err-flg nil (quail-error "No graphnode for ID : ~S" id)))) (defun gn-bottom (node &aux (pos (graph-node-position node))) "Determines the bottom position of a Graph-Node." (if pos (- (or (wb::position-y pos) 0) (half (or (graph-node-height node) 0))) 0)) (defun gn-left (node &aux (pos (graph-node-position node))) "Determines the left position of a Graph-Node." (if pos (- (or (wb::position-x pos) 0) (half (or (graph-node-width node) 0))) 0)) (defun gn-right (node &aux (pos (graph-node-position node))) "Determines the right position of a Graph-Node." (if pos (+ (or (wb::position-x pos) 0) (- (half (+ 1 (or (graph-node-width node) 0))) 1)) 0)) (defun gn-top (node &aux (pos (graph-node-position node))) "Determines the top position of a Graph-Node." (if pos (+ (or (wb::position-y pos) 0) (- (half (+ 1 (or (graph-node-height node) 0))) 1)) 0)) (defun graph-node-border-width (border) "Returns a non-negative integer giving the border width." (cond ((null border) 0) ((eq border t) 1) ((integerp border) (abs border)) ((and (listp border) (integerp (first border)) (>= (first border) 0)) (first border)) (t (quail-error "Illegal border : ~S" border)))) (defun graph-region (graph) "Return the minimum region containing the graph." (if graph (prog (left-offset bottom-offset (node-lst (graph-node-lst graph))) (return (cond (node-lst (dolist (n node-lst) (measure-graph-node n)) (list (setq left-offset (min-left node-lst)) (setq bottom-offset (min-bottom node-lst)) (+ 1 (- (max-right node-lst) left-offset)) (+ 1 (- (max-top node-lst) bottom-offset)))) (t (list 0 0 0 0))))) (list 0 0 0 0))) (defun init-nodes-for-layout (ns format root-ids font) ;;; (declare (special the-node-lst)) (dolist (gn ns) (setf (graph-node-position gn) ;; T indicate prior visitation. Roots are already visited (not (not (member (graph-node-id gn) root-ids :test #'eq)))) (or (graph-node-font gn) (setf (graph-node-font gn) font))) (dolist (r root-ids) (if (eq-or-member 'lattice format) (lattice-break-cycles (get-node-from-id r the-node-lst) nil) (forest-break-cycles (get-node-from-id r the-node-lst)))) (dolist (gn the-node-lst) (setf (graph-node-position gn) nil) (set-label-size gn))) (defun interpret-mark-format (format) "Sets special variables for new-instance-of-graph-node and mark-graph-node." (declare (special box-both-flg box-leaves-flg border-for-marking label-shade-for-marking)) (prog (pl) (and (eq-or-member 'copies-only format) (setq box-both-flg nil)) (and (eq-or-member 'not-leaves format) (setq box-leaves-flg nil)) (cond ((not (listp format)) (return)) ((eq (car format) 'mark) (setq pl (cdr format))) (t (return))) (if (member 'border pl :test #'eq) (setq border-for-marking (getf pl 'border)) (setq border-for-marking 'dont)) (if (member 'label-shade pl :test #'eq) (setq label-shade-for-marking (getf pl 'label-shade)) (setq label-shade-for-marking 'dont)))) (defun intersect-regionp-lbwh (left bottom width height reg) "Like intersect regions, but without requiring the consing." (not (or (> (wb::region-bottom reg) (+ bottom height)) (< (+ (wb::region-left reg) (wb::region-width reg)) left) (> (wb::region-left reg) (+ left width)) (< (+ (wb::region-bottom reg) (wb::region-height reg)) bottom)))) (defun lattice-break-cycles (node stack) ;;; ;;; (declare (special the-node-lst)) (setf (graph-node-position node) t) (let (d gn) (do ((d-tail (graph-node-to-nodes node) (cdr d-tail))) ((null d-tail)) ; (setq gn (get-node-from-id (setq d (first d-tail)) the-node-lst)) (cond ((member d stack) (setq gn (new-instance-of-graph-node gn)) (setf (first d-tail) (graph-node-id gn))) ((null (graph-node-position gn)) (lattice-break-cycles gn (cons d stack))))))) (defun layout (graph) ;;; ;;; Layout in lattice for tests ;;; (let (roots) (dolist (node (graph-node-lst graph)) (unless (dolist (link (graph-node-from-nodes node)) (when (get-node-from-id link (graph-node-lst graph) ) (return t))) (push (graph-node-id node) roots))) (show-graph (layout-graph (graph-node-lst graph) roots 'lattice nil nil nil nil)))) (defun layout-graph (the-node-lst root-ids format font &optional mother-d personal-d family-d) "Takes a list of Graph-node records and a list node ids for the top level ~ nodes, where the graph-nodes have only the NODE-ID, NODE-LABEL and ~ TO-NODES fields filled in. It fills in the other fields approprietly ~ according the format switch and the boxing switch so that the graph ~ becomes a forest. If there are loops in the graph they are snapped and the ~ NODE-LST is extended with push this function returns a graph record with ~ the display slots filled in appropriately." (declare (special the-node-lst mother-d personal-d family-d)) (prog ((box-both-flg t) (box-leaves-flg t) (border-for-marking t) (label-shade-for-marking 'dont) g) (declare (special box-both-flg box-leaves-flg border-for-marking label-shade-for-marking)) (or (and root-ids (listp root-ids)) (quail-error "LAYOUT-GRAPH needs a LIST of root node ids")) (dolist (r root-ids) ; the nodes of ROOT-IDS must be ; in THE-NODE-LST (unless (dolist (node the-node-lst nil) (when (eq r (graph-node-id node)) (return t))) (quail-error "~S is in ROOT-IDS but no GRAPH-NODE for it in THE-NODE-LST" r))) (setq font (if (wb::canvas-font-p font) font *graph-default-font*)) (or mother-d (setq mother-d (wb::string-width "AAAAAA" font))) (or personal-d (setq personal-d (if (eq-or-member 'vertical format ) (wb::string-width "AA" font) 0))) (or family-d (setq family-d (half (wb::canvas-font-ascent font)))) (interpret-mark-format format) (init-nodes-for-layout the-node-lst format root-ids font) (and (eq-or-member 'vertical format) (switch-node-height-width the-node-lst)) (setq g (cond ((eq-or-member 'lattice format) (browse-layout-lattice root-ids)) ((eq-or-member 'fast format) (browse-layout-horiz root-ids)) (t (browse-layout-horiz-compactly root-ids)))) (dolist (n the-node-lst) (or (wb::position-p (graph-node-position n)) (quail-error "Disconnected graph. Root(s) didn't connect to : ~S" (graph-node-label n)))) (offset-to-origin the-node-lst) (cond ((eq-or-member 'vertical format) (switch-node-height-width the-node-lst) (reflect-graph-diagonally g) (and (eq-or-member 'reverse format) (reflect-graph-vertically g)) (and (eq-or-member 'reverse-daughters format) (reflect-graph-horizontally g))) (t (and (eq-or-member 'reverse format) (reflect-graph-horizontally g)) (and (eq-or-member 'reverse-daughters format) (reflect-graph-vertically g)))) (return g))) (defun layout-s-expr (tree &optional format boxing font mother-d personal-d family-d) "Assumes CAR of Tree is Node label, CDR is daughter trees." (if tree (prog (result) (declare (special result)) (layout-s-expr-1 tree) ;; Result contains a list of node corresponding to Tree which ;; label and to-nodes link are updated (return (layout-graph result (list tree) (append (if (listp format) format (list format)) boxing) font mother-d personal-d family-d))) (quail-error "Cannot layout NIL as S-EXPRESSION"))) (defun layout-s-expr-1 (tree) ;;; (declare (special result)) (cond ((dolist (r result nil) ; If Tree is already in result ; nothing is done (when (eq tree (graph-node-id r)) (return t)))) ((not (listp tree)) ; if Tree is a simple node it ; is added in result (push (make-graph-node :id tree :label tree) result)) ; otherwise Tree is a node with ; subnodes which are ; recursively added to result (t (push (make-graph-node :id tree :label (first tree) :to-nodes (append (cdr tree))) result) (dolist (d (cdr tree)) (layout-s-expr-1 d))))) (defun mark-graph-node (node) "Changes appearance of graph node to indicate that a link has been snapped." (declare (special border-for-marking label-shade-for-marking)) (or (eq border-for-marking 'dont) (setf (graph-node-border node) border-for-marking)) (or (eq label-shade-for-marking 'dont) (setf (graph-node-label-shade node) label-shade-for-marking))) (defun max-right (node-lst) "Returns the largest right position of nodes in Node-lst." (let ((largest (gn-right (car node-lst)))) (dolist (node node-lst) (when (> (gn-right node) largest) (setq largest (gn-right node)))) largest)) (defun max-top (node-lst) "Returns the largest Top position of nodes in Node-Lst." (let ((largest (gn-top (car node-lst)))) (dolist (node node-lst) (when (> (gn-top node) largest) (setq largest (gn-top node)))) largest)) (defun measure-graph-node (node &optional (reset-flg nil)) "Measure the node label image." (set-label-size node reset-flg) (set-layout-position node (or (graph-node-position node) (quail-error "This Graph node has not been given a position : ~S" node)))) (defun memb-to-nodes (to-node to-nodes) (dolist (z to-nodes) (when (eq z to-node) (return z)))) (defun min-bottom (node-lst) "Returns the smallest bottom position of nodes in Node-Lst." (let ((smallest (gn-bottom (car node-lst)))) (dolist (node node-lst) (when (< (gn-bottom node) smallest) (setq smallest (gn-bottom node)))) smallest)) (defun min-left (node-lst) "Returns the smallest left position of nodes in Node-lst." (let ((smallest (gn-left (car node-lst)))) (dolist (node node-lst) (when (< (gn-left node) smallest) (setq smallest (gn-left node)))) smallest)) (defun new-instance-of-graph-node (node) "Returns a second instance of the graph-node, boxing it." (declare (special the-node-lst box-leaves-flg box-both-flg)) (prog ((new (make-graph-node :id (list (graph-node-id node)) :label (graph-node-label node) :font (graph-node-font node) :width (graph-node-width node) :height (graph-node-height node) :border (graph-node-border node) :label-shade (graph-node-label-shade node)))) (push new the-node-lst) (when (or box-leaves-flg (graph-node-to-nodes node)) ; in the original version, the node are boxed when they are ; duplicated. we remove this so that every node seems identical ; on the map ;(mark-graph-node new) ;(when box-both-flg (mark-graph-node node)) ) (return new))) (defun node-lst-as-menu (node-lst position) "Find the node that is closest to position and returns it ~ the node N of Node-lst is returned if position is inside the region it ~ occupies in the window otherwise NIL is returned." (let ((x (wb::position-x position)) (y (wb::position-y position)) t1 t2) (dolist (n node-lst nil) (when (and (< (- (setq t1 (wb::position-y (graph-node-position n))) (setq t2 (half (graph-node-height n)))) y) (< y (+ t1 t2)) (< (- (setq t1 (wb::position-x (graph-node-position n))) (setq t2 (half (graph-node-width n)))) x) (< x (+ t1 t2))) (return n))))) (defun offset-to-origin (node-lst) "After layout, the computed positions can be negative, which can be a problem ~ on some environments. To avoid this, we systematically offset the graph so ~ that each position is positive." (let ((inf-x (min-left node-lst)) (inf-y (min-bottom node-lst)) pos) (unless (and (eq 0 inf-x) (eq 0 inf-y)) (dolist (node node-lst) (setq pos (graph-node-position node)) (setf (wb::position-x pos) (- (wb::position-x pos) inf-x)) (setf (wb::position-y pos) (- (wb::position-y pos) inf-y)))))) (defun print-display-node (node window &optional clip-reg operation) "Prints a node at its position. Takes the operation from ~ the stream so that when editor has set the operation to :invert, this may ~ erase as well as draw; but when the operation is :paint, then nodes obliterate ~ any link lines that they are drawn over." (declare (special *graph-cache-node-labels*)) (setf operation (case operation (:invert boole-xor) (:paint :default) (T NIL))) (unless (eq 0 (graph-node-height node)) (prog ((left (gn-left node)) (bottom (gn-bottom node)) (width (graph-node-width node)) (height (graph-node-height node)) (font (graph-node-font node)) (nbw (graph-node-border-width (graph-node-border node)))) (when (and clip-reg (not (intersect-regionp-lbwh left bottom width height clip-reg))) (return node)) (cond ((wb::bitmap-p (graph-node-label-bitmap node)) (wb::canvas-bitblt (graph-node-label-bitmap node) window :canvas-left left :canvas-bottom bottom :width width :height height :operation operation)) ((wb::bitmap-p (graph-node-label node)) (cond ((eq 0 nbw) (wb::canvas-bitblt (graph-node-label node) window :canvas-left left :canvas-bottom bottom :width width :height height :operation operation)) (t (draw-graph-node-border (graph-node-border node) left bottom width height window) (wb::canvas-bitblt (graph-node-label node) window :canvas-left (+ left nbw) :canvas-bottom (+ bottom nbw) :width width :height height :operation operation)))) (t (or (wb::canvas-font-p font) (setf (graph-node-font node) (setq font (wb::canvas-font window)))) (if (not (eq nbw 0)) (draw-graph-node-border (graph-node-border node) left bottom width height window)) (wb::canvas-draw-center-string (graph-node-label node) left bottom width height window :font font) (if (graph-node-label-shade node) (fill-graph-node-label (graph-node-label-shade node) left bottom width height nbw window)) (when (and *graph-cache-node-labels* clip-reg (intersect-regionp-lbwh left bottom width height clip-reg)) (setf (graph-node-label-bitmap node) (wb::make-bitmap :width width :height height)) (wb::copy-canvas-region-to-bitmap window left bottom (graph-node-label-bitmap node) width height)) )) (return node)))) (defun raise-transition-chain (tc raise) "Raises a daughter's transition chain by adding in the offset of the ~ daughter's box relative to the mother's box." (dolist (p tc tc) (setf (wb::position-y p) (+ (wb::position-y p) raise)))) (defun redisplay-graph (window &rest rest) "Displays the graph that is in a window." (declare (ignore rest)) (wb::canvas-clear window) (when (wb::display-of window) (display-graph (wb::display-of window) window (wb::clipping-region-of window) ))) (defun reflect-graph-diagonally (graph) (setf (graph-side-flg graph) (not (graph-side-flg graph))) (let (yn) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setq yn (wb::position-y n)) (setf (wb::position-y n) (wb::position-x n)) (setf (wb::position-x n) yn)))) (defun reflect-graph-horizontally (graph) (let ((w (+ (max-right (graph-node-lst graph)) (min-left (graph-node-lst graph))))) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setf (wb::position-x n) (- w (wb::position-x n)))))) (defun reflect-graph-vertically (graph) (let ((h (+ (max-top (graph-node-lst graph)) (min-bottom (graph-node-lst graph))))) (dolist (n (graph-node-lst graph)) (setq n (graph-node-position n)) (setf (wb::position-y n) (- h (wb::position-y n)))))) (defun set-label-size (node &optional reset-flg) ;;; ;;; the SHADE and null font stuff is for ZOOM-GRAPH ;;; (or (and (not reset-flg) (integerp (graph-node-height node)) (integerp (graph-node-width node))) (prog ((font (graph-node-font node)) (lab (graph-node-label node)) (nbw (graph-node-border-width (graph-node-border node))) width height) (cond ((wb::bitmap-p lab) (setq width (wb::bitmap-width lab)) (setq height (wb::bitmap-height lab))) (t (or (stringp lab) (if (symbolp lab) (setq lab (symbol-name lab)) (setq lab (format nil "~s" lab))) ) (or (wb::canvas-font-p font) (setf (graph-node-font node) (setq font *graph-default-font*))) (setq width (+ (wb::string-width lab font) (wb::canvas-font-descent font))) (setq height (+ (wb::canvas-font-height font) (wb::canvas-font-descent font))))) (or (and (not reset-flg) (integerp (graph-node-width node))) (setf (graph-node-width node) (+ width nbw nbw))) (or (and (not reset-flg) (integerp (graph-node-height node))) (setf (graph-node-height node) (+ height nbw nbw))) (return node)))) (defun set-layout-position (node position) "Sets a node position." (setf (wb::position-x (graph-node-position node)) (wb::position-x position)) (setf (wb::position-y (graph-node-position node)) (wb::position-y position))) (defun size-graph-window (graph window-or-title &optional top-justify-flg) "Returns a window sized to fit the given graph. WINDOW-OR-TITLE can be ~ either a window to be printed in or a title of a window to be created.If ~ TOP-JUSTIFY-FLG is T, scrolls so top of graph is at top of window, else ~ puts bottom of graph at bottom of window." (declare (special *min-width-graph* *max-width-graph* *min-height-graph* *max-height-graph*)) (prog ((graph-reg (graph-region graph)) cursor-pos title window) (if (wb::canvas-p window-or-title) (setq window window-or-title) (setq title window-or-title)) (or title (setq title "Graph window")) ;; ;; If there is not already a window, ask the user for one to fit. ;; (cond ((null window) ;;(setq cursor-pos (screen-mouse-position)) (setq window (make-browser :region (list (wb::position-x cursor-pos) (wb::position-y cursor-pos) (wb::compute-window-width (min (max (third graph-reg) *min-width-graph*) *max-width-graph*)) (wb::compute-window-height (min (max (fourth graph-reg) *min-height-graph*) *max-height-graph*) title)) :title title))) (t (wb::canvas-to-top window))) (wb:set-extent-canvas-region window graph-reg) (wb:set-canvas-x-offset window (- (wb::canvas-x-offset window) (first graph-reg))) (wb:set-canvas-y-offset window (- (wb::canvas-y-offset window) (if top-justify-flg (- (+ (second graph-reg) (fourth graph-reg)) (wb::canvas-height window)) (second graph-reg)))) (return window))) (defun show-graph (&optional graph window top-justify-flg) "Puts the graph in a window and create one if it is not given." (setq window (size-graph-window (or graph (setq graph (make-graph))) window top-justify-flg)) (setf (wb::display-of window) graph) (redisplay-graph window) window) (defun switch-node-height-width (node-lst) (let (wn) (dolist (n node-lst) (setq wn (graph-node-width n)) (setf (graph-node-width n) (graph-node-height n)) (setf (graph-node-height n) wn)))) (defun to-links (node) (graph-node-to-nodes node)) (defun move-node-to (node to-pos window &optional clipping-region) (let* ((graph (wb::display-of window))) (erase-node-links node window graph) (erase-node-label node window) (setf (graph-node-position node) to-pos) (display-node-links node window graph) (print-display-node node window clipping-region) (flip-node node window) )) (defun relative-move-node-to (node dx dy window &optional clipping-region) (let ((current-pos (graph-node-position node))) (move-node-to node (wb::make-position (+ (wb::position-x current-pos) dx) (+ (wb::position-y current-pos) dy)) window clipping-region))) (defun move-nodes (node-list current-position canvas &optional clipping-region) "Dynamically moves all nodes of node-list in the graph of the window canvas." (let ((old-pos current-position) (new-pos current-position) dx dy) (loop while (wb::mouse-down-p) do (setf new-pos (wb::mouse-position canvas)) (unless (and (= (wb::position-x new-pos) (wb::position-x old-pos)) (= (wb::position-y new-pos) (wb::position-y old-pos))) (loop for node in node-list do (setf dx (- (wb::position-x new-pos) (wb::position-x old-pos))) (setf dy (- (wb::position-y new-pos) (wb::position-y old-pos))) (relative-move-node-to node dx dy canvas clipping-region)) (setf old-pos new-pos))) (unless (and (= (wb::position-x new-pos) (wb::position-x current-position)) (= (wb::position-y new-pos) (wb::position-y current-position))) (if clipping-region (wb::canvas-clear canvas :canvas-left (wb::region-left clipping-region) :canvas-bottom (wb::region-bottom clipping-region) :width (wb::region-width clipping-region) :height (wb::region-height clipping-region)) (wb::canvas-clear canvas)) (display-graph (wb::display-of canvas) canvas clipping-region)))) (defun move-node (node current-position canvas &optional clipping-region) "Dynamically moves the node in the graph of the canvas." (let ((old-pos current-position) (new-pos current-position)) (loop while (wb::mouse-down-p) do (setf new-pos (wb::mouse-position canvas)) (unless (and (= (wb::position-x new-pos) (wb::position-x old-pos)) (= (wb::position-y new-pos) (wb::position-y old-pos))) (move-node-to node new-pos canvas clipping-region) (setf old-pos new-pos))) (unless (and (= (wb::position-x new-pos) (wb::position-x current-position)) (= (wb::position-y new-pos) (wb::position-y current-position))) (if clipping-region (wb::canvas-clear canvas :canvas-left (wb::region-left clipping-region) :canvas-bottom (wb::region-bottom clipping-region) :width (wb::region-width clipping-region) :height (wb::region-height clipping-region)) (wb::canvas-clear canvas)) (display-graph (wb::display-of canvas) canvas clipping-region)))) (defun erase-node-label (node canvas) "Erases the label of the node in the canvas" (unless (eq 0 (graph-node-height node)) (let ((left (+ (gn-left node) -1)) (bottom (+ (gn-bottom node) -1)) (width (+ (graph-node-width node) 2 )) (height (+ (graph-node-height node) 2))) (wb::canvas-clear canvas :canvas-left left :canvas-bottom bottom :width width :height height))))
64,676
Common Lisp
.l
1,347
31.227914
92
0.485806
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1716e6f3f79fc43a234110e86448e854fc95aaac3a08a5718e43785766635bcd
33,910
[ -1 ]
33,911
graph.lsp
rwoldford_Quail/source/browser/graph.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; graph.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(graph-node-height graph-node-width graph-node-font graph-node-label-symbol graph-node-to-nodes graph-node-from-nodes graph-node-id graph-node-lst make-graph-node graph make-graph graph-node-lst))) (defclass graph-node (simple-view) ((id :initform NIL :accessor graph-node-id) (position :initform NIL :accessor graph-node-position) (label-bitmap :initform NIL :accessor graph-node-label-bitmap) (width :initform NIL :accessor graph-node-width) (height :initform NIL :accessor graph-node-height) (links :initform NIL :accessor graph-node-links) (to-nodes :initform NIL :accessor graph-node-to-nodes) (from-nodes :initform NIL :accessor graph-node-from-nodes) (label-symbol :initform NIL :accessor graph-node-label-symbol) (label-shade :initform *graph-default-node-label-shade* :accessor graph-node-label-shade ) (font :initform *graph-default-node-font* :accessor graph-node-font) (border :initform *graph-default-node-border* :accessor graph-node-border)) (:documentation "A node of a directed-graph.")) #| The next step would be to remove the nodes from each other and insert a link. (defgeneric graph-node-to-nodes (graph-node) (:documentation "Determines the nodes which are on a direct link from ~ the current node. This could be at the end of a directed ~ or undirected link.")) (defmethod graph-node-to-nodes ((self graph-node)) (loop for link in (graph-node-links-of self) when (graph-link-from-p link self) collect (graph-link-to-node link))) ;;; Need to do more checking here in order to use the same links ;;; between nodes. (defmethod (setf graph-node-to-nodes) (new-nodes (self graph-node)) (setf (graph-node-links self) (loop for new-node in new-nodes collect (make-instance 'graph-link :from-node self :to-node new-node))) new-nodes) (defmethod (setf graph-node-from-nodes) (new-nodes (self graph-node)) (setf (graph-node-links self) (loop for new-node in new-nodes collect (make-instance 'graph-link :from-node new-node :to-node self))) new-nodes) (defmethod graph-node-from-nodes ((self graph-node)) (loop for link in (graph-node-links-of self) when (graph-link-to-p link self) collect (graph-link-from-node link))) |# (defun make-graph-node (&rest args) "Makes an instance of graph-node." (if args (apply #'make-instance 'graph-node args) (make-instance 'graph-node))) (defclass graph (pass-draws-to-subviews compound-view) ((node-lst :initform NIL :accessor graph-node-lst) (side-flg :initform NIL :accessor graph-side-flg) (directed-flg :initform NIL :accessor graph-directed-flg)) (:documentation "A directed graph.")) (defun make-graph (&rest args) "Makes an instance of a graph." (if args (apply #'make-instance 'graph args) (make-instance 'graph))) (defclass graph-link (line-segment) ((from-node :initform NIL :accessor graph-link-from-node) (to-node :initform NIL :accessor graph-link-to-node) (directed? :initform T :accessor graph-link-directed-p) ) (:documentation "A link between two nodes in a graph.")) (defun graph-link-from-p (link node) "Tests whether the argument node defines the root of the link. ~ Note that undirected links are considered to be bi-directional ~ so that if node is at either end of an undirected link, this function ~ will return t. ~ (:required ~ (:arg link A graph link) ~ (:arg node The node to be tested.)) ~ (:returns T or NIL if the node is considered the root of a direction, or not)" (if (graph-link-directed-p link) (eq node (graph-link-from-node link)) (or (eq node (graph-link-from-node link)) (eq node (graph-link-to-node link))))) (defun graph-link-to-p (link node) "Tests whether the argument node defines the end of the link. ~ Note that undirected links are considered to be bi-directional ~ so that if node is at either end of an undirected link, this function ~ will return t. ~ (:required ~ (:arg link A graph link) ~ (:arg node The node to be tested.)) ~ (:returns T or NIL if the node is considered the end of a direction, or not)" (if (graph-link-directed-p link) (eq node (graph-link-to-node link)) (or (eq node (graph-link-from-node link)) (eq node (graph-link-to-node link)))))
5,281
Common Lisp
.l
121
37.68595
86
0.623927
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9eaedf6db7b3b32ba6e4c43061e36eb31996c0489dd82fb1d3aa91a811367f84
33,911
[ -1 ]
33,912
problems
rwoldford_Quail/source/browser/Notes/problems
#|Problems 1. labels outside of window area are not redrawn when scrolled 2. visible region is a little too short in shape-to-hold 3. reshaping window seems to change coordinate system without redisplaying 4. browser insists on adding points above the origin rather than below. |# ;;; Canvas region information: (wb::canvas-height self) (wb::canvas-width self) (wb::canvas-region self) (wb::clipping-region-of self) (get-active-region self) (wb::canvas-content-region-of self) (wb::extent-region-of self) (wb::mouse-position self) (wb::canvas-x-offset self) wb::*default-canvas-region* (wb::set-up-default-canvas-region) (wb::canvas-screen-region self) wb::*screen-region*
712
Common Lisp
.l
20
32.7
78
0.746356
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
be3ef1cf4ae7a440867b753238dea0e188b9fe5a1eeb09535814e7e1206711ec
33,912
[ -1 ]
33,916
quail-kernel-package.lsp
rwoldford_Quail/source/quail-kernel/quail-kernel-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-kernel-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1990 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; M.E. Lewis 1991. ;;; ;;;---------------------------------------------------------------------------- #+:CL-2 (DEFPACKAGE "QUAIL-KERNEL" #+:sbcl-linux (:USE :clim :clim-lisp :clim-extensions) ;"COMMON-LISP") ; 19 November 2019 #+:aclpc-linux (:USE :common-lisp) (:NICKNAMES "QK" "quail-kernel") ;(:SHADOWING-IMPORT-FROM "COMMON-LISP" "ARRAY") ; 19 November 2019 commented out 07JUN2023 to avoid compile complaint? #+:aclpc-linux(:SHADOWING-IMPORT-FROM "ACLMOP" "CLASS-PRECEDENCE-LIST") ; 05 FEB 2020 #+:aclpc-linux(:SHADOWING-IMPORT-FROM "SYSTEM" "FUNCTION-INFORMATION") ; 05 FEB 2020 (:SHADOW "ARRAY-ELEMENT-TYPE" "ARRAY-RANK" "ARRAY-DIMENSION" "ARRAY-DIMENSIONS" "ARRAY-TOTAL-SIZE" "ARRAY-IN-BOUNDS-P" "ADJUSTABLE-ARRAY-P" "ARRAY-ROW-MAJOR-INDEX" "SORT" "PACKAGE" ;"ARRAY" ;; see above shadowing-import-from 19 November 2019 "CLASS-SLOTS" ;#-:aclpc-linux "CLASS-PRECEDENCE-LIST" ; see above 23feb2020 It's in :SHADOWING-IMPORT-FROM ABOVE l23 "CLASS-PROTOTYPE") (:EXPORT "ARRAY-ELEMENT-TYPE" "ARRAY-RANK" "ARRAY-DIMENSION" "ARRAY-DIMENSIONS" "ARRAY-TOTAL-SIZE" "ARRAY-IN-BOUNDS-P" "ADJUSTABLE-ARRAY-P" "ARRAY-ROW-MAJOR-INDEX" "SORT" "SORT-OBJECT" "<-" ;; 05FEB2020 "+INFINITY" ;;07APR2020 "INFINITY" ;;07APR2020 "-INFINITY" ;; 07APR2020 ;"DIMENSIONED-REF-OBJECT" ;;15AUG2020 )) #-:CL-2 (IN-PACKAGE :QUAIL-KERNEL :USE '(PCL LISP) :NICKNAMES '(QK QUAIL-KERNEL ZK)) #-:CL-2 (SHADOW '(ARRAY-ELEMENT-TYPE ARRAY-RANK ARRAY-DIMENSION ARRAY-DIMENSIONS ARRAY-TOTAL-SIZE ARRAY-IN-BOUNDS-P ADJUSTABLE-ARRAY-P ARRAY-ROW-MAJOR-INDEX SORT)) #-:CL-2 (EXPORT '(ARRAY-ELEMENT-TYPE ARRAY-RANK ARRAY-DIMENSION ARRAY-DIMENSIONS ARRAY-TOTAL-SIZE ARRAY-IN-BOUNDS-P ADJUSTABLE-ARRAY-P ARRAY-ROW-MAJOR-INDEX))
2,565
Common Lisp
.l
74
26.810811
120
0.517893
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
47915eeeabbc6d00fb6f2f86872f4acc77a110d70a027404ab9613f0c3a76156
33,916
[ -1 ]
33,917
quail-kernel-system-sblx.lsp
rwoldford_Quail/source/quail-kernel/quail-kernel-system-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; quail-kernel-system-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; Authors: ;;; Greg Anglin 1990, 1991. ;;; Simply copied -pc version by G.W. Bennett 2017 ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (defun system-get-pointer (x) (declare (ignore x)) 0)
592
Common Lisp
.l
12
47.083333
84
0.355172
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9ec944ba072cc7fbd24238302d4f8ae4c338ad05db951148a6e8a78fa9842afb
33,917
[ -1 ]
33,918
quail-kernel-system-pc.lsp
rwoldford_Quail/source/quail-kernel/quail-kernel-system-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; quail-kernel-system-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; Authors: ;;; Greg Anglin 1990, 1991. ;;; Simply copied by G.W. Bennett 1997 ;;;-------------------------------------------------------------------------------- ;(in-package :quail-kernel) (defun system-get-pointer (x) (declare (ignore x)) ;24JUN2023 0)
591
Common Lisp
.l
12
46.916667
84
0.352332
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
825f7ceab9b9ee16ce79eadaf86cc6cc100382b1fb43569e27a2194f5b19408c
33,918
[ -1 ]
33,919
do-test.lsp
rwoldford_Quail/source/quail-kernel/test/do-test.lsp
;;; ********************************** do-test.lisp ************************** ;;; BROKEN !!! (in-package :make) (load (merge-pathnames (in-z-source (path-z-test) "test-ref.lisp")) (load (merge-pathnames (in-z-source (path-z-test) "test-collapse.lisp")) (load (merge-pathnames (in-z-source (path-z-test) "test-glue.lisp"))
341
Common Lisp
.l
6
52.833333
79
0.544892
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b6b85b3fd689a613df99e3e586e839104f94fe02ddbd69690392eebee21c2865
33,919
[ -1 ]
33,920
test-ops.lsp
rwoldford_Quail/source/quail-kernel/test/test-ops.lsp
;;; ******************************* test-ops.lisp ****************************** (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) (setf at (tp a)) ; transpose of a (setf b (array '(2 3) :initial-contents '((101.2 103.0 104.5) (206.7 208.9 200.1)))) (setf c (array '(2 1) :initial-contents '((100.0) (200.0)))) (setf d '(0 10 20 30 40 50 60 70 80)) (setf e (array '(3 2) :initial-contents '((0 0) (1 1) (0 2)))) (setf g (array '(2 3 4) :initial-contents '(((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)) ((10 20 30 40) (50 60 70 80) (90 100 110 120))))) ;------------------------------------------------------------------------------- ; new+, z-, new*, Q- do ELEMENT-WISE +, -, *, / in extended real numbers ; .* does inner product and matrix multiplication ; these functions are all n-ary (Q+ a b) (Q* a b) (.* at a) (Q- d) (setf (ref b 0 1) nan) b (Q/ b a) (.* at b) (Q* d d d) (.* d d) (quail-min +infinity 5 0.7 2000) (quail-min -infinity NaN) (quail-max +infinity) ; tp for 0, 1, 2 dimensional things. (tp d) ; tp has a more general form for higher dimensional things (tp a :perm '(1 0)) ; same as (tp a) (tp g :perm '(2 0 1))
1,613
Common Lisp
.l
37
31.027027
81
0.393659
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
12dd5e0557e3e220a49d709f56dcec02c3d26d9568ef63782362c31db166b5c5
33,920
[ -1 ]
33,921
test-inject.lsp
rwoldford_Quail/source/quail-kernel/test/test-inject.lsp
;;; ****************************** test-inject.lisp *************************** (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) (setf c (array '(2 1) :initial-contents '((100.0) (200.0)))) (setf d '(0 10 20 30 40 50 60 70 80)) (setf e (array '(3 2) :initial-contents '((0 0) (1 1) (0 2)))) (setf g (array '(2 3 4) :initial-contents '(((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)) ((10 20 30 40) (50 60 70 80) (90 100 110 120))))) ;------------------------------------------------------------------------------ (inject '(1 2 3) t #'Q+ :init 0) (inject (vector 1 2 3) t #'new+) (inject 10 t #'new+) (inject 10 nil #'new+) (defun sum (r &optional (margin nil)) (let ((not-margin (if (atom margin) (not margin) (mapcar #'not margin)))) (inject r not-margin #'new+))) (ref g) (sum g) (sum g '(t nil nil)) (sum g '(t t nil)) ;; This one blows up ... FIND OUT WHY !!!! ;(sum g '(t nil t)) (sum g '(nil t nil))
1,334
Common Lisp
.l
29
31.37931
80
0.357427
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e55a524ef7532e29c9a7dc80ef8e4d4f552463807a08fb4fa3f158017d7038cc
33,921
[ -1 ]
33,922
test-linpack.lsp
rwoldford_Quail/source/quail-kernel/test/test-linpack.lsp
;;;****************************** test-linpack.lisp ********************** (in-package :quail) ;=========================================================================== (defunf 'dchdc-hook :language :fortran :entry-name "DCHDC" :arguments '((array f-real*8) ;a fixnum ;lda fixnum ;p (array f-real*8) ;work (array f-integer) ;jpvt fixnum ;job (array f-integer) ;info )) ;=========================================================================== (defun dchdc (a jpvt job) (let* ((dims (dimensions-of a)) (nrow (first dims)) (work (make-array (list nrow) :initial-element 0)) (info (make-array '() :initial-element 0))) (dchdc-hook a nrow nrow work jpvt job info) (eref info))) ;-------------------------------------------------------------------------- (setf a (make-array '(3 3) :initial-contents '((1.523 1.897 3.456) (0.000 7.890 0.765) (0.000 0.000 10.56)))) (setf jpvt (make-array '(3) :initial-contents '(0 0 0))) (setf job 0) (dchdc a jpvt job) a jpvt (.* (tp a) a)
1,509
Common Lisp
.l
31
32.612903
77
0.314738
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
df14deee2573e6acb11cd514b68bdaf6dd71bb23ee280fc717cd75dbbb03a7b5
33,922
[ -1 ]
33,923
test-linpack-old.lsp
rwoldford_Quail/source/quail-kernel/test/test-linpack-old.lsp
;;;****************************** test-linpack.lisp ********************** (in-package :quail) (load "ccl;Z:Z:zffi-load-all.lisp") ;=========================================================================== (defunf 'dchdc-hook :language :fortran :entry-name "DCHDC" :arguments '((array f-real*8) ;a fixnum ;lda fixnum ;p (array f-real*8) ;work (array f-integer) ;jpvt fixnum ;job (array f-integer) ;info )) ;-------------------------------------------------------------------------- (defgeneric dchdc (a jpvt job)) (defmethod dchdc ((self foreign-array) jpvt job) (let* ((dims (dimensions-of self)) (nrow (first dims))) (with-open-quail-objects (self jpvt :temp work info) #'quail-pred3 (setf work (array (list nrow) 'f-real*8 :class 'f-array :language :fortran)) (setf info (array '() 'f-integer :class 'f-array :language :fortran)) (dchdc-hook self nrow nrow work jpvt job info) (eref info)))) ;-------------------------------------------------------------------------- (setf a (array '(3 3) :type 'f-real*8 :class 'f-array :language :fortran :initial-contents '((1.523 1.897 3.456) (0.000 7.890 0.765) (0.000 0.000 10.56)))) (setf jpvt (array '(3) :type 'f-integer :class 'f-array :language :fortran :initial-contents '(0 0 0))) (setf job 0) (dchdc a jpvt job) a jpvt (.* (tp a) a) ;==========================================================================
2,127
Common Lisp
.l
43
32.209302
77
0.331871
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f7f60573ba5049b4a4f291098fa85d821a3b5098fe4763eb3bb2df2a1ce6f48c
33,923
[ -1 ]
33,924
test-ff.lsp
rwoldford_Quail/source/quail-kernel/test/test-ff.lsp
;;; ******************* test-ff.lisp *********************************** (in-package :quail) (load "ccl;Z:Z:zffi-load.lisp") (import 'zffi::peek) ;------------------------------------------------------------------------------ (setf aa (array '(1) :type 'f-real*8 :class 'f-array :language :fortran :initial-element 0)) (peek aa) (setf ab (array '(2 3 4) :type 'f-real*8 :class 'f-array :language :fortran :initial-element 1)) (progn (loop for i from 0 to 1 do (loop for j from 0 to 2 do (loop for k from 0 to 3 do (setf (eref ab i j k) (sqrt (* (+ i 2) (+ j 3) (+ k 4))))))) ab) (peek ab) (setf ac (array '(2 3 4) :type 'f-integer :class 'f-array :language :fortran :initial-contents '(((1 2 3 4) (5 6 7 8) (9 10 11 12)) ((13 14 15 16) (17 18 19 20) (21 22 23 24))))) (ref ac t 0 t) (setf ad (array '(2 3) :type 'f-real*8 :class 'f-array :language :fortran :initial-contents '((1.7893 2.4678 3.8976) (4.1256 5.9876 6.3487)))) (setf ae (ref ad '(0 1 0 1 0 1) '(0 1 2 0 1 2 0 1 2))) (setf af (tp ae)) (setf ag (array '(2 3 4) :type 'f-real*8 :class 'f-array :language :c :initial-contents '(((1 2 3 4) (5 6 7 8) (9 10 11 12)) ((13 14 15 16) (17 18 19 20) (21 22 23 24))))) (setf a0 '(((210 220 230 240) (350 360 370 380) (90 100 110 120)) ((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)))) (make-array '(2 3 4) :initial-contents a0) (setf ah (array '(2 3 4) :type 'f-real*8 :class 'f-array :language :fortran :initial-contents '(((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)) ((10 20 30 40) (50 60 70 80) (90 100 110 120))))) (setf ai (array '(5 3 3) :type 'f-real*8 :class 'f-array :language :c :initial-contents '((( 1 2 3) ( 4 5 6) ( 7 8 9)) ((10 11 12) (13 14 15) (16 17 18)) ((19 20 21) (22 23 24) (25 26 27)) ((28 29 30) (31 32 33) (34 35 36)) ((37 38 39) (40 41 42) (43 44 45)))))
3,927
Common Lisp
.l
81
21.395062
81
0.258294
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
43ae1f8d0df4da02a802b58e41f202bc7c1ce302f3cbd6c23799a6d989d20e72
33,924
[ -1 ]
33,925
test-collapse.lsp
rwoldford_Quail/source/quail-kernel/test/test-collapse.lsp
;;; **************************** test-collapse.lisp *************************** (in-package :quail-user) (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) ;------------------------------------------------------------------------------ (collapse 5 nil #'(lambda (x) (* x x))) #| (collapse "abcde" nil #'reverse) (collapse "abcde" t #'(lambda (x) (make-string 3 :initial-element x))) |# (collapse a t #'tp) (collapse a '(nil t) #'tp) (collapse a '(t) #'tp) (collapse a nil #'tp) (collapse a t #'ref-list) (collapse a '(nil t) #'ref-list) (collapse a '(t) #'ref-list) (collapse a nil #'ref-list)
718
Common Lisp
.l
18
33.111111
80
0.440549
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3a77fa2b8f3e6995ab3965e2c6ef4c880d20bfeb79dfef642560db8ee6b060f2
33,925
[ -1 ]
33,926
do-benchmark.lsp
rwoldford_Quail/source/quail-kernel/test/do-benchmark.lsp
;;; ****************************** do-benchmark.lisp ****************************** #+:ccl (progn (compile-file "ccl;Z:Z Source:Z Kernel:Z Test:benchmark.lisp") (load "ccl;Z:Z Source:Z Kernel:Z Test:benchmark.fasl")) #+(and :aclunix (not :aclpc)) (load "benchmark" :search-list (:first (:newest-do-compile #.(make-pathname :directory "/usr/people/dganglin/lisp/new/z-test/" :type "fasl")) (:newest-do-compile #.(make-pathname :directory "/usr/people/dganglin/lisp/new/z-test/" :type "lisp")))) ;----------------------------------------------------------------------------------
793
Common Lisp
.l
17
33
84
0.392208
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bec683a4a7499b2875c16e803550a6bb4d782b8df8db08ca4c1d39460b39e8c7
33,926
[ -1 ]
33,927
jims-bug.lsp
rwoldford_Quail/source/quail-kernel/test/jims-bug.lsp
;;; first problem ... solved ? (setf m (array '(1 3) :initial-contents '((0 1 2)))) (setf a (ref m 0 (list :c 1) :shape t)) (sel a 0) ;;; first problem ... _the day after_ (setf x (make-array '(1 2 2) :initial-contents '(((0 0) (0 2))))) (setf b (ref m x :shape t)) (sel b 0) ; fails ;;; second problem ... not solved (setf gg (array '(1) :initial-element 2)) (setf hh (array '(1 1) :initial-element 3)) (Q+ hh gg)
462
Common Lisp
.l
12
34.833333
66
0.564103
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8ee252a927aa29bf2d9de31efbd701392edc38c1b1e5ad96c38ab0659961cfa4
33,927
[ -1 ]
33,928
test-ref.lsp
rwoldford_Quail/source/quail-kernel/test/test-ref.lsp
;;; ********************************** test-ref.lisp ****************************** (in-package :quail-user) (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) (setf c (array '(2 1) :initial-contents '((100.0) (200.0)))) (setf d '(0 10 20 30 40 50 60 70 80)) (setf e (array '(3 2) :initial-contents '((0 0) (1 1) (0 2)))) (setf g (array '(2 3 4) :initial-contents '(((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)) ((10 20 30 40) (50 60 70 80) (90 100 110 120))))) ;---------------------------------------------------------------------------------- (setf h (ref g (array '(2 3 3) :initial-contents '(((0 1 2) (1 0 2) (1 2 0)) ((1 0 1) (1 1 2) (1 2 3)))))) (setf hh (ref h e)) (setf hhh (ref hh '(0 2))) (ref a) (ref a t 1) (ref a t 1 :shape t) (ref c) (ref c :shape t) (ref c :shape '(t nil)) (ref c :shape '(nil t)) (setf (ref a t 1) c) (ref a) (setf (ref a 0 0) 555) (sel a 0) (setf (sel a t 1) '(111.11 222.22)) a (setf (ref a 1) '(11 22 33)) (ref a) (setf d '(0 10 20 30 40 50 60 70 80)) (ref d '(2 3)) (ref d '(:c 4 6)) (ref (ref d '(:c 4 6)) '(3 4)) (setf (ref d '((2) (3))) c) d ; ; This type of ref ("by indices") basically works, but the interaction of this ; with the previous ref ("by margin") is not yet complete. For now, it's ; probably best to ignore "by indices" ref. ; a (ref a '((0 0) (1 1) (0 2))) (setf e (make-array '(3 2) :initial-contents '((0 0) (1 1) (0 2)))) (ref a e) (setf (ref a e) '(100.0 200.0 300.0)) a ;------------------------------------------------------------------------------ ; ; Here is the difference between sel and ref. Note that even if two things ; _print_ identically, they do not necessarily behave the same way. ; ; Since ref identifies a place, it works with setf. By contrast, sel copies ; to another object, so setf does not work on sel. ; a (setf b (sel a t 1)) (setf (ref b 1) 17) a a (setf b (ref a t 1)) (setf (ref b 1) 17) a
2,369
Common Lisp
.l
66
28.151515
84
0.433319
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0b124417bf10c483420126c9cd19b4975d90485dc8548d5c790635122a7368f3
33,928
[ -1 ]
33,929
benchmark.lsp
rwoldford_Quail/source/quail-kernel/test/benchmark.lsp
;;; ****************************** benchmark.lisp ********************************* (in-package :quail) (defvar *n*) (setf *n* 1000) (defvar *small-n*) (defvar *small-n1*) (setf *small-n1* 50) (defvar *small-n2*) (setf *small-n2* 0) ; upper bound is max number of open files, fix later ;---------------------------------------------------------------------------------- (defun banner (test-name) (format *quail-terminal-io* "~&~%Testing ~A for ~S iterations:~%~%" test-name *n*)) (defun banner-small (test-name) (format *quail-terminal-io* "~&~%Testing ~A for ~S iterations:~%~%" test-name *small-n*)) ;---------------------------------------------------------------------------------- (defclass foo () ((bar :accessor bar-of :initarg :bar))) (defclass foo-lish (foo) ()) (defun test-make-instance () (banner "(make-instance 'foo :bar i)") (time (loop for i from 1 to *n* do (make-instance 'foo :bar i)))) (defun test-smarter-make-instance () (banner "(make-instance {standard class FOO} :bar i)") (let ((std-class (find-class 'foo))) (time (loop for i from 1 to *n* do (make-instance std-class :bar i))))) (defun test-make-sequence-10 () (banner "(make-sequence 'list 10 :initial-element i)") (time (loop for i from 1 to *n* do (make-sequence 'list 10 :initial-element i)))) (defun test-make-sequence-100 () (banner "(make-sequence 'list 100 :initial-element i)") (time (loop for i from 1 to *n* do (make-sequence 'list 10 :initial-element i)))) (defun test-change-class () (banner "(change-class {a foo instance} 'foo-lish)") (let ((f (make-instance 'foo :bar 47))) (time (loop for i from 1 to (/ *n* 2) do (progn (change-class f 'foo-lish) (change-class f 'foo)))))) (defun test-accessor () (banner "(setf (bar-of f) i), f an instance of foo,") (let ((f (make-instance 'foo :bar pi))) (time (loop for i from 1 to *n* do (setf (bar-of f) i))))) (defmethod hand-coded-accessor ((self foo)) (slot-value self 'bar)) (defmethod (setf hand-coded-accessor) (new-value (self foo)) (setf (slot-value self 'bar) new-value)) (defun test-hand-coded-accessor () (banner "(setf (hand-coded-accessor f) i), f an instance of foo,") (let ((f (make-instance 'foo :bar pi))) (time (loop for i from 1 to *n* do (setf (hand-coded-accessor f) i))))) (test-make-sequence-10) (test-make-sequence-100) (test-make-instance) (test-smarter-make-instance) (test-change-class) (test-accessor) (test-hand-coded-accessor) ;---------------------------------------------------------------------------------- (defmethod snerd ((self t) &optional bumpf) (declare (ignore bumpf)) self) (defmethod snerd ((self array) &optional bumpf) (declare (ignore bumpf)) self) (defmethod snerd ((self foo) &optional bumpf) (declare (ignore bumpf)) self) (defun test-method-t () (banner "(snerd i i) [specialize on t]") (time (loop for i from 1 to *n* do (snerd i i)))) (defun test-method-array () (banner "(snerd an-array i)") (let ((an-array (make-array nil))) (time (loop for i from 1 to *n* do (snerd an-array i))))) (defun test-method-foo () (banner "(snerd a-foo i)") (let ((a-foo (make-instance 'foo))) (time (loop for i from 1 to *n* do (snerd a-foo i))))) (test-method-t) (test-method-array) (test-method-foo) ;---------------------------------------------------------------------------------- (defvar a) (defvar b) (defvar junk) (defun test-single-direct-eref () (banner-small "a single direct eref") (time (loop for i from 1 to *small-n* do (eref a 1 (- i i))))) (defun test-single-direct-ref () (banner-small "a single direct ref") (time (loop for i from 1 to *small-n* do (ref a 1 (- i i))))) (defun test-single-direct-sel () (banner-small "a single direct sel") (time (loop for i from 1 to *small-n* do (sel a 1 (- i i))))) (defun test-single-indirect-eref () (banner-small "a single indirect eref") (time (loop for i from 1 to *small-n* do (eref b 1 (- i i))))) (defun test-single-indirect-ref () (banner-small "a single indirect ref") (time (loop for i from 1 to *small-n* do (ref b 1 (- i i))))) (defun test-single-indirect-sel () (banner-small "a single indirect sel") (time (loop for i from 1 to *small-n* do (sel b 1 (- i i))))) (defun test-submatrix-direct-ref () (banner-small "a submatrix direct ref") (time (loop for i from 1 to *small-n* do (ref a '(0 1) (- i i))))) (defun test-submatrix-direct-sel () (banner-small "a submatrix direct sel") (time (loop for i from 1 to *small-n* do (sel a '(0 1) (- i i))))) (defun test-submatrix-indirect-ref () (banner-small "a submatrix indirect ref") (time (loop for i from 1 to *small-n* do (ref b '(0 1) (- i i))))) (defun test-submatrix-indirect-sel () (banner-small "a submatrix indirect sel") (time (loop for i from 1 to *small-n* do (sel b '(0 1) (- i i))))) (defun do-the-ref-tests () (test-single-direct-eref) (test-single-direct-ref) (test-single-direct-sel) (test-single-indirect-eref) (test-single-indirect-ref) (test-single-indirect-sel) (test-submatrix-direct-ref) (test-submatrix-direct-sel) (test-submatrix-indirect-ref) (test-submatrix-indirect-sel)) (setf *small-n* *small-n1*) (format *quail-terminal-io* "~&~%**** Do eref, ref, and sel tests ~ for class num-array, ~S iterations ****~%~%" *small-n*) (setf a (array '(2 3) :initial-contents '((1.2 3.4 5.6) (7.8 9.1 2.3)))) (setf b (ref a '(0 1) '(0 2))) ; create an indirect ref, warming up ref. (setf junk (sel a '(0 1) '(0 2))) ; warm up sel as well ... (do-the-ref-tests) (setf *small-n* *small-n2*) (format *quail-terminal-io* "~&~%**** Do eref, ref, and sel tests ~ for class num-array, ~S iterations ****~%~%" *small-n*) (setf a (array '(2 3) :initial-contents '((1.2 3.4 5.6) (7.8 9.1 2.3)))) (setf b (ref a '(0 1) '(0 2))) ; create an indirect ref, warming up ref. (setf junk (sel a '(0 1) '(0 2))) ; warm up sel as well ... (do-the-ref-tests) #| (format *quail-terminal-io* "~&~%**** Do eref, ref, and sel tests ~ for class file-matrix, ~S iterations ****~%~%" *small-n*) (setf a (array '(2 3) :class 'file-matrix :initial-element pi)) (setf b (ref a '(0 1) '(0 2))) ; create an indirect ref, warming up ref. (setf junk (sel a '(0 1) '(0 2))) ; warm up sel as well ... (do-the-ref-tests) |# ;---------------------------------------------------------------------------------- (setf *small-n* *small-n1*) (defun expander (cols-in-a b) (cglue-replicates cols-in-a b)) (defun test-expander () (let ((b (array '(7) :initial-element 3.14)) (cols-in-a 10)) (banner-small "expander") (time (loop for i from 0 to *small-n* do (expander cols-in-a b)))))
7,516
Common Lisp
.l
183
34.590164
92
0.540838
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4b033b0cafa5bbf8840ea15b3162ad7b8f799cadfbc78ef67978b2b52a2fc3fb
33,929
[ -1 ]
33,930
test-scan.lsp
rwoldford_Quail/source/quail-kernel/test/test-scan.lsp
;********************************* test-scan.lisp **************************** (scan-reset "ccl;Z I/O:test.io") (setf a (array '(3 2) :type :quail :initial-contents :scan)) (setf b (array '(3 2) :type :quail :initial-contents :scan)) (setf c (array '(3 2) :type :quail :initial-contents :scan)) (quit)
316
Common Lisp
.l
6
49.333333
79
0.521595
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f130f72c173f021a62a9c5a2d6679e40a1e5975b359613f42b957072afce3aa1
33,930
[ -1 ]
33,931
test-with-open.lsp
rwoldford_Quail/source/quail-kernel/test/test-with-open.lsp
(in-package :quail-kernel) (setf a (z::array '(3) :initial-contents '(0 1 2))) (defclass foo (quail-object quail-open-mixin) ()) (defmethod quail-open-object ((self foo)) ) (defmethod quail-close-preserve-object ((self foo)) ) (defmethod quail-close-destroy-object ((self foo)) ) (defmethod quail-close-physically-object ((self foo)) ) (setf b (make-instance 'foo)) (defun foop (x) (typep x 'foo)) (pprint (macroexpand '(with-open-quail-objects (a b :temp c d) #'foop (setf d (make-instance 'foo)) (quail-print (setf c (tp a))) (describe b) 14))) (with-open-quail-objects (a b :temp c d) #'foop (setf d (make-instance 'foo)) (quail-print (setf c (tp a))) (describe b) 14) (pprint (macroexpand '(with-open-quail-objects (x :temp z) #'foop (Q+ x (setf z (Q* 3 y)))))) (defun try-it (x y) (with-open-quail-objects (x :temp z) #'foop (Q+ x (setf z (Q* 3 y))))) (pprint (macroexpand '(with-open-quail-objects (self :keep result) #'quail-pred1 (with-slots (stream) self (file-position stream index) (setf result (read stream)) result)))) (pprint (macroexpand '(with-open-quail-objects nil nil nil))) (pprint (macroexpand '(with-open-quail-objects (a :list b c :temp d) #'pred (body))))
1,400
Common Lisp
.l
37
30.891892
85
0.598348
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e726ea7b29c87a99d0bf6f014bb0e0121e417e919be49de71c1116e065b32809
33,931
[ -1 ]
33,932
quail-kernel-system-pc.lsp
rwoldford_Quail/source/quail-kernel/test/quail-kernel-system-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; quail-kernel-system-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; Authors: ;;; Greg Anglin 1990, 1991. ;;; Simply copied by G.W. Bennett 1997 ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (defun system-get-pointer (x) 0)
555
Common Lisp
.l
11
48.272727
84
0.332721
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
593c68770af3489b12f5156f6020f835b4d2cd1e92acfbfe8ebec2b283649d1e
33,932
[ -1 ]
33,933
test-bounds.lsp
rwoldford_Quail/source/quail-kernel/test/test-bounds.lsp
;;; ******************* test-arrays.lisp *********************************** (in-package :quail) (load "ccl;Z:zffi-load.lisp") ;------------------------------------------------------------------------------ (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) (setf b (array '(2 3) 'f-real*8 :type :f :language :fortran :initial-contents a)) ;-------------------------------------------------------------------------------- (setf (bounds-checking b) nil) (eref b 0 0) (eref b 2 3) (eref b -1 2) ; oops (eref b -1 -2) (eref b 4 0) ; oops (setf (bounds-checking b) t) (eref b 0 0) (eref b 2 3) (eref b -1 2) (eref b -1 -2) (eref b 4 0)
847
Common Lisp
.l
22
30.136364
82
0.328698
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
64ad9eb4907037a0231079ccec2aec9b73cc79e33e29e4f21f8d41a60b685e45
33,933
[ -1 ]
33,934
test-file-matrix.lsp
rwoldford_Quail/source/quail-kernel/test/test-file-matrix.lsp
;;; ************************** test-file-matrix.lisp ********************************* (setf f (array '(5 3) :class 'file-matrix :file "test1" :initial-element 5)) (setf g (ref f t '(1 2))) (describe g) (setf h (sel f t '(1 2))) (setf ff (array '(5 5) :class 'file-matrix :file "test2" :initial-element 3)) ;------------------------------------------------------------------------------------- #| (scan-reset "test1.fmat") (setf new-f (array '(10 3) :class 'file-matrix :file "test3" :initial-contents :scan)) |#
540
Common Lisp
.l
11
45.636364
87
0.450292
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a22dfbccb21cea18285ed314483f611a11a5f56c7f99b8a2ce6fbcc4b6d900d4
33,934
[ -1 ]
33,935
test-glue.lsp
rwoldford_Quail/source/quail-kernel/test/test-glue.lsp
;;; ****************************** test-glue.lisp ***************************** (in-package :quail-user) (setf a (array '(2 3) :initial-contents '((1.2 3 4.5) (6.7 8.9 0.1)))) ;------------------------------------------------------------------------------ (setf cc (vector 100 200)) (cglue a cc) (cglue 1 2 3) (rglue 1 2 3) (rglue '(1 2) cc) (cglue '(1 2) cc) (rglue '(1 2) cc :1d :col) (cglue '(1 2) cc :1d :row)
477
Common Lisp
.l
13
30.846154
80
0.342105
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fa413f23e62d5a4d429b3dc4133d969aecf708698ca69e9f81f1cfc240239bd7
33,935
[ -1 ]
33,936
setf-ref.lsp
rwoldford_Quail/source/quail-kernel/ref/setf-ref.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; setf-ref.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; setf-ref-kernel ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*setf-ref* setf-ref-kernel))) ;-------------------------------------------------------------------------------- (defgeneric (setf ref) (new-value r &rest specifiers) (:documentation "Puts new-value in place (ref r specifiers). new-value must be an object ~ itself accepted by ref (although not necessarily of the same class as r), ~ and be dimensioned appropriately for specifiers. (setf ref) DOES NOT ~ accept :shape in the ref portion of the form. ~ new-value is returned by all (setf ref) methods.") ) ;-------------------------------------------------------------------------------- ;;; This code allows us to do (apply #'(setf ref) ...) using the expression ;;; (apply *setf-ref* ...) (defvar *setf-ref*) (setf *setf-ref* #+:cl-2 #'(setf ref) #-:cl-2 #'pcl::setf\ quail-kernel\ ref) ;-------------------------------------------------------------------------------- ;;; ; Kernel functions required by the (setf ref) defmethods. ; (defgeneric setf-ref-kernel (new-value targ) ) ; ; (setf-ref-kernel new-value target) is required for same reason as ref-kernel. ; ; ; May have problems with something like ; ; (setf (ref a ...) (ref a ...)). ; ; Should deal with this by doing copy-ref first on new-value if the ultimate ; ref-object is the same for new-value and r. ; (defmethod setf-ref-kernel (new-value (targ t)) (missing-method 'setf-ref-kernel new-value targ)) (defmethod setf-ref-kernel (new-value (targ dimensioned-ref-object)) (declare (special *setf-eref*)) (let* ((targ-dim (dimensions-of targ)) (src-dim (dimensions-of new-value))) (multiple-value-bind (conformable dim targ-mask src-mask) (conform targ-dim src-dim) (if (not conformable) (quail-error "Referenced portion of object ~S has dimensions ~S, ~ ~&but new value ~S provided has dimensions ~S." targ targ-dim new-value src-dim)) (let* ((num-dims (length dim)) (current (make-sequence 'list num-dims :initial-element 0)) index) (loop for d from 0 to (- (apply #'* dim) 1) do (progn (setf index (list-if-t current targ-mask)) (apply *setf-eref* (apply #'eref-mask new-value (append current (list :mask src-mask))) targ index) (setf current (row-major-next-subscript current dim))))))) new-value) ;-------------------------------------------------------------------------------- ;;; ; DEFMETHODs of (setf ref) ; (defmethod (setf ref) (new-value (self sequence) &rest specifiers) (setf-ref-kernel new-value (apply #'ref self specifiers))) (defmethod (setf ref) (new-value (self array) &rest specifiers) (setf-ref-kernel new-value (apply #'ref self specifiers))) (defmethod (setf ref) (new-value (self dimensioned-ref-object) &rest specifiers) (setf-ref-kernel new-value (apply #'ref self specifiers)))
3,959
Common Lisp
.l
96
33.270833
95
0.484436
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8b2cff1aab30ba93930a5dc099d4516b4ffe4cd031d8259fe51b34a3a7a59c88
33,936
[ -1 ]
33,937
indices.lsp
rwoldford_Quail/source/quail-kernel/ref/indices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; indices.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Bob White ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(indices))) (defgeneric indices (object predicate) (:documentation "Applies the predicate to each element of object and returns the ~ index of those elements which return T. These are returned in an ~ array which may in turn be passed as the index argument to ref. ~ If no elements satisfy the predicate then NIL is returned.")) ;; should really do multiple methods for cases we can handle, but ;; good enough for now ... (defmethod indices (object predicate) (let* ((dim (dimensions-of object)) (current (make-list (length dim) :initial-element 0)) (contents (loop for i from 1 to (number-of-elements object) append (prog1 (if (funcall predicate (apply #'eref object current)) (list (copy-list current))) (row-major-next-subscript current dim))))) (if contents (array contents :class 'ref-array :dimensions (list (length contents))))))
1,639
Common Lisp
.l
40
32.925
80
0.494014
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c49e840b9a679fd94aec48ab85264cbdb2c186509e5b00a9b27eec2e72f4c893
33,937
[ -1 ]
33,938
ref-eq.lsp
rwoldford_Quail/source/quail-kernel/ref/ref-eq.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ref-eq.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :qk) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(ref-eq))) (defgeneric ref-eq (x y)) (defmethod ref-eq ((x t) (y t)) (eq x y)) (defmethod ref-eq ((x dimensioned-ref-object) (y dimensioned-ref-object)) (or (call-next-method x y) (and (eq (ref-obj-of x) (ref-obj-of y)) (equal (specs-mask-of x) (specs-mask-of y)) (let ((xs (specs-of x)) (ys (specs-of y))) (or (equal xs ys) (specs-the-same-p xs ys (dimensions-of (ref-obj-of x)))))))) ;;; Does this work when it's supposed to? (defmethod ref-eq ((x quail-open-mixin) (y quail-open-mixin)) (and (not (quail-open-p-object x)) (not (quail-open-p-object y)) (call-next-method x y))) ;;; What this really needs to do is carefully analyze the specs and ;;; determine whether they look at the same part of the (shared) ;;; ref-object of x and y. This'll be a real problem if the specs ;;; of either x or y is not a list ... for now this case returns nil. ;;; ;;; takes xs = specs of x ;;; ys = specs of y ;;; d = dimensions of shared ref-object ;;; ;;; One can modify specs of x or y before passing to this routine if ;;; desired (eg. sort and remove duplicates, to check if same stuff is ;;; referred to, but maybe somewhat differently in each object) (defun specs-the-same-p (xs ys d) (and (listp xs) (listp ys) (let ((the-same t)) (loop for xi in xs as yi in ys as di in d while the-same do (setf the-same (or (eq xi yi) (and (listp xi) (listp yi) (equal xi yi)) (let ((xii (cond ((eq xi t) (iseq di)) ((numberp xi) (list xi)) ((and (listp xi) (eq (first xi) :c)) (set-difference (iseq di) (cdr xi) :test #'=)) (T xi))) (yii (cond ((eq yi t) (iseq di)) ((numberp yi) (list yi)) ((and (listp yi) (eq (first yi) :c)) (set-difference (iseq di) (cdr yi) :test #'=)) (T yi)))) (equal xii yii))))) the-same)))
3,532
Common Lisp
.l
82
26.52439
84
0.368266
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
62acfd007dc7e7d1423fbbcc4f4f4fe1bbb00bb99598d6daf04dc9d0cff8075b
33,938
[ -1 ]
33,939
row-major-ops.lsp
rwoldford_Quail/source/quail-kernel/ref/row-major-ops.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; row-major-ops.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(row-major-eref row-major-list-elements row-major-set-elements row-major-ref-slice))) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-eref ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (subscripts nil) (index nil) (result nil)) (defun row-major-eref (a i) "Returns the i-th element of the argument a, counting by row major order. ~ It can be used with setf to set elements of its argument.~ (:required ~ (:arg A The object whose i'th element is to be returned.) ~ (:arg i The row major index of the element to be returned.) ~ )~ (:see-also column-major-eref row-major-ref-slice)" (if (eq a array) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts dimensions :row))) ( 0 result) ( 1 (setf subscripts (next-subscripts subscripts dimensions :row))) ( t (setf subscripts (index-to-subscripts i dimensions :row)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf subscripts (index-to-subscripts i dimensions :row)))) (setf index i) (setf result (apply #'eref a subscripts)) result)) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-eset ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (subscripts nil) (index nil) (result nil)) (defun row-major-eset (a i new-value) "Sets the value of the i-th element of the argument a, ~ counting by row major order." (declare (special *setf-eref*)) (if (eq a array) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts dimensions :row))) ( 0 result) ( 1 (setf subscripts (next-subscripts subscripts dimensions :row))) ( t (setf subscripts (index-to-subscripts i dimensions :row)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf subscripts (index-to-subscripts i dimensions :row)))) (setf index i) (setf result (apply *setf-eref* new-value a subscripts)) result)) ;;;-------------------------------------------------------------------------------- ;;; row-major-eref setf macro ;;;-------------------------------------------------------------------------------- (defsetf row-major-eref row-major-eset) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-list-elements ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (defun row-major-list-elements (object) "Returns a list containing all elements of the object in row major order.~ (:see-also row-major-set-elements row-major-eref row-major-ref-slice ~ column-major-list-elements)" (do ((counter (- (number-of-elements object) 1) (- counter 1)) (result nil (push (row-major-eref object counter) result))) ((minusp counter) result) ())) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-set-elements ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (defun row-major-set-elements (object list) "Sets the elements in object to that of list, iterating over object's ~ elements in row-major-order.~ (:see-also row-major-list-elements row-major-eref row-major-ref-slice ~ column-major-set-elements)" (dotimes (counter (number-of-elements object) object) (setf (row-major-eref object counter) (elt list counter)))) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-ref-slice ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (f-slices nil) (r-slices nil) (f-dims nil) (subscripts nil) (index nil) (result nil)) (defun row-major-ref-slice (a slices i) "Returns the i-th slice of the refable object a, indexing by row major order. ~ Like row-major-eref in this way except that slices of a can be identified as ~ fixed by giving a list of their dimension numbers as the slices argument.~ It can be used with setf to set slices to new values.~ (:required ~ (:arg A The object whose i'th slice is to be returned.) ~ (:arg slices The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of A having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of A. ~ Similarly, if slices is '(0 1) then a slice of A is the set of all elements ~ of A having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the object a is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them. In this special ~ case, row-major-ref-slice is identical to row-major-eref)~ (:arg i The row major index of the slice to be returned.) ~ )~ (:see-also row-major-eref column-major-ref-slice)" (cond ((eq :elements slices) ;; Treat elements as slices (row-major-eref a i)) ((null slices) ;;(or (null slices) ;; (and (= (length slices) 1) ;; (null (first slices)))) ;; if no slices are fixed just do a row-major-eref (ref a)) (t (if (and (eq a array) (equal slices f-slices)) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts f-dims :row))) ( 0 result) ( 1 (setf subscripts (next-subscripts subscripts f-dims :row))) ( t (setf subscripts (index-to-subscripts i f-dims :row)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf f-slices (cl:sort (remove-duplicates slices) #'cl:<)) (setf r-slices (row-major-list-elements (ref (iseq (length dimensions)) (cons :c f-slices) ))) (setf f-dims (row-major-list-elements (ref dimensions f-slices ))) (setf subscripts (index-to-subscripts i f-dims :row)))) (setf index i) (setf result (apply #'ref a (expand-subscripts subscripts r-slices))) result) )) ) ;;;--------------------------------------------------------------------------- ;;; ;;; Row-major-set-slice ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (f-slices nil) (r-slices nil) (f-dims nil) (subscripts nil) (index nil)) (defun row-major-set-slice (a slices i new-value) "Sets the i-th element of the refable object a, counting by row major order. ~ Like row-major-eset in this way except that slices of a can be identified as ~ fixed by giving their dimension number (0, 1, 2, ...) as further arguments." (cond ((eq :elements slices) ;; Treat elements as slices (setf (row-major-eref a i) new-value)) ((null slices) ;;(or (null slices) ;; (and (= (length slices) 1) ;; (null (first slices)))) ;; if no slices are fixed just do a row-major-eref (setf (ref a) new-value)) (t (if (and (eq a array) (equal slices f-slices)) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts f-dims :row))) ( 1 (setf subscripts (next-subscripts subscripts f-dims :row))) ( t (setf subscripts (index-to-subscripts i f-dims :row)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf f-slices (cl:sort (remove-duplicates slices) #'cl:<)) (setf r-slices (row-major-list-elements (ref (iseq (length dimensions)) (cons :c f-slices) ))) (setf f-dims (row-major-list-elements (ref dimensions f-slices ))) (setf subscripts (index-to-subscripts i f-dims :row)))) (setf index i) (apply *setf-ref* new-value a (expand-subscripts subscripts r-slices)))))) ;;;-------------------------------------------------------------------------------- ;;; row-major-ref-slice setf macro ;;;-------------------------------------------------------------------------------- (defsetf row-major-ref-slice row-major-set-slice)
10,684
Common Lisp
.l
271
30.509225
85
0.475717
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
25678af5ab2c72b70cbfc952120ee50ab9e12c39db514ea0ea7dd4287b83c740
33,939
[ -1 ]
33,940
subscript-utility.lsp
rwoldford_Quail/source/quail-kernel/ref/subscript-utility.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; subscript-utility.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defun next-subscripts (subscripts dimensions order) "Returns the subscripts of the next element, ~ in row or column major order." (ecase order (:row (reverse (next-subscripts (reverse subscripts) (reverse dimensions) :col))) (:col (cond ((null subscripts) nil) (t (if (< (car subscripts) (- (car dimensions) 1)) (cons (+ (car subscripts) 1) (cdr subscripts)) (cons 0 (next-subscripts (cdr subscripts) (cdr dimensions) order)))))))) (defun prior-subscripts (subscripts dimensions order) "Returns the subscripts of the prior element, ~ in row or column major order." (ecase order (:row (reverse (prior-subscripts (reverse subscripts) (reverse dimensions) :col))) (:col (cond ((null subscripts) nil) (t (if (> (car subscripts) 0) (cons (- (car subscripts) 1) (cdr subscripts)) (cons (- (car dimensions) 1) (prior-subscripts (cdr subscripts) (cdr dimensions) order)))))))) (defun index-to-subscripts (index dimensions order) "Returns the subscripts of the element at location index, ~ counting in row or column major order." (labels ((f (index dimensions-product) (cond ((null dimensions-product) nil) ((= (length dimensions-product) 1) (list index)) (t (multiple-value-bind (quotient remainder) (floor index (car dimensions-product)) (cons quotient (f remainder (cdr dimensions-product)))))))) (ecase order (:col (reverse (index-to-subscripts index (reverse dimensions) :row))) (:row (cdr (f index (cum-prod dimensions))))))) (defun cum-prod (seq) "Running cumulative products." (labels ((f (seq result) (cond ((null seq) result) ((null result) (f (cdr seq) (list (car seq) 1))) (t (f (cdr seq) (cons (* (car seq) (car result)) result)))))) (f (reverse seq) nil))) (defun expand-subscripts (subscripts f-slices &optional (counter 0)) (cond ((and (null subscripts) (null f-slices)) NIL) ((null f-slices) subscripts) ((null subscripts) (make-list (length f-slices) :initial-element T)) ((= counter (car f-slices)) (cons T (expand-subscripts subscripts (cdr f-slices) (+ counter 1)))) (t (cons (car subscripts) (expand-subscripts (cdr subscripts) f-slices (+ counter 1))))))
3,704
Common Lisp
.l
89
28.629213
84
0.458693
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
910482ed7b0516488e1aac579945c0c52a9d3b19af2803588d947e0da9e7784a
33,940
[ -1 ]
33,941
number-of-slices.lsp
rwoldford_Quail/source/quail-kernel/ref/number-of-slices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; number-of-slices.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994 ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(number-of-slices))) (defgeneric number-of-slices (object slices) (:documentation "The number of slices in object. ~ (:required ~ (:arg object The object whose number of slices are to be determined.) ~ (:arg slices The list of fixed dimensions that identify each slice.~ This should be an index or list of indices that identifies ~ where in the object the positions are to be determined. For example if slices ~ is 0 then a slice is defined to be the set of all elements having a common ~ value of the zeroth index. ~ Slices may also be the keyword :elements in which case number-of-slices ~ is identical to number-of-elements,)~ ) ~ (:see-also number-of-elements number-of-dimensions)~ ")) (defmethod number-of-slices (object slices) (missing-method 'number-of-slices object slices)) (defmethod number-of-slices ((object symbol) slices) (declare (ignorable object slices)) ;(declare (ignore object slices)) 25JUL2023 1) (defmethod number-of-slices ((object number) slices) (declare (ignorable object slices)) ;(declare (ignore object slices)) 25JUL2023 1) (defmethod number-of-slices ((object T) (slices null)) (declare (ignorable object slices)) ;(declare (ignore object slices)) 25JUL2023 1) (defmethod number-of-slices :around ((object T) (slices list)) (if slices (if (or (>= (apply #'max slices) (number-of-dimensions object)) (< (apply #'min slices) 0)) (quail-error "~&Slices ~s are invalid ~%~ for ~s having dimensions: ~s." slices object (dimensions-of object)) (call-next-method)) (call-next-method))) (defmethod-multi number-of-slices ((object (sequence dimensioned-ref-object array)) (slices list)) (let ((dimensions (dimensions-of object))) (cond ((or (null dimensions) (null slices)) 1) (t (let ((product 1)) (loop for index in slices do (setf product (* product (elt dimensions index)))) product))))) (defmethod-multi number-of-slices ((object (T sequence dimensioned-ref-object array)) (slices (eql :elements))) (number-of-elements object)) (defmethod-multi number-of-slices ((object (sequence dimensioned-ref-object array)) (slices number)) (number-of-slices object (list slices)))
3,122
Common Lisp
.l
69
37.463768
87
0.569449
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6faca1b340f2fa799a91e2e3920773faa7e5d58dd534e863f72439bc8b4f8b08
33,941
[ -1 ]
33,942
sel.lsp
rwoldford_Quail/source/quail-kernel/ref/sel.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; sel.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; sel ;;; copy-ref ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(sel))) ;-------------------------------------------------------------------------------- ;;; ; Utility functions required by the sel defmethods ; (some others in eref.lisp). ; (defun copy-ref (ref-r) (let* ((proto (ref-obj-of ref-r))) ;; only used to find proper class (copy-dispatch proto ref-r))) ;-------------------------------------------------------------------------------- ;;; ; DEFGENERIC of sel ; (defgeneric sel (r &rest args) (:documentation "Sel is identical to ref except that it makes ~ and returns a copy of the referenced structure of r ~ as opposed to a reference to the r. ~ (:see-also ref eref) ~ ") ) ;;; ; DEFMETHODs of sel ; (defmethod sel ((self dimensioned-ref-object) &rest args) (if (indirect-ref-p self) (let* ((ref-self (ref-instantiate self))) (ref-kernel ref-self self args) ;; changes ref-self !! (copy-ref ref-self)) (missing-method 'sel self))) (defmethod sel ((self character) &rest args) (declare (ignore args)) self) (defmethod sel ((self number) &rest args) (declare (ignore args)) self) (defmethod sel ((self symbol) &rest args) (declare (ignore args)) self) (defmethod sel ((self sequence) &rest args) (let* ((ref-self (ref-instantiate self))) (ref-kernel ref-self self args) ;; changes ref-self !! (copy-ref ref-self))) ;;; array also handles string case (defmethod sel ((self array) &rest args) (let* ((ref-self (ref-instantiate self))) (ref-kernel ref-self self args) ;; changes ref-self !! (copy-ref ref-self))) ;------------------------------------------------------------------------------- ;;; ; DEFGENERIC of (setf sel) ; (defgeneric (setf sel) (new-value r &rest args)) ;;; ; DEFMETHOD of (setf sel) ; (defmethod (setf sel) (new-value (self t) &rest args) (apply *setf-ref* new-value self args))
2,726
Common Lisp
.l
78
30.192308
84
0.465848
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c5246fb70b28a0fd5d576577f3e5afce9b05c07c01a84170ec29b9d7f7ac7b6d
33,942
[ -1 ]
33,943
ref.lsp
rwoldford_Quail/source/quail-kernel/ref/ref.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ref.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1991, 1993. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; ref ;;; ref-kernel ;;; ref-list ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(ref ref-instantiate ref-kernel ind))) ;-------------------------------------------------------------------------------- ;;; ; Utility functions for ref methods ; ; ; ref-true-args ; allows objects (esp. with dimensions-rank < 2) to be ref'd with extraneous args, ; if the extraneous args are some sensible use of 0, '(0), T, or '(:C). ; If the object is direct-ref and 1-dimensional (defvar *true-args-maskable* (list 0 '(0) T '(:c))) (defun ref-err (r args) (quail-error "Improper arguments ~S provided to REF for object ~S ~ with dimensions ~S." args r (dimensions-of r))) ;; this method is only called when dim-rank-r < dim-rank-args. ;; If dim-rank-r = 1, then must have dim-rank-args = 2 (column vs row discrimination) (defun ref-true-args (r args dim-rank-r dim-rank-args) (declare (special *true-args-maskable*)) (let ((true-args (cond ((and (= dim-rank-args 2) (= dim-rank-r 1)) (if (member (second args) *true-args-maskable* :test #'equal) (list (first args)) :err)) ((= dim-rank-r 0) (if (find-if-not #'(lambda (arg) (member arg *true-args-maskable* :test #'equal)) args) :err)) (t :err)))) (if (eq :err true-args) (ref-err r args)) true-args)) ;;; ; DEFGENERIC of ref ; #| ;; I thought this was too obscure too leave on the doc string for now ... dga 93 03 "ref is called as if it had lambda list (r &rest specifiers &key shape), ~ except that the keys do not get included in specifiers, and specifiers do not ~ get processed as keys (in other words, this works as it intuitively would, ~ whereas the Common Lisp specification does something quite different ... CLtL p61). ~ ~ Returns an object with same class as r ~ which is built according to specifiers. All formats for specifiers ~ have not yet (89 12 01) been determined. Proposed classes for r include ~ sequences, arrays, ref-arrays (including foreign-arrays). ~ All such classes must have eref and ~ dimensions-of methods." |# (defgeneric ref (r &rest args) (:documentation "Returns a reference to the object r. Dimensions and contents are ~ determined by the remaining arguments. ~ If a copy is desired instead, use sel. See examples file for usage. ~ (:see-also sel eref row-major-ops) ~ " ) ) ;-------------------------------------------------------------------------------- ;;; ; Kernel functions required by the ref defmethods. ; (defgeneric ref-instantiate (r) (:documentation "Makes an instance of some subclass of ref-object, to eventually be returned ~ by ref. Which class is created depends on the class of r." )) (defmethod ref-instantiate ((self dimensioned-ref-object)) (make-instance (class-of self) :proto self)) #| ;-------------------------------------------------------------------------- ; Should probably change ref-instantiate for dimensioned-ref-object ; to calculate return-class (not automatically use class of ; referenced object). ;-------------------------------------------------------------------------- (defmethod ref-instantiate ((self dimensioned-ref-object)) (make-instance (get-return-class self self) ;; semantics not quite right :proto self)) |# (defmethod ref-instantiate ((self number)) self) (defmethod ref-instantiate ((self symbol)) self) (defmethod ref-instantiate ((self sequence)) (make-dimensioned-ref-object)) ;;; array also handles the string case (defmethod ref-instantiate ((self array)) (make-dimensioned-ref-object)) ;-------------------------------------------------------------------------- (defgeneric ref-kernel (ref-r r args) (:documentation "Does the guts of the ref computations. ref-r is an instance which was ~ created by calling ref-instantiate on r.") ) (defmethod ref-kernel ((ref-r t) r args) (missing-method 'ref-kernel ref-r r args)) (defmethod ref-kernel ((ref-r dimensioned-ref-object) r args) (multiple-value-bind (specifiers shape) (interpret args '(:shape)) (if (margin-specs-p (first specifiers)) (ref-by-margin ref-r r specifiers shape) (ref-by-indices ref-r r specifiers shape))) ref-r) (defun ref-by-margin (ref-r r specifiers shape) (if (direct-ref-p r) ;; ;; simplest case; just stuff the info into an indirect ;; ref-object. ;; (let* ((specs (expand-margin-specs r specifiers)) (dim (compute-margin-dim (dimensions-of r) specs))) (finish-ref ref-r r dim shape specs)) ; --> margin ;; ;; Here r is an indirect-ref, so we want to figure out how ;; to configure a new indirect-ref which refers to the same ;; direct ref-obj as r, namely, (ref-obj-of r). ;; (let* ((r-specs (specs-of r)) (r-mask (specs-mask-of r))) (if (margin-specs-p r-specs) ;; ;; Here r is a margin-ref, and so will be our ;; returned ref-object. Its ref-obj will be (ref-obj-of r). ;; Hence we need to refer back to the dimensions of (ref-obj-of r), ;; using the (specs-mask-of r) to lengthen the expanded specs ;; to (length (dimensions-of (ref-obj-of r))). Then do ;; margin-of-margin, which does not require any knowledge of ;; dimensions. In fact, we cannot calculate the final dimensions ;; until we have the result of margin-of-margin !! ;; (let* ((temp-specs (expand-margin-specs r specifiers)) (specs (margin-of-margin temp-specs r)) (dim (compute-margin-dim (dimensions-of (ref-obj-of r)) specs))) (finish-ref ref-r (ref-obj-of r) dim shape specs r-mask)) ; --> margin ;; ;; Otherwise r is an indices-ref, and so will be ;; our returned ref-object. Its ref-object will be (ref-obj-of r). ;; Here we are really just doing a margin sel on r-specs; so, we use ;; (dimensions-of r) in compute-margin-dim. ;; (let* ((temp-specs (expand-margin-specs r specifiers)) (specs (margin-of-indices temp-specs r)) (dim (array-dimensions specs))) (finish-ref ref-r (ref-obj-of r) dim shape specs)))))) ; --> indices (defun ref-by-indices (ref-r r specifiers shape) (if (direct-ref-p r) ;; ;; simplest case; just stuff the info into an indirect ;; ref-object. ;; (let* ((specs (indices-array (first specifiers))) (dim (array-dimensions specs))) (finish-ref ref-r r dim shape specs)) ; --> indices ;; ;; Here r is an indirect-ref, so we want to figure out how ;; to configure a new indirect-ref which refers to the same ;; direct ref-obj as r, namely, (ref-obj-of r). ;; (let* ((r-specs (specs-of r)) (temp-specs (indices-array (first specifiers))) (dim (array-dimensions temp-specs)) (specs (if (margin-specs-p r-specs) (indices-of-margin temp-specs r) (indices-of-indices temp-specs r)))) (finish-ref ref-r (ref-obj-of r) dim shape specs)))) ; --> indices (defun finish-ref (ref-r ref-obj dim shape specs &optional (r-mask nil)) (let* ((mask (get-mask dim shape r-mask)) (dim (list-if-t dim mask))) #+:debug-ref (progn (format *quail-debug-io* "~&dimensions ~S" (setf (dimensions-of ref-r) dim)) (format *quail-debug-io* "~&specs-mask ~S" (setf (specs-mask-of ref-r) mask)) (format *quail-debug-io* "~&ref-obj ~S" (setf (ref-obj-of ref-r) ref-obj)) (format *quail-debug-io* "~&specs ~S" (setf (specs-of ref-r) specs)) (describe ref-r)) (setf (dimensions-of ref-r) dim) (setf (specs-mask-of ref-r) mask) (setf (ref-obj-of ref-r) ref-obj) (setf (specs-of ref-r) specs)) ref-r) ; useful when debugging to return this ;-------------------------------------------------------------------------------- ;;; ; Utility functions required by ref ; ; ; margin-of-margin ... ; (defun margin-of-margin (new-specs r) (loop for margin-old in (specs-of r) as margin-new in new-specs collect (cond ((eq margin-old t) margin-new) ((eq margin-new t) margin-old) ((eq :c (first margin-old)) (if (eq :c (first margin-new)) (complement-complement margin-old margin-new) (complement-index margin-old margin-new))) ((eq :c (first margin-new)) (index-complement margin-old margin-new)) (t (index-index margin-old margin-new))))) (defun index-index (old-list new-list) (loop for i in new-list collect (elt old-list i))) (defun index-complement (old-list new-list) (let ((return-list '())) (loop for comp-i in (cdr new-list) with index = 0 do (setf return-list (append return-list (subseq old-list index comp-i))) (setf index (+ comp-i 1)) finally (setf return-list (append return-list (subseq old-list index)))) return-list)) (defun complement-index (old-list new) (let* ((new-list (copy-list new))) (loop for index in new-list with comp-list = (cdr old-list) collect (or (loop for comp-i in comp-list do (cond ((< index comp-i) (return index)) (T (incf index)))) index)))) (defun complement-complement (old new) (let* ((old-list (copy-list old)) (new-list (copy-list new)) (additional-comps (loop for new-comp-i in (cdr new-list) with old-comps = (cdr old-list) collect (or (loop for old-comp-i in old-comps do (cond ((< new-comp-i old-comp-i) (return new-comp-i)) (T (incf new-comp-i)))) new-comp-i)))) (append '(:c) (merge 'list (cdr old-list) additional-comps #'<)))) ; ; indices-of-margin ; (defun indices-of-margin (new-specs r) ;; destroys new-specs !! (let ((old-specs (specs-of r)) (old-mask (specs-mask-of r))) (loop for i from 0 to (- (number-of-elements new-specs) 1) do (column-major-eset new-specs i (eref-transform-of-margin (expand-list (eref-true-index r (column-major-eref new-specs i)) old-mask 0) old-specs)))) new-specs) ; ; margin-of-indices ; #| (defun margin-of-indices (new-specs r) ;; a little computationally expensive, but easy. (apply #'sel (specs-of r) new-specs)) |# (defun margin-of-indices (new-specs r) ;; conceptually (apply #'sel (specs-of r) new-specs) (let* ((old-specs (specs-of r)) (old-dim (array-dimensions old-specs)) (dim (compute-margin-dim old-dim new-specs)) (specs (make-array dim))) (copy-kernel old-specs specs new-specs (make-list (length old-dim) :initial-element t)) specs)) ; ; indices-of-indices ; (defun indices-of-indices (new-specs r) ;; destroys new-specs !! (let ((old-specs (specs-of r)) (old-mask (specs-mask-of r))) (loop for i from 0 to (- (number-of-elements new-specs) 1) do (column-major-eset new-specs i (eref-transform-of-indices (expand-list (eref-true-index r (column-major-eref new-specs i)) old-mask 0) old-specs)))) new-specs) ; ; expand-margin-specs does the following to specs: ; ; 1. if specs are longer than (dimensions-of r), ; appends '(t) to the end of specs enough times so that the length of ; specs is the number of dimensions of r ; OR uses ; OR uses ref-true-args to reduce the length of specs to number of dims of r #| This has been removed to 'fix' a bug ... dga & rwo 91 11 29 ; 2. When r is indirect-ref-p and a ref-margin, all occurrences of t are ; changed to the corresponding element of the (specs-of r) reduced by ; by taking only those for which (specs-mask-of r) are t. |# ; 3. if an element of specs is a single number n, it gets changed to (list n). ; 4. if an element of specs is a list beginning with :c, the rest of the list ; is sorted into ascending order. ; (defun expand-margin-specs (r specs) (let* ((dim (dimensions-of r)) (len-dim (length dim)) (len-spec (length specs)) (indirect-ref-p (indirect-ref-p r))) (if (> len-spec len-dim) (let ((true-specs (ref-true-args r specs len-dim len-spec))) (if (> (length true-specs) len-dim) (ref-err r specs) (setf specs true-specs))) (if (< len-spec len-dim) (setf specs (pad-list specs len-dim t)))) (setf len-spec (length specs)) (loop for i from 0 to (- len-spec 1) do (let ((spec (elt specs i))) (setf (elt specs i) (cond ((listp spec) (if (eq :c (first spec)) (append '(:c) (remove-duplicates (sort (rest spec) #'<))) spec)) ((eq spec t) t) ((integerp spec) (list spec)) (t (quail-error "Invalid specifier for dimension ~S: ~S." i spec)))))) (if (and indirect-ref-p (= len-spec len-dim)) (setf specs (expand-list specs (specs-mask-of r) t))) specs)) #| ;; a working version which distinguished between rows and columns on margin refs ... ;; too confusing due to incompatibilities with other cases (defun expand-margin-specs (r specs) (let* ((dim (dimensions-of r)) (len-dim (length dim)) (len-spec (length specs)) (indirect-ref-p (indirect-ref-p r)) r-specs) (if (> len-spec len-dim) (if (and indirect-ref-p (margin-specs-p (setf r-specs (specs-of r))) (= (length specs) (length r-specs))) ;; then these are specs recognizing the shape of the ref-obj, ;; so try to use them nil ;; else there's no masking, maybe can do something. (let ((true-specs (ref-true-args r specs len-dim len-spec))) (if (> (length true-specs) len-dim) (ref-err r specs) (setf specs true-specs))) ) ;; else try < (if (< len-spec len-dim) (setf specs (pad-list specs len-dim t)))) (setf len-spec (length specs)) (loop for i from 0 to (- len-spec 1) do (let ((spec (elt specs i))) (setf (elt specs i) (cond ((listp spec) (if (eq :c (first spec)) (append '(:c) (remove-duplicates (sort (rest spec) #'<))) spec)) ((eq spec t) t) ((integerp spec) (list spec)) (t (quail-error "Invalid specifier for dimension ~S: ~S." i spec)))))) (if (and indirect-ref-p (= len-spec len-dim)) (setf specs (expand-list specs (specs-mask-of r) t))) specs)) |# ; ; compute-margin-dim ; (defun compute-margin-dim (total-dim specs) (loop for s in specs as d in total-dim collect (cond ((eq s t) d) ((eq (first s) :c) (- d (length (rest s)))) (t (length s))))) ; ; indices-array ; (defgeneric indices-array (indices &key instance elements)) (defun indices-array-kernel (indices instance elements) (let ((needs-consing-p (not (consp (column-major-eref indices 0))))) (if (or instance elements needs-consing-p) (let* ((dim (array-dimensions indices)) (targ (if instance (make-array dim) indices)) (new-value-fcn (if needs-consing-p #'list (if elements #'copy-list #'identity)))) (loop for i from 0 to (1- (number-of-elements indices)) do (column-major-eset targ i (funcall new-value-fcn (column-major-eref indices i)))) targ) indices))) ;; this method is useful if the user calls indices-array directly (defmethod indices-array ((indices list) &key (instance t) (elements nil)) ;; we get a new instance regardless (declare (ignore instance)) (if (not (consp (first indices))) (setf indices (mapcar #'(lambda (ind) (list ind)) indices)) (if elements (setf indices (mapcar #'copy-list indices)))) (apply #'vector indices)) (defmethod indices-array ((indices array) &key (instance nil) (elements nil)) (indices-array-kernel indices instance elements)) (defmethod indices-array ((indices dimensioned-ref-object) &key (instance nil) (elements nil)) (declare (ignore instance)) (indices-array-kernel indices t elements)) ;; a more useful indices-array maker, for users (defun ind (indices-list &key (element-copy nil)) "Builds an array of indices from the given list of indices. ~ Each element is copied if keyword argument element-copy ~ is non-NIL." (let* ((d1 (nested-list-dimensions indices-list)) (dim (butlast d1))) (indices-array-kernel (make-array dim :initial-contents indices-list) :elements element-copy))) ; ; get-mask ; (defun get-mask (dim shape dim-mask) (let* ((dim (if dim-mask (list-if-t dim dim-mask) dim)) (shape (if (eq shape t) (pad-list '() (length dim) t) (pad-list shape (length dim) nil))) (mask (mapcar #'(lambda (x y) (or x (/= y 1))) shape dim))) (expand-list mask dim-mask nil))) ;-------------------------------------------------------------------------------- ;;; ; DEFMETHODs of ref ; (defmethod ref ((self dimensioned-ref-object) &rest args) (if (indirect-ref-p self) (ref-kernel (ref-instantiate self) self args) (missing-method 'ref self))) (defmethod ref ((self number) &rest args) (ref-true-args self args 0 (length args)) ;; if no error ... self) (defmethod ref ((self symbol) &rest args) (ref-true-args self args 0 (length args)) ;; if no error ... self) (defmethod ref ((self character) &rest args) (ref-true-args self args 0 (length args)) ;; if no error ... self) (defmethod ref ((self sequence) &rest args) (ref-kernel (ref-instantiate self) self args)) ;;; array also handles the string case (defmethod ref ((self array) &rest args) (ref-kernel (ref-instantiate self) self args)) ;-------------------------------------------------------------------------------- ; ; ref-list ; For any dimensioned ref-object. (defun ref-list (r) (let* ((dim (dimensions-of r)) (len (length dim))) (ref-list-recursion r dim (make-sequence 'list len) len 0))) (defun ref-list-recursion (r dim current terminus split) (if (eq split terminus) (apply #'eref r current) (let ((d-end (- (elt dim split) 1))) (loop for d from 0 to d-end collect (progn (setf (elt current split) d) (ref-list-recursion r dim current terminus (1+ split))))))) (defun ref-print (r &optional (stream *quail-terminal-io*)) (let* ((dim (dimensions-of r)) (len (length dim))) (ref-print-recursion r dim (make-sequence 'list len) len 0 stream))) (defun ref-print-recursion (r dim current terminus split stream &rest keys &key (elt-format "~S") (sep " ") (left "(") (right ")")) #-:sbcl-linux(declare (special *print-length*)) (if (eq split terminus) (format stream elt-format (apply #'eref r current)) (let ((d-end (- (elt dim split) 1)) (ellipsis nil)) (when (and *print-length* (>= d-end *print-length*)) (setf d-end (- *print-length* 1)) (setf ellipsis t)) (if left (format stream left)) (loop for d from 0 to d-end collect (progn (setf (elt current split) d) (apply #'ref-print-recursion r dim current terminus (1+ split) stream keys) (if (and sep (< d d-end)) (format stream sep)))) (if ellipsis (format stream " ...")) (if right (format stream right)))) ) #| #+:sbcl-linux(defun ref-print-recursion (r dim current terminus split stream &rest keys &key (elt-format "~S") (sep " ") (left "(") (right ")")) ;(declare (special *print-length*)) (if (eq split terminus) (format stream elt-format (apply #'eref r current)) (let ((d-end (- (elt dim split) 1)) (ellipsis nil)) (when (and *print-length* (>= d-end *print-length*)) (setf d-end (- *print-length* 1)) (setf ellipsis t)) (if left (format stream left)) (loop for d from 0 to d-end collect (progn (setf (elt current split) d) (apply #'ref-print-recursion r dim current terminus (1+ split) stream keys) (if (and sep (< d d-end)) (format stream sep)))) (if ellipsis (format stream " ...")) (if right (format stream right)))) ) |#
25,552
Common Lisp
.l
618
29.289644
103
0.49327
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a88fe1bc3838e528de1f95fb24b46e3338c6f2b93b983fe6b8ccca09190f73e9
33,943
[ -1 ]
33,944
with-ref.lsp
rwoldford_Quail/source/quail-kernel/ref/with-ref.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; with-ref.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :qk) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(with-ref))) (defun matching-p (form dummy-form) (or (eq dummy-form :dummy) (equal form dummy-form) (if (and (listp form) (listp dummy-form)) (let ((matching t)) (loop while matching for f in form as df in dummy-form do (setf matching (matching-p f df))) matching) nil))) ;; This next function collects up the pieces from form which match the ;; :dummy indicators in dummy-form, knowing in advance that the forms ;; are lists and match in the sense of matching-p. (defun collect-dummy-pieces (form dummy-form) (loop for f in form as df in dummy-form when (eq df :dummy) append (list f) when (listp df) append (collect-dummy-pieces f df))) ;;; Given the right number of dummies, this function DESTRUCTIVELY ;;; substitutes them for the :dummy indicators in specs. (defun substitute-dummy-pieces (specs dummies) (loop for i from 0 to (- (length specs) 1) when (eq (elt specs i) :dummy) do (progn (setf (elt specs i) (first dummies)) (setf dummies (rest dummies))) when (listp (elt specs i)) do (multiple-value-bind (new-specs new-dummies) (substitute-dummy-pieces (elt specs i) dummies) (declare (ignore new-specs)) (setf dummies new-dummies))) (values specs dummies)) ;; make-ref-template makes a list which will eventually hold: ;; ;; 1. the original ref'd object ;; 2. a template of the ref, initially :none ;; 3. the specs including the :dummy indicators ;; (defun make-ref-template (r dummy-specs) (vector r :none dummy-specs)) (defmacro original-ref (ref-template) `(svref ,ref-template 0)) (defmacro template (ref-template) `(svref ,ref-template 1)) (defmacro args (ref-template) `(svref ,ref-template 2)) ;;; This is the function which will take the place of the ref in code. The (only) ;;; win here is not doing many different make-instances. (defun template-ref (ref-template &rest dummy-pieces) (let ((args (substitute-dummy-pieces (copy-tree (args ref-template)) dummy-pieces))) (if (eq (template ref-template) :none) ;; This'll happen the first time thru, since template initially :none (setf (template ref-template) (apply #'ref (original-ref ref-template) args)) ;; This is the usual case, avoiding a new make-instance (ref-kernel (template ref-template) (original-ref ref-template) args)))) (defun template-setf-ref (new-value ref-template &rest dummy-pieces) (let ((targ (apply #'template-ref ref-template dummy-pieces))) (setf-ref-kernel new-value targ))) (defun convert-with-ref-body-recursion (body dummy-ref ref-template-symbol) (loop for i from 0 to (- (length body) 1) as b in body when (and (listp b) (eq (first b) 'setf) (listp (second b)) (eq (first (second b)) 'ref) (matching-p (rest (second b)) dummy-ref)) do (setf (elt body i) `(template-setf-ref ,(third b) ,ref-template-symbol ,@(collect-dummy-pieces (rest (second b)) dummy-ref))) when (and (listp b) (eq (first b) 'ref) (matching-p (rest b) dummy-ref)) do (setf (elt body i) `(template-ref ,ref-template-symbol ,@(collect-dummy-pieces (rest b) dummy-ref))) when (listp b) do (convert-with-ref-body-recursion b dummy-ref ref-template-symbol) ) body) (defun convert-with-ref-body (body dummy-refs dummy-ref-template-symbols) (loop for dr in dummy-refs as drts in dummy-ref-template-symbols do (convert-with-ref-body-recursion body dr drts)) body) (defun dummy-lets (dummy-refs dummy-ref-template-symbols) (loop for dr in dummy-refs as drts in dummy-ref-template-symbols collect `(,drts (make-ref-template ,(first dr) (quote ,(rest dr)))))) (defmacro with-ref (dummy-refs &rest body) (let* ((dummy-ref-template-symbols (loop for dr in dummy-refs collect (gensym)))) `(let* ,(dummy-lets dummy-refs dummy-ref-template-symbols) ,@(convert-with-ref-body (copy-tree body) dummy-refs dummy-ref-template-symbols)))) #| ;;; Seems to be a substantial improvement !! (defun test-it (x count) (let ((size (first (dimensions-of x)))) (time (let ((xc (make-ref-template x '(:dummy t))) (xr (make-ref-template x '(t :dummy)))) (loop for j from 1 to count do (loop for i from 0 to (- size 1) do (progn (template-ref xc i) (template-ref xr i)))))) (time (loop for j from 1 to count do (loop for i from 0 to (- size 1) do (progn (ref x i t) (ref x t i))))))) (defun test1 (x count) (with-ref ((x :dummy t) (x t :dummy)) (let ((size (first (dimensions-of x)))) (time (loop for j from 1 to count do (loop for i from 0 to (- size 1) do (progn (ref x i t) (ref x t i)))))))) (defun test2 (x count) (let ((size (first (dimensions-of x)))) (time (loop for j from 1 to count do (loop for i from 0 to (- size 1) do (progn (ref x i t) (ref x t i))))))) |#
6,832
Common Lisp
.l
155
31.625806
84
0.505679
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
50f6bdcdb91cb8f84c553600943c66bf4596e4f01e48cc454e3f632406b2dbcd
33,944
[ -1 ]
33,945
ref-if.lsp
rwoldford_Quail/source/quail-kernel/ref/ref-if.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ref-if.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Bob White ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(ref-if))) (defgeneric ref-if (object predicate) (:documentation "Applies the predicate to each element of object and returns ~ those elements which return T. These are returned in an array. ~ If no elements satisfy the predicate then an empty array is returned.")) (defmethod ref-if (object predicate) (ref object (indices object predicate)))
946
Common Lisp
.l
24
34.958333
80
0.462637
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
301b0e6c09eb5df1c83c4e564845f5165ce9b42d422ca5a552d90c80814946bc
33,945
[ -1 ]
33,946
eref.lsp
rwoldford_Quail/source/quail-kernel/ref/eref.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; eref.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1991. ;;; R.W. Oldford 1992. ;;; Greg Anglin 1993. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; eref ;;; eref-transform ;;; eref-transform-of-margin ;;; eref-transform-of-indices ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(eref *setf-eref*))) ;-------------------------------------------------------------------------------- ;;; ; DEFGENERICs of eref ; (defgeneric eref (r &rest index) (:documentation "Returns element of r specified by index.") ) (defgeneric (setf eref) (new-value a &rest index) (:documentation "Puts new-value in place (eref a index). new-value is returned by all (setf eref) methods.") ) ;-------------------------------------------------------------------------------- ;;; This code allows us to do (apply #'(setf eref) ...) using the expression ;;; (apply *setf-eref* ...) (defvar *setf-eref* "The value of this symbol allows us to do (apply #'(setf eref) ...) ~ using the expression (apply *setf-eref* ...).") (setf *setf-eref* #+:cl-2 #'(setf eref) #+:pcl #'pcl::setf\ quail-kernel\ eref) ;-------------------------------------------------------------------------------- ;;; ; Useful macros ; ; this should really handle a dim-ref-obj pointing to a list, too. (defmacro margin-specs-p (specs) `(or (listp ,specs) (symbolp ,specs) (numberp ,specs))) (defmacro indices-specs-p (specs) `(not (margin-specs-p ,specs))) ;;; ; Utility functions for eref methods ; ; ; eref-true-index ; allows objects with dimensions-rank < 2 to be eref'd with extraneous args, ; if the additional args are zeroes. (defun eref-err (r args) (quail-error "Improper arguments ~S provided to EREF for object ~S ~ with dimensions ~S." args r (dimensions-of r))) (defun eref-true-index (r index &optional dim-rank-r dim-rank-index) (let* ((dim-rank-r (or dim-rank-r (length (dimensions-of r)))) (dim-rank-index (or dim-rank-index (length index)))) (if (>= dim-rank-r dim-rank-index) ;; leaves the method to deal with any problems if >. index (let ((true-index (remove 0 index :count (- dim-rank-index dim-rank-r)))) (if (and (< dim-rank-r 2) (eql (length true-index) dim-rank-r)) true-index (eref-err r index)))))) ; ; eref-transform ; transforms index to indirect-ref dimensioned-ref-object r to index ; to (ref-obj-of r) ; assumes that index is already a true-index in the sense of eref-true-index (defun eref-transform (r index) (let* ((specs (specs-of r)) (specs-mask (specs-mask-of r)) (index (expand-list index specs-mask 0))) (if (margin-specs-p specs) (eref-transform-of-margin index specs) (eref-transform-of-indices index specs)))) (defun eref-transform-of-margin (index specs) (loop for i in index as s in specs collect (cond ((eq s t) i) ((eq (first s) :c) (let ((comp-list (rest s))) (or (loop for comp-i in comp-list do (cond ((< i comp-i) (return i)) (t (incf i)))) i))) (t (elt s i))))) (defun eref-transform-of-indices (index specs) (apply #'aref specs index)) ;;; ; DEFMETHODs of eref ; (defmethod eref ((self t) &rest index) (declare (ignore index)) (missing-method 'eref self)) ; the following case is only called in practice for dimensioned-ref-objects which have ; a ref-obj belonging to one of the basic classes, or accidently when a eref method ; is left undefined for an object inheriting from dimensioned-ref-object. Since this ; slows down eref for indirect refs to basic classes, such refs might better be ; avoided by using sel unless indirect reference is absolutely necessary. (defmethod eref ((self dimensioned-ref-object) &rest index) (if (indirect-ref-p self) (apply #'eref (ref-obj-of self) (eref-transform self (eref-true-index self index))) (missing-method 'eref self))) (defmethod eref ((self number) &rest index) (eref-true-index self index 0 0) ;; if no error, then ... self) (defmethod eref ((self symbol) &rest index) (eref-true-index self index 0 0) ;; if no error, then ... self) (defmethod eref ((self character) &rest index) (eref-true-index self index 0 0) ;; if no error, then ... self) (defmethod eref ((self sequence) &rest index) ;; let elt worry about out-of-bounds ... (elt self (first (eref-true-index self index 1)))) #| ;; old functionality which eref'd some nested lists with more than one ;; index ... not used anymore, I hope. dga 93 03 26. (defmethod eref ((self sequence) &rest index) (if (>= (first index) (length self)) (quail-error "Index ~d out of bounds for sequence ~s -- in EREF." (first index) self) (if (/= (length index) 1) (let ((result (elt self (first index)))) ;; use 'list to dodge the list of strings case (if (typep result 'list) (apply #'eref result (rest index)) (elt self (first (eref-true-index self index 1))))) (elt self (first index))))) |# (defmethod eref ((self array) &rest index) (apply #'aref self (eref-true-index self index))) ;;; ; DEFMETHODs of (setf eref) ; (defmethod (setf eref) (new-value (self t) &rest index) (declare (ignore index new-value)) (missing-method "(setf eref)" self)) ; see above comment for (defmethod eref (self dimensioned-ref-object) ...) (defmethod (setf eref) (new-value (self dimensioned-ref-object) &rest index) (declare (special *setf-eref*)) (if (indirect-ref-p self) (apply *setf-eref* new-value (ref-obj-of self) (eref-transform self (eref-true-index self index))) (missing-method 'eref self))) (defmethod (setf eref) (new-value (self sequence) &rest index) ;; let elt worry about out-of-bounds ... (setf (elt self (first (eref-true-index self index 1))) new-value)) #| ;; old functionality which eref'd some nested lists with more than one ;; index ... not used anymore, I hope. dga 93 03 26. (defmethod (setf eref) (new-value (self sequence) &rest index) (if (>= (first index) (length self)) (quail-error "Index ~d out of bounds for sequence ~s -- in (SETF EREF)." (first true-index) self) (if (/= (length index) 1) (let ((result (elt self (first index)))) ;; use 'list to dodge the list of strings case (if (typep result 'list) (apply *setf-eref* new-value result (rest index)) (setf (elt self (first (eref-true-index self index 1))) new-value))) (setf (elt self (first index)) new-value)))) |# (defmethod (setf eref) (new-value (self array) &rest index) (setf (apply #'aref self (eref-true-index self index)) new-value)) ;;; ; Function eref-mask and (setf eref-mask) ; (defun eref-mask (r &rest args) (multiple-value-bind (index mask) (interpret args '(:mask)) (apply #'eref r (if mask (list-if-t index mask :pad-with t) index))))
8,163
Common Lisp
.l
202
33.227723
88
0.55557
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
657a0e7940db7473b5d20f787e92cbe1489b2099e850af0c48d0130cb1ef4429
33,946
[ -1 ]
33,947
compound.lsp
rwoldford_Quail/source/quail-kernel/ref/compound.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; z-compound.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1989, 1990. [ Incomplete ] ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; z-compound ;;; make-compound ;;; components-of ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(z-compound make-compound components-of))) ;----------------------------------------------------------------------------- (defclass z-compound (ref-object) ((ref-contents :reader contents-of :initform (make-hash-table)))) (push-extension-class 'z-compound) (defun make-compound (&key names values name-value-list like) (let ((instance NIL)) (cond ((and names values (listp names) (listp values) (= (length names) (length values))) (setf instance (make-instance 'z-compound)) (loop for n in names for v in values do (setf (ref instance n) v))) ((and names values (listp names) (listp values)) (quail-cerror "Ignore the keyword parameters names and values" "The keyword parameters names and values are lists ~ of unequal length!~%~ Names = ~S ~%~ and values = ~S ~%." names values)) ((and names values) (setf instance (make-instance 'z-compound)) (setf (ref instance names) values)) ((and names (listp names)) (setf instance (make-instance 'z-compound)) (loop for n in names do (setf (ref instance n) NIL))) (names (setf instance (make-instance 'z-compound)) (setf (ref instance names) NIL))) (if name-value-list (loop for pair on name-value-list by #'cddr with obj = (or instance (make-instance 'z-compound)) do (setf (ref obj (car pair)) (cadr pair)))) (if (and like (typep like 'z-compound)) (loop for name in (components-of like) with obj = (or instance (setf instance (make-instance 'z-compound))) do (setf (ref obj name) NIL))) (or instance (make-instance 'z-compound)))) ;;; ; DEFMETHODs for ref ; (defmethod ref ((self z-compound) &rest selectors) (let ((n (length selectors))) (cond ((= n 0) self) ((= n 1) (gethash (first selectors) (contents-of self))) (t (loop for s in selectors with c = (contents-of self) collect (gethash s c)))))) ;; setf: do this way to be consistent with defgeneric (defmethod (setf ref) (new-value (self z-compound) &rest selectors) (setf (gethash (first selectors) (contents-of self)) new-value)) (defmethod components-of ((self z-compound)) (let ((components '())) (labels ((key-collect (key val) (declare (ignore val)) (setf components (cons key components)))) (maphash #'key-collect (contents-of self)) components)))
3,567
Common Lisp
.l
83
33.108434
107
0.49356
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0f1fafb4e7f05d10c868de33cf8200a4339a5593049fb2062a049eb345132247
33,947
[ -1 ]
33,948
column-major-ops.lsp
rwoldford_Quail/source/quail-kernel/ref/column-major-ops.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; column-major-ops.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(column-major-eref column-major-list-elements column-major-set-elements column-major-ref-slice ))) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-eref ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (dimensions-product nil) (subscripts nil) (index nil) (result nil)) (defun column-major-eref (a i) "Returns the i-th element of the argument a, counting by column major order. ~ It can be used with setf to set elements of its argument.~ (:required ~ (:arg A The object whose i'th element is to be returned.) ~ (:arg i The column major index of the element to be returned.) ~ )~ (:see-also row-major-eref column-major-ref-slice)" (if (eq a array) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts dimensions :col))) (0 result) (1 (setf subscripts (next-subscripts subscripts dimensions :col))) (t (setf subscripts (index-to-subscripts i dimensions :col)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf dimensions-product (cum-prod dimensions)) (setf subscripts (index-to-subscripts i dimensions :col)))) (setf index i) (setf result (apply #'eref a subscripts)) result)) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-eset ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (dimensions-product nil) (subscripts nil) (index nil) (result nil)) (defun column-major-eset (a i new-value) "Sets the value of the i-th element of the argument a, ~ counting by column major order." (declare (special *setf-eref*)) (if (eq a array) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts dimensions :col))) (0 result) (1 (setf subscripts (next-subscripts subscripts dimensions :col))) (t (setf subscripts (index-to-subscripts i dimensions :col)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf dimensions-product (cum-prod dimensions)) (setf subscripts (index-to-subscripts i dimensions :col)))) (setf index i) (setf result (apply *setf-eref* new-value a subscripts)) result)) ;;;-------------------------------------------------------------------------------- ;;; column-major-eref setf macro ;;;-------------------------------------------------------------------------------- (defsetf column-major-eref column-major-eset) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-list-elements ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (defun column-major-list-elements (object) "Returns a list containing all elements of the object in column major order.~ (:see-also column-major-set-elements column-major-eref column-major-ref-slice ~ row-major-list-elements)" (do ((counter (- (number-of-elements object) 1) (- counter 1)) (result nil (push (column-major-eref object counter) result))) ((minusp counter) result) ())) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-set-elements ;;; ;;; ;;;--------------------------------------------------------------------------- (defun column-major-set-elements (object list) "Sets the elements in object to that of list, iterating over object's ~ elements in column-major-order.~ (:see-also column-major-list-elements column-major-eref column-major-ref-slice ~ row-major-set-elements)" (dotimes (counter (number-of-elements object) object) (setf (column-major-eref object counter) (elt list counter)))) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-ref-slice ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (f-slices nil) (r-slices nil) (f-dims nil) (subscripts nil) (index nil) (result nil)) (defun column-major-ref-slice (a slices i) "Returns the i-th slice of the refable object a, indexing by column major order. ~ Like column-major-eref in this way except that slices of a can be identified as ~ fixed by giving a list of their dimension numbers as the slices argument.~ It can be used with setf to set slices to new values.~ (:required ~ (:arg A The object whose i'th slice is to be returned.) ~ (:arg slices The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of A having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of A. ~ Similarly, if slices is '(0 1) then a slice of A is the set of all elements ~ of A having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the object a is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them. In this special ~ case, column-major-ref-slice is identical to column-major-eref)~ (:arg i The column major index of the slice to be returned.) ~ )~ (:see-also column-major-eref row-major-ref-slice)" (cond ((eq :elements slices) ;; Treat elements as slices (column-major-eref a i)) ((null slices) ;;(or (null slices) ;; (and (= (length slices) 1) ;; (null (first slices)))) ;; if no slices are fixed just do a column-major-eref (ref a)) (t (if (and (eq a array) (equal slices f-slices)) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts f-dims :col))) ( 0 result) ( 1 (setf subscripts (next-subscripts subscripts f-dims :col))) ( t (setf subscripts (index-to-subscripts i f-dims :col)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf f-slices (cl:sort (remove-duplicates slices) #'cl:<)) (setf r-slices (row-major-list-elements (ref (iseq (length dimensions)) (cons :c f-slices) ))) (setf f-dims (row-major-list-elements (ref dimensions f-slices ))) (setf subscripts (index-to-subscripts i f-dims :col)))) (setf index i) (setf result (apply #'ref a (expand-subscripts subscripts r-slices))) ) ) ) ) ;;;--------------------------------------------------------------------------- ;;; ;;; Column-major-set-slice ;;; ;;; Note definition inside a lexical closure. ;;; ;;;--------------------------------------------------------------------------- (let* ((array nil) (dimensions nil) (f-slices nil) (r-slices nil) (f-dims nil) (subscripts nil) (index nil)) (defun column-major-set-slice (a slices i new-value) "Sets the i-th element of the refable object a, counting by column major order. ~ Like column-major-eset in this way except that slices of a can be identified as ~ fixed by giving their dimension number (0, 1, 2, ...) as further arguments." (cond ((eq :elements slices) ;; Treat elements as slices (setf (column-major-eref a i) new-value)) ((null slices) ;;(or (null slices) ;; (and (= (length slices) 1) ;; (null (first slices)))) ;; if no slices are fixed just do a column-major-eref (setf (ref a) new-value)) (t (if (and (eq a array) (equal slices f-slices)) (case (- i index) (-1 (setf subscripts (prior-subscripts subscripts f-dims :col))) ( 1 (setf subscripts (next-subscripts subscripts f-dims :col))) ( t (setf subscripts (index-to-subscripts i f-dims :col)))) (progn (setf array a) (setf dimensions (dimensions-of a)) (setf f-slices (cl:sort (remove-duplicates slices) #'cl:<)) (setf r-slices (column-major-list-elements (ref (iseq (length dimensions)) (cons :c f-slices) ))) (setf f-dims (column-major-list-elements (ref dimensions f-slices ))) (setf subscripts (index-to-subscripts i f-dims :col)))) (setf index i) (apply *setf-ref* new-value a (expand-subscripts subscripts r-slices)))))) ;;;-------------------------------------------------------------------------------- ;;; column-major-ref-slice setf macro ;;;-------------------------------------------------------------------------------- (defsetf column-major-ref-slice column-major-set-slice)
10,908
Common Lisp
.l
269
31.605948
88
0.48606
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d8d9ef7fade7bcfd7a9a1fdd827b0ee9d418695757c5a64eae1b0ab127481ca7
33,948
[ -1 ]
33,949
number-of-elements.lsp
rwoldford_Quail/source/quail-kernel/ref/number-of-elements.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; number-of-elements.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1991 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; Michael Lewis 1991 ;;; Greg Anglin 1991 ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(number-of-elements))) (defgeneric number-of-elements (thing) (:documentation "The number of elements in thing.")) (defmethod number-of-elements ((thing symbol)) 1) (defmethod number-of-elements ((thing number)) 1) (defmethod number-of-elements ((thing sequence)) (length thing)) (defmethod number-of-elements ((thing array)) (array-total-size thing)) (defmethod number-of-elements ((thing dimensioned-ref-object)) (array-total-size thing))
1,113
Common Lisp
.l
31
31.903226
89
0.488743
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dbc0c970a026cc5f7b243c823d84f17d95e17132b4433402a36c73d79f06029f
33,949
[ -1 ]
33,950
ref-behavior.lsp
rwoldford_Quail/source/quail-kernel/ref/ref-behavior.lsp
;;;------------------------------------------------------------------------ ;;; ref-behavior.lisp ;;; ;;; copyright, 1991, r. wayne oldford ;;;------------------------------------------------------------------------ (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(defrefclass copy-slots shared-initialize))) (proclaim '(declaration author)) (proclaim '(author "michael lewis")) ;-------------------------------------------------------------------------- ; defgeneric: copy-slots ;-------------------------------------------------------------------------- (defgeneric copy-slots (self) (:documentation "Decides the destiny of the contents of the slots of an object ~ after it is referenced. Persistent slots are copied to the ~ result; transient slots are reinitialized.")) (defmethod copy-slots ((self t)) nil) ;-------------------------------------------------------------------------- (defmacro make-copy-slots (class-name direct-slots) (block the-entire-macro (if (not (listp direct-slots)) (return-from the-entire-macro nil)) (if (not (listp (car direct-slots))) (return-from the-entire-macro `(make-copy-slots ,class-name ,(list direct-slots)))) (let ((defmethod-form (multiple-value-bind (slot-names reader-names writer-names) (loop for slot in direct-slots as persistent = (second (member :persistent slot)) with slot-name = nil with accessor = nil with reader = nil with writer = nil when persistent do (setf slot-name (first slot)) (setf accessor (second (member :accessor slot))) (setf reader (second (member :reader slot))) (setf writer (second (member :writer slot))) (setf reader (if accessor `(lambda () (,accessor read-object)) (if reader `(lambda () (,reader read-object)) `(lambda () (slot-value read-object ',slot-name))))) (setf writer (if accessor `(lambda (new-value) (setf (,accessor write-object) new-value)) (if writer `(lambda (new-value) (,writer new-value write-object)) `(lambda (new-value) (setf (slot-value write-object ',slot-name) new-value))))) and collect slot-name into slot-names and collect reader into reader-names and collect writer into writer-names finally (return (values slot-names reader-names writer-names))) `(defmethod copy-slots ((write-object ,class-name)) (let* ((proto-list (proto-of write-object)) (read-object (find-if #'(lambda (x) (eql (class-of x) (class-of write-object))) proto-list))) (when read-object ,.(loop for slot in slot-names as reader in reader-names as writer in writer-names collect `(funcall ,writer (funcall ,reader))))))))) defmethod-form))) ;---------------------------------------------------------------------------------- ; defmethod: shared-initialize ;---------------------------------------------------------------------------------- (defmethod shared-initialize :after ((self proto-mixin) slot-names &rest initargs) (declare (ignore slot-names initargs)) (with-slots (proto) self (if (eq proto :ignore) (setf proto nil) (progn (if (not (listp proto)) (setf proto (list proto))) (copy-slots self) (fill-unbound-slots self))))) ;----------------------------------------------------------------------------------- (defun make-slot-defs (direct-slots) (cond ((null direct-slots) nil) ((equal direct-slots (list nil)) direct-slots) (t (let ((a (car direct-slots)) (b (cdr direct-slots))) (cond ((atom a) (if (eql a :persistent) (make-slot-defs (cdr b)) (cons a (make-slot-defs b)))) ((listp a) (cons (make-slot-defs a) (make-slot-defs b))) (t (quail-error "~s is an unreadable slot definition" direct-slots))))))) (defmacro make-defclass (name direct-superclasses direct-slots &rest options) `(defclass ,name ,direct-superclasses ,(make-slot-defs direct-slots) ,.options)) (defmacro defrefclass (name direct-superclasses direct-slots &rest options) `(prog1 (make-defclass ,name ,direct-superclasses ,direct-slots ,.options) (make-copy-slots ,name ,direct-slots) (push-extension-class ',name) )) ;--------------------------------------------------------------------------------------
5,781
Common Lisp
.l
118
32.949153
109
0.42516
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f343da5df4099c7941965de9c5337b342120ea22e2452358ba0c797d9b496329
33,950
[ -1 ]
33,952
quail-save-old.lsp
rwoldford_Quail/source/quail-kernel/io/quail-save-old.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-save-old.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. [ Incomplete ] ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(save save-loop))) ;-------------------------------------------------------------------------------- ;; *save-dir* is defined in "q;Source:Kernel:IO:quail-file.lisp" (defvar *save-stream*) (defun set-save-dir (&optional (dir *save-dir-default*)) (setf *save-dir* (make-pathname :directory dir))) #| (defun save (&key (dir *save-dir*)) (declare (special *save-dir* *save-stream*)) ) |# (defun save-loop (&optional (stream *quail-terminal-io*)) (let* ((sym (list-owned-symbols 'quail)) (var-p (mapcar #'boundp sym)) (sym (list-if-t sym var-p)) (var (mapcar #'eval sym))) (loop for v in var as s in sym do (output-make-instance stream v s) (format stream "~%~%"))) (values))
1,417
Common Lisp
.l
37
32.864865
85
0.421944
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
59b2d13a41b64cc70f6241feae09579c3e068d88744bb042a9f8a04cc9369784
33,952
[ -1 ]
33,954
scan.lsp
rwoldford_Quail/source/quail-kernel/io/scan.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; scan.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) ;-------------------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (export '(scan))) (defvar *scan-file-default* nil) (defvar *scan-delimiter-default* #\\) (defvar *scan-ignore-default* nil) (defvar *eof* (gensym "this-better-not-show-up-in-the-input-anywhere")) (defclass scan-env (quail-file) ((delimit :initarg :delimit) (ignore :initarg :ignore))) (defun scan (file &key (delimit nil) (ignore nil)) (setf delimit (if delimit (if (eq delimit t) *scan-delimiter-default* delimit) nil)) (setf ignore (if (eq ignore :default) *scan-ignore-default* (copy-list ignore))) (setf file (quail-file-pathname file)) (make-instance 'scan-env :pathname file :delimit delimit :ignore ignore)) (defun scan-reset (scan-env) (quail-file-close scan-env) (quail-file-open scan-env)) (defun scan-cleanup (scan-env) (quail-file-destroy scan-env)) (defun scan-1 (scan-env) ;; This function assumes the stream is open ... ;; should have a with-open-quail-objects wrapped around it !! (with-slots (stream ignore delimit) scan-env (let (the-input) ;; ;; The delimited case isn't very useful ;; (if delimit ;; ;; Assumes the list is well-structured: The delimiter is the ;; last non-whitespace character in the file. Thus this type of scanning ;; is probably only useful for programmatically constructed files. ;; (progn (setf the-input (if (eq *eof* (peek-char t stream nil *eof* nil)) *eof* (read-delimited-list delimit stream t))) (if (not (eq *eof* the-input)) (loop for junk in ignore do (setf the-input (delete junk the-input))))) ;; ;; This is the more useful case. ;; (let ((junk-input t)) (loop while junk-input do (setf the-input (read stream nil *eof* nil)) (if (not (member the-input ignore)) (setf junk-input nil))))) the-input))) (defun scan-into-adjustable-vector (scan-env &optional (size-guess 16)) (with-open-quail-objects (scan-env) quail-file (let ((eof nil) (count 0) (size size-guess) (vec (make-array (list size-guess) :adjustable t)) the-input) (loop while (not eof) do (setf the-input (scan-1 scan-env)) (when (not (setf eof (eq the-input *eof*))) (when (>= count size) (setf size (* 2 size)) (setf vec (adjust-array vec (list size)))) (setf (elt vec count) the-input) (incf count))) (if (eq size count) vec (adjust-array vec (list count))))))
3,732
Common Lisp
.l
96
28.229167
84
0.477196
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7ddba695955d870aa193723105ec2e4b36c273fd9b5bd41b87d9468574823a6c
33,954
[ -1 ]
33,955
quail-file.lsp
rwoldford_Quail/source/quail-kernel/io/quail-file.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-file.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989-93. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*quail-data-dir-default* *quail-data-dir* set-quail-data-directory quail-file quail-file-pathname quail-file-cleanup))) ;-------------------------------------------------------------------------------- (defvar *quail-data-dir-default*) ;; this is a CLtL2 logical pathname ;#-:sbcl-linux (setf *quail-data-dir-default* "Home:Quail Data;") ;#+:sbcl-linux(setf *quail-data-dir-default* cl-user::*data-dir*) (defvar *quail-data-dir*) (setf *quail-data-dir* nil) (defvar *quail-files*) (setf *quail-files* nil) ;-------------------------------------------------------------------------------- (defclass quail-file (quail-open-state-mixin quail-object) ((pathname :accessor pathname-of :initarg :pathname :initform :NONE) (stream :accessor stream-of :initarg :stream :initform :NONE))) (push-extension-class 'quail-file) (defmethod initialize-instance :after ((self quail-file) &rest args) (declare (ignore args)) (pushnew self *quail-files* :test #'equal)) (defun quail-file-cleanup (&optional (destroy nil)) (mapcar (if destroy #'quail-close-destroy-object #'quail-close-physically-object) *quail-files*) nil) (defmethod quail-open-object ((self quail-file)) (with-slots (pathname stream) self (let ((open (quail-open-p-object self))) (if (not open) (setf stream (open-existing-io-file pathname)))))) (defmethod quail-close-preserve-object ((self quail-file)) (let ((open (quail-open-p-object self)) (originally-open (originally-open-p-object self))) (if (and open (not originally-open)) (quail-file-close self)))) (defmethod quail-close-destroy-object ((self quail-file)) (quail-file-destroy self)) (defmethod quail-close-physically-object ((self quail-file)) (let ((open (quail-open-p-object self))) (if open (quail-file-close self)))) ;;; ; quail-file operations ; (defmethod quail-file-initial-open ((self quail-file)) (with-slots (pathname stream open-state) self (setf stream (open-io-file pathname)) (setf open-state 1) #+:open-mixin-debug (format *quail-terminal-io* "~&Doing quail-file-initial-open of ~S, open-state ~S --> ~S" self (1- open-state) open-state) )) (defmethod quail-file-open ((self quail-file)) (with-slots (stream pathname) self (setf stream (open-existing-io-file pathname)))) (defmethod quail-file-close ((self quail-file)) (with-slots (stream) self (if (streamp stream) (close stream)))) (defmethod quail-file-destroy ((self quail-file)) (quail-file-close-and-delete self) (with-slots (pathname stream) self (setf pathname :none) (setf stream :none)) (setf *quail-files* (remove self *quail-files*))) (defmethod quail-file-close-and-delete ((self quail-file)) (with-slots (pathname stream) self (if (streamp stream) (close stream)) (if (and (pathnamep pathname) (probe-file pathname)) (delete-file pathname)))) (defmethod quail-file-read ((self quail-file)) (with-open-quail-objects (self) quail-file (with-slots (stream) self (read stream)))) (defmethod quail-file-read-at-index ((self quail-file) index) (with-open-quail-objects (self) quail-file (with-slots (stream) self (file-position stream index) (read stream)))) (defmethod quail-file-write ((self quail-file) format &rest args) (with-open-quail-objects (self) quail-file (with-slots (stream) self (apply #'format stream format args)))) (defmethod quail-file-write-at-index ((self quail-file) index format &rest args) (with-open-quail-objects (self) quail-file (with-slots (stream) self (file-position stream index) (apply #'format stream format args)))) ;; quail-file-length needs to be more explicit since using open-file-for-inspection. ;; Note that it cheats by never modifying open-state. (defmethod quail-file-length ((self quail-file)) (with-slots (pathname stream) self (let ((open (quail-open-p-object self))) (if (not open) (setf stream (open-file-for-inspection pathname))) (prog1 (file-length stream) (if (not open) (close stream)))))) ;-------------------------------------------------------------------------------- ;;; ; File utility routines ; (defun set-quail-data-directory (&optional dir &key reset) (declare (special *quail-data-dir* *quail-data-dir-default*)) (setf *quail-data-dir* (pathname (or dir (let ((default (if reset *quail-data-dir-default* (or *quail-data-dir* *quail-data-dir-default*)))) (funcall ;; A way of making this wb function accessible despite the fact ;; that package wb does not exist at this point when building quail. (symbol-function (find-symbol "PROMPT-USER" "WINDOW-BASICS")) :prompt-string (format nil "Please provide the name of a directory to reference for Quail data") :initial-string (namestring (translate-logical-pathname default)) :type 'string))))) (if (pathname-name *quail-data-dir*) ;; then the user forgot to specify the ending : or ; (setf *quail-data-dir* (pathname (concatenate 'string (namestring *quail-data-dir*) (if (typep *quail-data-dir* 'logical-pathname) ";" ":"))))) *quail-data-dir*) (defun quail-file-pathname (file &key (prefix "quail-file-") (suffix nil)) (declare (special *quail-data-dir* *quail-data-dir-default*)) (let* ((file (if file (pathname file) "")) (name (pathname-name file)) (dir (pathname-directory file))) (when (and (not dir) (not *quail-data-dir*)) (set-quail-data-directory)) (setf file (cond ((and (null name) (null dir)) (merge-pathnames *quail-data-dir* (get-unique-filename prefix *quail-data-dir*))) ((null dir) (merge-pathnames *quail-data-dir* file)) ((null name) (merge-pathnames file (get-unique-filename prefix dir))) (t file))) (if (pathname-type file) file (merge-pathnames file (make-pathname :type suffix))))) (defun get-unique-filename (leader dir) (let (filename (there t)) (loop while there do (progn (setf filename (string (gensym leader))) (setf there (probe-file (merge-pathnames dir filename))))) filename)) (defun open-file-for-inspection (file) (open file :direction :input :if-does-not-exist :create)) (defun open-existing-io-file (file) (open file :direction :io :if-exists :overwrite :if-does-not-exist :error)) (defun open-io-file (file) (open file :direction :io :if-exists :overwrite :if-does-not-exist :create)) (defun open-io-file-safely (file) (let (stream) ;; open :probe to determine if it exists (setf stream (open file :direction :probe)) (if stream (quail-cerror "Overwrite ~S." "File ~S ~ ~&already exists." (truename file))) ;; open :direction :io for :overwrite (setf stream (open file :direction :io :if-exists :overwrite :if-does-not-exist :create)) stream)) (defun open-io-file-with-no-mercy (file) (let (stream) ;; open :rename-and-delete then close to truncate (setf stream (open file :direction :output :if-exists :rename-and-delete :if-does-not-exist :create)) (close stream) ;; now open :append (to a zero-length file) (setf stream (open file :direction :io :if-exists :append :if-does-not-exist :create))))
9,344
Common Lisp
.l
227
31.114537
113
0.540684
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
847615143399179c86b96a61c1c19981c6e5b34e03fe41c136800dd0c494b83b
33,955
[ -1 ]
33,956
save-sblx.lsp
rwoldford_Quail/source/quail-kernel/io/save-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; save-sblx.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991. ;;; ;;; Mods: ;;; R.W. Oldford 1991. ;;; Greg Anglin 1993. ;;; Greg Bennett 1998, 2017 ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(save save-quail-objects add-save-exit-functions))) ;-------------------------------------------------------------------------------- ;;; A text form to get a pathname to a file ;;; This will be changed when we have a graphical interface. ;;; gwb 20APRIL2018 (defun ask-for-save-path () (format t "~%The image will besaved under disrectory ~s " (user-homedir-pathname)) (format t "~%Please enter a string for the path. \"ZZ\" to exit ~%") (let ((result (read))) (if (string= result "ZZ") (return-from ask-for-save-path "Exiting") (merge-pathnames result (user-homedir-pathname)))) ) (defun save (&optional file) "Saves the current Quail image in the named file. ~ If no file named, user is prompted for name." (unless file (let ((release-info (get-quail-release-info))) (cond (release-info (let ((version (first release-info)) (distribution (second release-info)) ) (if distribution (setf file (format NIL "Quail~s(~a)" version distribution)) (setf file (format NIL "Quail~s" version)) ) ) ) (T (setf file "Quail")) ) ) ) (let ((image-loc (ask-for-save-path) ;(cg::ask-user-for-new-pathname ; "Quail image location?" ; :initial-name (format NIL "~a.dxl" file)) ) ) ;(apply #'excl::dumplisp (list ':name image-loc)) (sb-ext::save-lisp-and-die image-loc) ) ) (defun save-quail-objects () "Save all quail objects created in the current session." (quail-error "Sorry don't know how to save your quail objects yet.")) (defparameter *quail-save-exit-functions* nil "A list of functions to be executed upon exit form lisp") (defun quail-save-exit (&rest args) (declare (ignore args)) (mapcar #'funcall *quail-save-exit-functions*)) (defun add-save-exit-functions (&rest functions) "Adds the given quail lisp functions to the set that will be ~ executed before the current image is saved." (setf *quail-save-exit-functions* (append *quail-save-exit-functions* functions))) #| ;;; Don't know what these are yet (pushnew #'quail-save-exit sys:*exit-cleanup-forms* ;(cg::session-exit-functions cg::*system*) spr29023 ) |#
3,052
Common Lisp
.l
82
31.731707
115
0.536824
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
125f32cf60cb9cb444dcb004c97d918fff50066a5f071ad241816ee54617f666
33,956
[ -1 ]
33,957
save-pc.lsp
rwoldford_Quail/source/quail-kernel/io/save-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; save-pc.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991. ;;; ;;; Mods: ;;; R.W. Oldford 1991. ;;; Greg Anglin 1993. ;;; Greg Bennett 1998. ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(save save-quail-objects add-save-exit-functions))) ;-------------------------------------------------------------------------------- #| ;;; until I get to dialogs like ask-user-for-new-pathname 10au2017 (defun save (&optional file) "Saves the current Quail image in the named file. ~ If no file named, user is prompted for name." (unless file (let ((release-info (get-quail-release-info))) (cond (release-info (let ((version (first release-info)) (distribution (second release-info)) ) (if distribution (setf file (format NIL "Quail~s(~a)" version distribution)) (setf file (format NIL "Quail~s" version)) ) ) ) (T (setf file "Quail")) ) ) ) (let ((image-loc (cg::ask-user-for-new-pathname "Quail image location?" :initial-name (format NIL "~a.dxl" file))) ) (apply #'excl::dumplisp (list ':name image-loc)) ) ) |# (defun save-quail-objects () "Save all quail objects created in the current session." (quail-error "Sorry don't know how to save your quail objects yet.")) (defparameter *quail-save-exit-functions* nil "A list of functions to be executed upon exit form lisp") (defun quail-save-exit (&rest args) (declare (ignore args)) (mapcar #'funcall *quail-save-exit-functions*)) (defun add-save-exit-functions (&rest functions) "Adds the given quail lisp functions to the set that will be ~ executed before the current image is saved." (setf *quail-save-exit-functions* (append *quail-save-exit-functions* functions))) #| ;;; Until I sort out sbcl's analogue of *exit-cleanup-forms* (pushnew #'quail-save-exit sys:*exit-cleanup-forms* ;(cg::session-exit-functions cg::*system*) spr29023 ) |#
2,667
Common Lisp
.l
71
30.43662
116
0.504065
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0020d43c94dd93ec460dc3aa12a70ba5ae9b1d3bf4b323d2468db77057606653
33,957
[ -1 ]
33,959
quail-io.lsp
rwoldford_Quail/source/quail-kernel/io/quail-io.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-io.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1990. ;;; M.E. Lewis 1991. ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; QUAIL SYSTEM INPUT/OUTPUT ;;; ;;; In this file the officially sanctioned functions for direct communication ;;; with the user of quail software are defined. So are the io-streams for this ;;; communication. ;;; ;;; Variables: ;;; *quail-standard-input* ;;; *quail-standard-output* ;;; *quail-query-io* ;;; *quail-help-io* ;;; ;;; Functions: ;;; quail-print - print function ;;; quail-error - error function. ;;; quail-cerror - continuable quail-error. ;;; quail-query - prompt user for a form to evaluate. ;;; quail-y-or-n-p - ask user a question; wait for single character ;;; y or n response. ;;; quail-yes-or-no-p - ask user a question; wait for multiple character ;;; yes or no response. ;;; ;;;------------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*quail-standard-input* *quail-standard-output* *quail-query-io* *quail-debug-io* *quail-error-output* *quail-trace-output* *quail-terminal-io* *quail-help-io* quail-print quail-error quail-cerror quail-query quail-y-or-n-p quail-yes-or-no-p))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; (defvar *quail-standard-output* (make-synonym-stream '*standard-output*)) (defvar *quail-standard-input* (make-synonym-stream '*standard-input*)) (defvar *quail-query-io* (make-synonym-stream '*query-io*)) (defvar *quail-debug-io* (make-synonym-stream '*debug-io*)) (defvar *quail-error-output* (make-synonym-stream '*error-output*)) (defvar *quail-trace-output* (make-synonym-stream '*trace-output*)) (defvar *quail-terminal-io* (make-synonym-stream '*terminal-io*)) (defvar *quail-help-io* (make-synonym-stream '*terminal-io*) "The stream to be used by Quail's online help function.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; (defun quail-print (object &optional output-stream) "Outputs the printed representation of data object to output-stream, ~ preceded by a newline and followed by a space. Returns object." (print object output-stream)) (defun quail-error (datum &rest args) "Invokes the signal facility on a condition. If the condition is not handled, ~ (invoke-debugger condition) is executed. " (apply #'error datum args)) (defun quail-cerror (continue-format-string datum &rest args) "Invokes the signal facility on a condition. If the condition is not handled, ~ (invoke-debugger condition) is executed. While signaling is going on, ~ it is possible to return from cerrror by invoking continue. cerror returns nil." (apply #'cerror continue-format-string datum args)) #| (defmacro quail-error (datum &rest args) "Invokes the signal facility on a condition. If the condition is not handled, ~ (invoke-debugger condition) is executed. " `(error , datum ,@args)) (defmacro quail-cerror (continue-format-string datum &rest args) "Invokes the signal facility on a condition. If the condition is not handled, ~ (invoke-debugger condition) is executed. While signaling is going on, ~ it is possible to return from cerrror by invoking continue. cerror returns nil." `(cerror ,continue-format-string ,datum ,@args)) |# (defun quail-y-or-n-p (&optional format-string &rest format-args) "Prints a message from format-string and format-args, followed by (y or n), ~ and waits for the user to type y or n. ~ Returns T if the user typed y, or nil if the user typed n. ~ (:see-also y-or-n-p quail-yes-or-no-p prompt-t-or-f quail-query)" (apply #'y-or-n-p format-string format-args) ) (defun quail-yes-or-no-p (&optional format-string &rest format-args) "Prints a message from format-string and format-args, followed by (yes or no), ~ and waits for the user to type yes or no followed by a carriage return. ~ Returns t if the user typed yes, nil if the user typed no. ~ (:see-also yes-or-no-p quail-y-or-n-p prompt-true-or-false)" (apply #'yes-or-no-p format-string format-args)) (defun quail-query (format-string &rest args) "Prompts the user with format-string and reads in user-typed expression. ~ (:see-also prompt-user quail-yes-or-no-p *quail-query-io* quail-y-or-n-p ~ quail-query)" (declare (special *quail-query-io*)) (apply #'format *quail-query-io* format-string args) (read *quail-query-io*) )
5,377
Common Lisp
.l
115
42.382609
89
0.583094
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f449703fc649737e46060cfa41414203be4c91c867d80a12937f041c5fd30b14
33,959
[ -1 ]
33,960
restore.lsp
rwoldford_Quail/source/quail-kernel/io/restore.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; restore.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991. ;;; ;;; Mods: ;;; R.W. Oldford 1991. ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(add-restore-lisp-functions))) ;-------------------------------------------------------------------------------- (defparameter *quail-restore-lisp-functions* nil) (defun quail-restore () (mapcar #'funcall *quail-restore-lisp-functions*) nil) (defun add-restore-lisp-functions (&rest functions) "Adds the given quail lisp functions to the set that will be ~ restored when the current image is restarted." (setf *quail-restore-lisp-functions* (append *quail-restore-lisp-functions* functions)))
1,164
Common Lisp
.l
29
36
95
0.443455
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cbc356a4dd346fa07a576b65a567d760a1c624e59afd0f7176e1146977a48953
33,960
[ -1 ]
33,962
defmethod-multi.lsp
rwoldford_Quail/source/quail-kernel/basic/defmethod-multi.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; defmethod-multi.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1991, 1995. ;;; ;;;---------------------------------------------------------------------------- (in-package :qk) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(defmethod-multi defmethod-multi-one-body))) (defmacro defmethod-multi (&rest defmethod-args) (let* ((split (position-if-not #'(lambda (x) (and x (atom x))) defmethod-args)) (lambda-list (if split (elt defmethod-args split) (quail-error "Malformed defmethod-multi: ~ no lambda-list provided."))) (function-name-and-method-qualifiers (subseq defmethod-args 0 split)) (body (subseq defmethod-args (+ 1 split))) (split (position-if #'(lambda (x) (member x lambda-list-keywords)) lambda-list)) (multi-specialized-parameters (if split (subseq lambda-list 0 split) lambda-list)) (other-parameters (if split (subseq lambda-list split) nil)) specialized-parameters-cross-product) (setf specialized-parameters-cross-product (defmethod-cross-product multi-specialized-parameters)) `(progn ,@(loop for specialized-parameters in specialized-parameters-cross-product collect `(defmethod ,@function-name-and-method-qualifiers (,@specialized-parameters ,@other-parameters) ,@body))) )) (defmacro defmethod-multi-one-body (&rest defmethod-args) (let* ((split (position-if-not #'(lambda (x) (and x (atom x))) defmethod-args)) (lambda-list (if split (elt defmethod-args split) (quail-error "Malformed defmethod-multi: ~ no lambda-list provided."))) (function-name-and-method-qualifiers (subseq defmethod-args 0 split)) (body (subseq defmethod-args (+ 1 split))) (split (position-if #'(lambda (x) (member x lambda-list-keywords)) lambda-list)) (multi-specialized-parameters (if split (subseq lambda-list 0 split) lambda-list)) (other-parameters (if split (subseq lambda-list split) nil)) body-par-list specialized-parameters-cross-product) (setf specialized-parameters-cross-product (defmethod-cross-product multi-specialized-parameters)) (setf body-par-list (mapcar #'(lambda (x) (if (listp x) (first x) x)) (append (first specialized-parameters-cross-product) other-parameters))) `(flet ((body-fn ,body-par-list ,@body)) ,@(loop for specialized-parameters in specialized-parameters-cross-product collect `(defmethod ,@function-name-and-method-qualifiers (,@specialized-parameters ,@other-parameters) (funcall #'body-fn ,@body-par-list)))) )) (defun defmethod-cross-product (multi-specialized-parameters) (if multi-specialized-parameters (let* ((sp (first multi-specialized-parameters)) (xprod-rest (defmethod-cross-product (rest multi-specialized-parameters))) (var (if (listp sp) (first sp) sp)) (specializers (if (listp sp) (prog1 (second sp) (if (nthcdr 2 sp) (error "Malformed multiple specialization in DEFMETHOD-MULTI: ~S. ~ ~&Should probably read (~S ~S)." sp var (rest sp)))) :not-provided))) (if (and (listp specializers) (not (eq 'eql (first specializers)))) (loop for s in specializers append (xprod-with var s xprod-rest)) (xprod-with var specializers xprod-rest))))) (defun xprod-with (var spec xprod) (let ((var-spec (if (eq spec :not-provided) var (list var spec)))) (if xprod (loop for xp in xprod collect (list* var-spec xp)) (list (list var-spec)))))
5,134
Common Lisp
.l
106
31.849057
109
0.471679
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2e23eac5a1f51c758d57c14c7211a8da3b53cef328e51580f5ea7a264995ecf8
33,962
[ -1 ]
33,963
make-result.lsp
rwoldford_Quail/source/quail-kernel/basic/make-result.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; make-result.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; make-dimensioned-result ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-dimensioned-result))) (defun make-dimensioned-result (dimensions &rest args) (declare (special NaN)) ;; uncommented 25JUL2023 from F-D-7 (multiple-value-bind (proto-list minimal-class) (interpret args '(:class)) (let* ((len-dim (length dimensions)) (ret-class (find-return-class len-dim minimal-class proto-list)) (result (if (eq (class-name (class-of (find-class ret-class))) 'built-in-class) ;; this is the best we can do for now ... need better subtypep (cond ((or (eq ret-class 'array) (eq ret-class 'vector)) (make-array dimensions)) ((and (or (eq ret-class 'cons) (eq ret-class 'list)) (eq len-dim 1)) (make-sequence 'list (first dimensions))) (t (array NaN :dimensions dimensions))) ;; We do (make-instance ret-class ...) rather than ;; (make-instance (find-class ret-class) ...) because ;; then we catch occurrences of, for example, ;; (defmethod make-instance ((class (eql 'num-array)) ...) ...) (make-instance ret-class :dimensions dimensions :contents :empty :proto proto-list)))) result)))
2,141
Common Lisp
.l
47
33.574468
92
0.436303
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d82f07143546e18eed0c99275e70b12c22c8000801af794afd2f5d00bfdc84a4
33,963
[ -1 ]
33,965
search-tree.lsp
rwoldford_Quail/source/quail-kernel/basic/search-tree.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; search-tree.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) ;;;; (defmethod family-tree ((tree key-tree) (me node)) (labels ((fam (node-list node) (cond ((null node) NIL) (t (cons (name node) (fam node-list (as-node tree (dad node)))))))) (fam (nodes tree) me))) (defmethod successor-nodes ((tree key-tree)) #'(lambda (node) (mapcar #'(lambda (son) (as-node tree son)) (sons node)))) (defmethod share-family-tree-p ((tree key-tree) value) #'(lambda (node) (let ((f-tree (family-tree tree node))) (and (= (length value) (length f-tree)) (every #'(lambda (x y) (contained x (atomcar y))) value f-tree))))) (defun atomcar (obj) (cond ((null obj) nil) ((atom obj) obj) (t (atomcar (car obj))))) (defun contained (x y &key (test #'equalp)) (eql 0 (search x y :test test)))
1,574
Common Lisp
.l
47
23.957447
80
0.37591
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
38ff530cf4ccac677113405ecdb21963c201dd0f785dd0ce1a1f798af3d1fb7b
33,965
[ -1 ]
33,966
tree.lsp
rwoldford_Quail/source/quail-kernel/basic/tree.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tree.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1992 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) ;;;; NODES (defclass node () ((name :initarg :name :accessor name :initform NIL) (dad :initarg :dad :accessor dad :initform NIL) (pedigree :initarg :pedigree :accessor pedigree :initform NIL) (sons :initarg :sons :accessor sons :initform NIL) (value :initarg :value :accessor value :initform NIL) (hold :initarg :hold :accessor hold :initform NIL) (show :initarg :show :accessor show :initform NIL) )) (defmethod show ((me t)) #'(lambda () me)) (defmethod print-object ((self node) stream) (format stream "#<ND ~a>" (name self))) (defun root-node-p (node) (equalp ":root" (name node))) ;;;; KEY-TREES (defclass key-tree () ((nodes :initarg :nodes :accessor nodes :initform NIL))) (defun make-key-tree (nested-list) (make-instance 'key-tree :nodes (mapcar #'(lambda (x) (make-instance 'node :name (first x) :dad (second x) :sons (third x))) (node-specs nested-list)))) (defun make-empty-tree () (make-key-tree '((":root")))) (defmethod as-node ((me key-tree) name) (find name (nodes me) :test #'equalp :key #'name)) (defmethod root-tree ((me key-tree)) (make-instance 'key-tree :nodes (list (root-node me)))) (defmethod root-node ((me key-tree)) (as-node me ":root")) (defmethod root-pedigree ((me key-tree)) (pedigree (root-node me))) ;;;; (defmethod find-node ((me key-tree) trail) (find trail (nodes me) :test #'equalp :key #'pedigree)) (defmethod add-node ((tree key-tree) (me node)) (make-instance 'key-tree :nodes (cons me (nodes tree)))) ;;;; DECORATING A TREE (defun decorate (key-tree result-tree dad item) (cond ((null item) (collect-items result-tree dad)) ((atom item) (add-item result-tree dad item)) (t (cond ((find-node result-tree (cons (first item) dad)) (decorate key-tree result-tree (cons (first item) dad) (rest item))) ((find-node key-tree (cons (first item) dad)) (decorate key-tree (add-node result-tree (find-node key-tree (cons (first item) dad))) (cons (first item) dad) (rest item))) (t (decorate key-tree (decorate key-tree result-tree dad (first item)) dad (rest item))))))) (defun add-item (result-tree dad item) (push item (hold (find-node result-tree dad))) result-tree) (defun collect-items (result-tree dad) (unless (null (hold (find-node result-tree dad))) (push (hold (find-node result-tree dad)) (value (find-node result-tree dad))) (setf (hold (find-node result-tree dad)) NIL)) result-tree) ;;;; utility functions (defun node-specs (nested-list &optional (dad nil)) (cond ((null nested-list) nil) ((atom nested-list) (list (list nested-list dad NIL))) ((atom (car nested-list)) (cons (list (car nested-list) dad (mapcar #'atomcar (cdr nested-list))) (mapcan #'(lambda (x) (cond ((null x) nil) ((atom x) (list (list x (car nested-list) NIL))) (t (node-specs x (car nested-list))))) (cdr nested-list)))) (t (mapcan #'(lambda (x) (node-specs x dad)) nested-list)))) (defun tree-apply (fn tree) (let ((result nil)) (dolist (v tree (nreverse result)) (cond ((null v) (push "NIL" result)) ((atom v) (push (funcall fn v) result)) (t (push (tree-apply fn v) result)))))) (defun tree-remove (item tree &key (test #'equalp)) (cond ((null tree) nil) ((atom tree) tree) ((funcall test item (car tree)) (tree-remove item (cdr tree) :test test)) (t (cons (tree-remove item (car tree) :test test) (tree-remove item (cdr tree) :test test)))))
5,198
Common Lisp
.l
136
26.382353
80
0.466533
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
503b9535b4c036050e206b309e863af8e8aee50bcc0c1722e3a4e66702f2aa2d
33,966
[ -1 ]
33,967
proto-mixin.lsp
rwoldford_Quail/source/quail-kernel/basic/proto-mixin.lsp
(in-package :qk) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; proto-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; mel, rwo touched in places ;;;-------------------------------------------------------------------------------- (defclass proto-mixin () ((proto :accessor proto-of :initarg :proto :initform nil))) ;; The following is defined on shared-initialize :after so that it gets used ;; when reinitialize-instance, like initialize-instance, is called. It also ;; gives a slot-names which are permitted to be modified. Usually ;; this is T, meaning any slot. See CLtL 2, section 28.1.9.5. ;; ;; If make-instance is called with :proto :ignore, then that make-instance MUST ;; be followed by a reinitialize-instance (not having :proto :ignore) BEFORE ;; the created instance is used in any way other than method dispatching. ;; ;; proto-mixins, say of class 'quail-proto-using-class, ;; should be initialized in one of two ways: ;; ;; 1. (setf self (make-instance 'quail-proto-using-class ...)) ;; or ;; 2. (setf self (make-instance 'quail-proto-using-class :proto :ignore ...)) ;; ;; then later, when possible (using :proto if desired) ;; (reinitialize-instance self ...) ;; ;; CAUTION: In scheme 2, initialize-instance :after is executed only once, ;; during the make-instance. If you want code executed both times, ;; put it onto shared-initialize :after. I suppose you could instead ;; put different code on reinitialize-instance :after, but at the very ;; least it's prudent to have similar code on initialize-instance :after ;; as well, in which case shared-initialize :after would probably serve ;; the purpose. ;; (defmethod shared-initialize :after ((self proto-mixin) slot-names &rest initargs) (declare (ignore slot-names initargs)) (with-slots (proto) self (if (eq proto :ignore) (setf proto nil) (progn (if (not (listp proto)) (setf proto (list proto))) (fill-unbound-slots self))))) ;; proto is destroyed --> nil by default :around method #| ;; This may be useful for debugging, since can't trace shared-initialize. ;; Substitute whatever class is of interest (not proto-mixin !). (defmethod shared-initialize :after ((self ref-array) slot-names &rest initargs) (format *quail-terminal-io* "~&Shared-initialize ~S slot-names ~S initargs ~S" self slot-names initargs)) |# ;; ;; fill-unbound-slots is a very important generic function called from ;; initialize-instance :after ((self proto-mixin) ...). ;; ;; The purpose of fill-unbound-slots is to perform complex initialization ;; of slots of new instances of subclasses of proto-mixin. The slot proto ;; contains a list of instances which were involved in the construction ;; of the new instance, and these can be used to provide information ;; about the best values for any unbound slots of the new instance. ;; New methods will be :after methods, thus slots from superclasses ;; can be relied upon to be bound. ;; ;; It is crucial to the operation of this generic function that any slot involved ;; has no :initform, since each :after method relies upon the unbound-ness of ;; the slot to ascertain that it was not specifically initialized with an ;; :initarg. ;; ;; The :around method provided leaves slot proto with value nil, and thus avoids ;; keeping unnecessary references to the proto objects (this helps with garbage ;; collection). This can be overridden by more specialized :around methods, but ;; such methods should be sure to invoke #'call-next-method !! ;; ;; I CHANGED THIS - MEL ;; (defmacro fill-slot-p (self slot-name) ;; `(not (slot-boundp ,self ,slot-name))) (defun fill-slot-p (self slot-name) (not (slot-boundp self slot-name))) (defgeneric fill-unbound-slots (any-proto-mixin)) (defmethod fill-unbound-slots ((self proto-mixin)) ;; do nothing ... just here for :around ) (defmethod fill-unbound-slots :around ((self proto-mixin)) (call-next-method self) (setf (proto-of self) nil)) ;; The structure for more specialized proto-mixins (say quail-proto-using-class), should be ;; something like: #| (defmethod fill-unbound-slots :after ((self quail-proto-using-class)) (with-slots ((protos proto)) self (setf protos (remove-if-not #'(lambda (proto) (typep proto 'quail-proto-using-class)) protos)) (if (fill-slot-p self 'quail-proto-using-class-slot) (setf (slot-value self 'quail-proto-using-class-slot) (some-optimal-value self protos 'quail-proto-using-class-slot))))) |#
5,176
Common Lisp
.l
109
42.853211
95
0.632373
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
21a1c3264d01d5af0df97fbe7231831b1e40f7cf9df2adce1aac59921066c285
33,967
[ -1 ]
33,968
seq-utilities.lsp
rwoldford_Quail/source/quail-kernel/basic/seq-utilities.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; seq-utilities.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1990 ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(seq-min seq-max seq-destructive-union general-seq-union seq-union type-of-seq seq-complement seq-difference seq-intersection seq-sym-difference))) ;;; ---------------------------------------------------------------------------- ;;; ;;; A file full of useful operators on (primarily) numerical CL sequences. ;;; ;;; ---------------------------------------------------------------------------- (defun seq-min (sequence) (reduce #'min sequence)) (defun seq-max (sequence) (reduce #'max sequence)) ;;;---------------------------------------------------------------------------- ;;; ;;; A general set-union operator for any CL sequence. ;;; The keyword argument is to be a comparison predicate function that ;;; operates as an appropriate "less-than" function. Same as key for ;;; (merge ... ) in CLtL chapter on sequences. ;;; ;;;---------------------------------------------------------------------------- (defun seq-destructive-union (seq-1 seq-2 &key (increase NIL)) (delete-duplicates (if increase ;; then (merge (type-of-seq seq-1) seq-1 seq-2 increase) ;; else (concatenate (type-of-seq seq-1) seq-1 seq-2)))) (defun general-seq-union (seq-1 seq-2 &key (increase NIL)) (let ((copy-seq-1 (copy-seq seq-1)) (copy-seq-2 (copy-seq seq-2))) (seq-destructive-union copy-seq-1 copy-seq-2 :increase increase))) ;;;---------------------------------------------------------------------------- ;;; ;;; Set operations for CL sequences whose contents are numbers, arranged ;;; in STRICTLY INCREASING ORDER. ;;; ;;;---------------------------------------------------------------------------- (defun seq-union (seq-1 seq-2) (general-seq-union seq-1 seq-2 :increase #'<)) (defun type-of-seq (sequence) (if (listp sequence) 'list (type-of sequence))) (defun seq-complement (seq-1 seq-2) (seq-difference seq-2 seq-1)) (defun seq-difference (seq-1 seq-2) (remove-if #'(lambda (x) (find x seq-2 :test #'equal)) seq-1)) (defun seq-intersection (seq-1 seq-2) (seq-difference seq-1 (seq-difference seq-1 seq-2))) (defun seq-sym-difference (seq-1 seq-2) (seq-union (seq-difference seq-2 seq-1) (seq-difference seq-1 seq-2)))
2,959
Common Lisp
.l
70
36.985714
131
0.469373
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
085901ec236136a25d09435afd0ba759c4f9078e5eb2bd64b932123f1b8f26f9
33,968
[ -1 ]
33,970
defconstant.lsp
rwoldford_Quail/source/quail-kernel/basic/defconstant.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; define-constant.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Bennett 2018 ;;; ;;; ;;;---------------------------------------------------------------------------- ;;; From sbcl manual 1.4.4 ;;; Section 2.3.4 Defining Constants (in-package :quail-kernel) (export '(define-constant)) (defmacro define-constant (name value &optional doc) `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value) ,@(when doc (list doc))))
768
Common Lisp
.l
22
31.454545
83
0.38874
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3fbea583bba3f3ddc3d0c1790c3d39cae547ec537c4766b37832e549de6cb5b8
33,970
[ -1 ]
33,973
utility-pc.lsp
rwoldford_Quail/source/quail-kernel/basic/utility-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; utility-pc.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1991. ;;; R.W. Oldford 1991 ;;; M.E. Lewis 1991 ;;; Greg Anglin 1993, -excl port ;;; ;;;-------------------------------------------------------------------------------- ;;; A copy of utility-excl.lisp <= *** ;;; There is no EXCL package in aclwin ;;; ;;; Includes: ;;; ;;; get-lambda-list (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(structure-p built-in-class-p))) #+:cl-1 (eval-when (:compile-toplevel :load-toplevel :execute) "A gimmick to accomodate CLtL 1. The package ~ containing the LISP language is called lisp in CLtL 1 but ~ common-lisp in CLtL 2. Here LISP is given the same ~ nicknames." (let ((old-package (find-package "LISP"))) (excl::enter-new-nicknames old-package (list "COMMON-LISP" "CL"))) ) (defun structure-p (symbol) "Returns T if the given symbol is the name of a structure, NIL otherwise." (let ((the-class-itself (find-class symbol NIL))) (eql (and the-class-itself (class-name (class-of the-class-itself))) 'structure-class))) (defun built-in-class-p (symbol) "Returns T if the given symbol is the name of a built in class, NIL otherwise." (let ((the-class-itself (find-class symbol NIL))) (eql (and the-class-itself (class-name (class-of the-class-itself))) 'built-in-class))) (defun get-lambda-list (symbol) (let ((lam-list (excl:arglist symbol) ;(acl::lambda-list symbol) see spr29023 )) (if (equal lam-list :unknown) (list :unknown) (let ((args (tree-apply #'(lambda (x) (if (symbolp x) (intern (string x)) x)) lam-list))) (labels ((get-first-atom (x) (cond ((symbolp x) x) ((listp x) (get-first-atom (first x))))) ) (loop for arg in args collect (get-first-atom arg))))) ) )
2,514
Common Lisp
.l
68
29
97
0.487624
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a31a32030cbe8b9f28e4747636492a3c391dc3cb145d131d5d77a8bcb0270dae
33,973
[ -1 ]
33,974
symbols.lsp
rwoldford_Quail/source/quail-kernel/basic/symbols.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; symbols.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; list-symbols ;;; list-owned-symbols ;;; list-external-symbols ;;; variable-symbols ;;; function-symbols ;;; nuke-variable-symbols ;;; nuke-function-symbols ;;; quail-cleanup-symbols)) (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(quail-cleanup-symbols push-extension-class import-quail-extension-symbols list-symbols))) ;---------------------------------------------------------------------------------- ;;; symbol finding routines (defun list-symbols (package-name &key (test #'(lambda (s) (declare (ignore s)) t))) (let* ((y nil)) (do-symbols (x (find-package package-name) y) (if (funcall test x) (setf y (list* x y)))))) (defun list-symbols-containing (name-subseq package-name) (let* ((name-subseq (string-downcase (string name-subseq))) (test #'(lambda (s) (search name-subseq (string-downcase (string s)))))) (list-symbols package-name :test test))) ;---------------------------------------------------------------------------------- ;;; owned-symbol finding routines (defun list-owned-symbols (package-name) (let* ((p (find-package package-name)) (test #'(lambda (s) (eq (symbol-package s) p)))) (list-symbols package-name :test test))) (defun list-owned-symbols-containing (name-subseq package-name) (let* ((p (find-package package-name)) (name-subseq (string-downcase (string name-subseq))) (test #'(lambda (s) (and (eq (symbol-package s) p) (search name-subseq (string-downcase (string s))))))) (list-symbols package-name :test test))) ;---------------------------------------------------------------------------------- ;;; external-symbol (which are always owned) finding routines (defun list-external-symbols (package-name &key (test #'(lambda (s) (declare (ignore s)) t))) (let* ((y nil)) (do-external-symbols (x (find-package package-name) y) (if (funcall test x) (setf y (list* x y)))))) (defun list-external-symbols-containing (name-subseq package-name) (let* ((name-subseq (string-downcase (string name-subseq))) (test #'(lambda (s) (search name-subseq (string-downcase (string s)))))) (list-external-symbols package-name :test test))) ;---------------------------------------------------------------------------------- ;;; filters for various types of symbols (defun variable-symbols (list-of-symbols) (let* ((vsymbolp (mapcar #'boundp list-of-symbols))) (list-if-t list-of-symbols vsymbolp))) (defun function-symbols (list-of-symbols) (let* ((fsymbolp (mapcar #'fboundp list-of-symbols))) (list-if-t list-of-symbols fsymbolp))) ;---------------------------------------------------------------------------------- ;;; nuking various types of symbols in current package (defun nuke-variable-symbols (list-of-symbols) (let ((vsymbols (variable-symbols list-of-symbols))) (mapcar #'makunbound vsymbols))) (defun nuke-function-symbols (list-of-symbols) (let ((fsymbols (function-symbols list-of-symbols))) (mapcar #'makunbound fsymbols))) ;---------------------------------------------------------------------------------- (defun quail-cleanup-symbols () (let ((z-symbols (list-owned-symbols 'z))) (nuke-variable-symbols z-symbols) (nuke-function-symbols z-symbols) (mapcar #'unintern z-symbols)) nil) ;---------------------------------------------------------------------------------- (defvar *extension-symbols*) (eval-when (:load-toplevel :execute) (setf *extension-symbols* nil)) (defun push-extension-symbols (&rest symbols) (declare (special *extension-symbols*)) (loop for symbol in symbols do (pushnew symbol *extension-symbols*))) ;; Remark (Greg Anglin 93 12): this should really use mop-<system>.lisp or whatever ;; (defun push-extension-class (class-name) (let (slot-names) #+:pcl (let* ((wrapper (progn (make-instance class-name) ;; otherwise pcl::wrapper will be NIL (slot-value (find-class class-name) 'pcl::wrapper)))) (if wrapper (setf slot-names (elt wrapper 9)) (warn "Wrapper in class ~S is nil, even after a make-instance." class-name))) #+:ccl-2 (let* ((direct-slots (progn (make-instance class-name) ;; might be a good test, for now (slot-value (find-class class-name) 'ccl::direct-slots)))) (setf slot-names (cdr (mapcar #'first direct-slots)))) #+(and :aclunix (not :aclpc)) (let* ((direct-slots (clos::class-direct-slots (find-class class-name)))) (setf slot-names (mapcar #'(lambda (slot-def) (slot-value slot-def 'clos::name)) direct-slots))) (apply #'push-extension-symbols class-name slot-names))) ;;; this routine imports symbols useful in extending z. ;;; Typical usage: ;;; (def-package :neat-new-package) ;;; (in-package :neat-new-package) ;;; (eval-when (compile load) ;;; (zk:import-quail-extension-symbols 'quail-kernel::quail-kernel :neat-new-package) ;;; (zk:import-quail-extension-symbols 'zffi::zffi :neat-new-package) ;;; ... etc ... ;;; ) (defun import-quail-extension-symbols (from-package to-package) (import (variable-symbols (list-owned-symbols from-package)) to-package) (import (function-symbols (list-owned-symbols from-package)) to-package) (import *extension-symbols* to-package) (import (list-symbols-containing "path-" "MAKE") to-package)) #| ;;; Commented out by Greg Anglin during Allegro port, Dec '93. ;;; I wonder how much of this file is really necessary now that we have ;;; the -package.lisp files?? ;;; Get the path- functions now for the quail-kernel package #-:ccl-1 ;; ccl-1 seems to have trouble with these ... (import (list-symbols-containing "path-" "MAKE") "quail-kernel") |#
6,927
Common Lisp
.l
143
40.972028
91
0.530533
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f7a318ba2af69c3f3f8aa76757e25fdedc6974c4a704e5976d2e0876301ce548
33,974
[ -1 ]
33,975
utility-sblx.lsp
rwoldford_Quail/source/quail-kernel/basic/utility-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; utility-sblx.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1991. ;;; R.W. Oldford 1991 ;;; M.E. Lewis 1991 ;;; Greg Anglin 1993, -excl port ;;; ;;;-------------------------------------------------------------------------------- ;;; A copy of utility-excl.lisp <= *** ;;; There is no EXCL package in aclwin ;;; ;;; Includes: ;;; ;;; get-lambda-list (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(structure-p built-in-class-p))) #+:cl-1(eval-when (:compile-toplevel :load-toplevel :execute) "A gimmick to accomodate CLtL 1. The package ~ containing the LISP language is called lisp in CLtL 1 but ~ common-lisp in CLtL 2. Here LISP is given the same ~ nicknames." (let ((old-package (find-package "LISP"))) (excl::enter-new-nicknames old-package (list "COMMON-LISP" "CL"))) ) (defun structure-p (symbol) "Returns T if the given symbol is the name of a structure, NIL otherwise." (let ((the-class-itself (find-class symbol NIL))) (eql (and the-class-itself (class-name (class-of the-class-itself))) 'structure-class))) (defun built-in-class-p (symbol) "Returns T if the given symbol is the name of a built in class, NIL otherwise." (let ((the-class-itself (find-class symbol NIL))) (eql (and the-class-itself (class-name (class-of the-class-itself))) 'built-in-class))) (defun get-lambda-list (symbol) (format t "~%symbol is ~s of type ~s " symbol (type-of symbol)) (let ((lam-list (sb-introspect:function-lambda-list symbol);(acl::lambda-list symbol) see spr29023 )) (if (equal lam-list :unknown) (list :unknown) (let ((args (tree-apply #'(lambda (x) (if (symbolp x) (intern (string x)) x)) lam-list))) (labels ((get-first-atom (x) (cond ((symbolp x) x) ((listp x) (get-first-atom (first x))))) ) (loop for arg in args collect (get-first-atom arg))))) ) )
2,524
Common Lisp
.l
68
30.264706
96
0.509002
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2f7a4c49a014a5feea72665f2994ef8f70d167d48cd390e70c53cee787029b0a
33,975
[ -1 ]
33,977
synonym.lsp
rwoldford_Quail/source/quail-kernel/basic/synonym.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; synonym.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1989, 1990, 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- ;;; ;;; Includes: ;;; make-synonym ;;; alias ;;; _ ;;; ** ;;; ^ ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-synonym))) ;;;---------------------------------------------------------------------------- ;;; ;;; MAKE-SYNONYM: ;;; ;;; A useful but potentially dangerous macro that lets the user ;;; introduce synonyms for existing or user defined functions. ;;; ;;; Danger can be eliminated by disallowing redefinition of existing ;;; functions. ;;; ;;;---------------------------------------------------------------------------- (defmacro make-synonym (&key old new (warn t)) "Makes the argument new a synonym for the argument old. ~ If warn is T (the default), the user is warned when new is ~ already defined." (declare (special *quail-query-io*)) (if (and (fboundp new) (or (symbol-function new) (macro-function new)) warn) ;; then (if (quail-yes-or-no-p "WARNING: ~S is already a defined function! ~%~ Are you sure you want to replace its definition~%~ by that of ~S?" new old) ;; if yes, then `(defmacro ,new (&rest args) ,(format nil "~a is simply a synonym for ~a. See make-synonym." new old) (append (quote (,old)) args)) ;; else (format *quail-query-io* "Aborted. ~S is not redefined." new) ) ;; else `(defmacro ,new (&rest args) ,(format nil "~a is simply a synonym for ~a. See make-synonym." new old) (append (quote (,old)) args))))
2,260
Common Lisp
.l
63
29.222222
81
0.431934
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b4f42fcee2b0ac1fca07fa9f3570ced7ab4ab8045d139df2bc777b0117b43875
33,977
[ -1 ]
33,978
open-mixin.lsp
rwoldford_Quail/source/quail-kernel/basic/open-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; open-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(with-open-quail-objects with-faster-eref-open-objects))) ;;; Some quail-objects require allocation of space which is not lisp space. ;;; Non-lisp space is NOT automatically garbage collected by lisp. ;;; ;;; The two main examples of this in quail are objects which create storage ;;; as files (eg. class file-matrix), and those which allocate storage ;;; in static space in non-lisp memory (eg. foreign-array). ;;; ;;; We use the general terminology from the specific case of files to describe ;;; the state of such a quail-object. We say the object is 'open' if the non-lisp ;;; space has been allocated and some handle to the space is being maintained by ;;; the lisp object, 'closed' otherwise. In the case of files, the handle is the ;;; open file-stream associated with the object, and in the case of foreign ;;; arrays, the handle is a pointer to static space (ie. not maintained by the ;;; lisp garbage collector). ;;; ;;; It is undesirable for the garbage collector to throw away an open ;;; quail-object. If this happened, the system would keep the storage allocated ;;; but there would remain no way to free it since the handle to ;;; the space had been lost along with the trashed quail-object. In the case of ;;; files, an extra file which perhaps should be destroyed will remain on ;;; disk, and in the case of foreign arrays, static storage space which ;;; should be free remains allocated. ;;; ;;; The intention is that Quail functions should look something like the following: ;;; ;;; (defun z-function-1 (obj-1 obj-2 obj-3) ;;; (with-open-quail-objects (obj-1 obj-2 obj-3 ;;; :keep result1 result2 ;;; :temp temp) #'predicate ;;; (setf temp (z-function-2 obj-1 obj-2)) ;;; (setf result1 (z-function-3 temp obj-3)) ;;; (setf result2 (z-function-4 obj-3 result1)) ;;; (values result1 result2))) ;;; ;;; The function predicate should return t for objects for which this is an ;;; appropriate place to use the open/close. ;;; An alternate syntax, more commonly used perhaps, uses a type or list ;;; of types in place of the predicate. Any object which satisfies ;;; typep with any one of these types is opened. ;;; ;;; The function #'identity may be ;;; used to always return t; objects for which open/close is meaningless will ;;; be unaffected. However, it should be noted that there *are* situations ;;; when one might want to open file-matrix instances, but not foreign-array ;;; instances, for example. ;;; ;;; For this reason there are innocuous mixin classes ;;; which can be used to specify certain types of opening behavior to the ;;; with-open-... series of macros. The ultimate ;;; opening class is quail-open-mixin, which can be used as a superclass to other ;;; mixins to specify opening behavior. The subclass faster-eref-open-mixin ;;; is used as ;;; a superclass of objects which when open are faster to eref. The subclass ;;; foreign-mixin specifies a class which knows how to open to an object with ;;; foreign space allocated. ;;; ;;; Notice :keep and :temp create the ;;; the objects they mention; one can use these objects as if they had been ;;; bound by a let form where the with-open-quail-objects appears (in fact, ;;; the expansion of the macro does exactly that!). ;;; ;;; One idea here is to ensure that no function returns an open quail-object ;;; unless all of the quail-objects provided to it in its arguments are open. ;;; If code adheres to this style, closed quail-objects can be used at the top-level ;;; without fear of creating spurious open quail-objects. ;;; ;;; The class quail-open-state-mixin provides a slot which maintains the current open ;;; status of the object. If open-state is 0, then the object is 'closed'. ;;; If open-state is greater than 0, this indicates the number of times the ;;; object needs to be logically closed before being physically closed. ;;; ;;; ***** VERY IMPORTANT: ;;; The result of _any_ intermediate calculation performed which may create ;;; an object for which open/close is meaningful MUST be bound to a :temp ;;; or a :keep variable. ;;; ***** ;;; ;;; All :temp variables are destroyed when the with-open-quail-objects is complete, ;;; and should never be returned by the body of the macro. All :keep variables ;;; are logically closed once so that they may be returned by the body. A z-function ;;; that returns an object should ensure that the object, if created open, has ;;; an open-state equal to the _minimum_ open-state of the objects passed to the ;;; function. If not required, :keep or :temp may be omitted. ;;; ;;; Most Z internal functions and generic functions are written assuming that ;;; they may be called with open quail-objects. THIS STYLE IS RECOMMENDED AS A ;;; PRECAUTION in all functions which create quail-objects. (defclass quail-open-mixin () ()) (defclass quail-open-state-mixin (quail-open-mixin proto-mixin) ((open-state :accessor open-state-of :initarg :open-state))) ; fill-unbound-slots o/w does init ;; for classes for which eref is always faster if the object is open eg. file-matrix ;; Note: faster-eref-open-mixin is NOT a subclass of quail-open-state-mixin ... there ;; are classes which open by opening the contents of a slot, which contents are an ;; instance of a subclass of quail-open-state-mixin. (defclass faster-eref-open-mixin (quail-open-mixin) ()) (push-extension-class 'quail-open-mixin) (push-extension-class 'quail-open-state-mixin) (push-extension-class 'faster-eref-open-mixin) ;;; ; VERY IMPORTANT: ; - fill-unbound-slots sets the open-state of a new instance to the minimum ; open-state of all proto objects with quail-open-state-mixin, defaulting to 0 (closed). ; - fill-unbound-slots is called by shared-initialize :after ((self quail-object)), ; hence quail-open-state-mixin must be mixed in with a subclass of quail-object to use ; this method. ; - then other shared-initialize :after methods MUST use this info to set up ; a consistent open/closed state for the instance. ; (defmethod fill-unbound-slots :after ((self quail-open-state-mixin)) (with-slots ((protos proto)) self (setf protos (remove-if-not #'(lambda (proto) (typep proto 'quail-open-state-mixin)) protos)) (if (fill-slot-p self 'open-state) (let* ((open-states (mapcar #'open-state-of protos)) (min-open-state (if (null open-states) 0 (apply #'min open-states)))) (setf (slot-value self 'open-state) min-open-state))))) ;;; ; DEFGENERICS for quail-open-object, etc. ; (defgeneric quail-open-object (arg)) (defgeneric quail-close-preserve-object (arg)) (defgeneric quail-close-destroy-object (arg)) (defgeneric quail-close-physically-object (arg)) ;;; ; DEFMETHODs for class t ; (defmethod quail-open-object ((self t)) ;; do nothing ) (defmethod quail-close-preserve-object ((self t)) ;; do nothing ) (defmethod quail-close-destroy-object ((self t)) ;; do nothing ) (defmethod quail-close-physically-object ((self t)) ;; do nothing ) ;;; ; DEFMETHODs for class quail-open-state-mixin ; ;; If there is no overriding primary method from a more specific class, ;; then it's an oversight ... call it an error, forcing the ;; definition of such a primary method. (defmethod quail-open-object ((self quail-open-mixin)) (missing-method 'quail-open-object self)) (defmethod quail-close-preserve-object ((self quail-open-mixin)) (missing-method 'quail-close-preserve-object self)) (defmethod quail-close-destroy-object ((self quail-open-mixin)) (missing-method 'quail-close-destroy-object self)) (defmethod quail-close-physically-object ((self quail-open-mixin)) (missing-method 'quail-close-physically-object self)) ;; The :after methods, assuming that the primary methods have done any ;; required physical opening/closing, do the modifications to open-state. ;; ;; Note that since physical modifications have already been done, the ;; debug statements MUST follow the mods to open-state for the object ;; to be consistent. Note also that the debug statements will cause ;; all sorts of difficulties with any objects which must be open ;; in order to print !! #| (eval-when (compile load eval) (pushnew :open-mixin-debug *features*)) |# (defmethod quail-open-object :after ((self quail-open-state-mixin)) (with-slots (open-state) self (incf open-state) #+:open-mixin-debug (format *quail-terminal-io* "~&Done quail-open-object of ~S, open-state ~S --> ~S" self (1- open-state) open-state))) (defmethod quail-close-preserve-object :after ((self quail-open-state-mixin)) (with-slots (open-state) self #-:open-mixin-debug (if (> open-state 0) (decf open-state)) #+:open-mixin-debug (let ((prev-state open-state)) (if (> open-state 0) (decf open-state)) (format *quail-terminal-io* "~&Doing quail-close-preserve-object of ~S, open-state ~S --> ~S" self prev-state open-state)) )) (defmethod quail-close-destroy-object :after ((self quail-open-state-mixin)) (with-slots (open-state) self #-:open-mixin-debug (setf open-state 0) #+:open-mixin-debug (let ((prev-state open-state)) (setf open-state 0) (format *quail-terminal-io* "~&Doing quail-close-destroy-object of ~S, open-state ~S --> ~S **destroy**" self prev-state open-state)) )) (defmethod quail-close-physically-object :after ((self quail-open-state-mixin)) (with-slots (open-state) self #-:open-mixin-debug (setf open-state 0) #+:open-mixin-debug (let ((prev-state open-state)) (setf open-state 0) (format *quail-terminal-io* "~&Doing quail-close-physically-object of ~S, open-state ~S --> ~S" self prev-state open-state)) )) ;;; ; quail-open, quail-close-destroy, quail-close-preserve, and quail-close-physically ; (defun quail-open (objects &optional (predicate #'identity)) (loop for object in objects do (if (funcall predicate object) (quail-open-object object)))) (defun quail-close-preserve (objects &optional (predicate #'identity)) (loop for object in objects do (if (funcall predicate object) (quail-close-preserve-object object)))) (defun quail-close-destroy (objects &optional (predicate #'identity)) (loop for object in objects do (if (funcall predicate object) (quail-close-destroy-object object)))) (defun quail-close-physically (objects &optional (predicate #'identity)) (loop for object in objects do (if (funcall predicate object) (quail-close-physically-object object)))) ;;; ; Other functions ; ;;; quail-open-p-object returns T if instance is open. Objects which are not instances ;;; of a subclass of quail-open-mixin are deemed always to be open. (defmethod quail-open-p-object ((self t)) t) (defmethod quail-open-p-object ((self quail-open-state-mixin)) (with-slots (open-state) self (> open-state 0))) ;;; originally-open-p-object returns T if instance was open *before* the previous ;;; quail-open call, NIL if it was closed. (defmethod originally-open-p-object ((self t)) t) (defmethod originally-open-p-object ((self quail-open-state-mixin)) (with-slots (open-state) self (> open-state 1))) (defvar *create-closed-only*) (setf *create-closed-only* nil) (defun quail-all-originally-open-p (&rest args) (declare (special *create-closed-only*)) (if *create-closed-only* nil (all-non-nil-p (mapcar #'originally-open-p-object args)))) ;;; ; Predicates for with-open-quail-objects ; (defmacro one-of-these-types-p (object types) (let ((type (gensym)) (pred (gensym))) `(let ((,pred nil)) (loop for ,type in ,types until (setf ,pred (typep ,object ,type))) ,pred))) ;;; The with-open-quail-objects macro (defun quail-open-interpret (objects) (let (env-objects list-objects keep-objects temp-objects (state :env)) (loop for obj in objects do (if (keywordp obj) (setf state obj) (case state (:env (push obj env-objects)) (:list (push obj list-objects)) (:keep (push obj keep-objects)) (:temp (push obj temp-objects)) (t (quail-error "~S is not a permitted keyword for with-open-quail-objects." state))))) (values env-objects list-objects keep-objects temp-objects))) (defmacro with-open-quail-objects (objects predicate-or-types &body body) (let* ((result (gensym)) (thru-safely (gensym)) (predicate (gensym)) (predicate-body (cond ((symbolp predicate-or-types) `(function (lambda (x) (typep x (quote ,predicate-or-types))))) ((and (listp predicate-or-types) (not (eq (car predicate-or-types) 'function))) `(function (lambda (x) (one-of-these-types-p x (quote ,predicate-or-types))))) (t `(eval ,predicate-or-types))))) (multiple-value-bind (env-objects list-objects keep-objects temp-objects) (quail-open-interpret objects) `(let (,result (,thru-safely nil) ,@keep-objects ,@temp-objects (,predicate ,predicate-body)) (unwind-protect (progn ,@(if (or env-objects list-objects) (list `(quail-open (append (list ,@env-objects) ,@list-objects) ,predicate))) (setf ,result (multiple-value-list (progn ,@body))) (setf ,thru-safely t) (values-list ,result)) ,@(if (or env-objects keep-objects list-objects) (list `(if ,thru-safely (quail-close-preserve (append (list ,@env-objects ,@keep-objects) ,@list-objects) ,predicate) (quail-close-physically (append (list ,@env-objects ,@keep-objects) ,@list-objects) ,predicate)))) ,@(if (or temp-objects) (list `(quail-close-destroy (list ,@temp-objects) ,predicate)))))))) (defmacro with-faster-eref-open-objects (objects &body body) `(with-open-quail-objects ,objects faster-eref-open-mixin ,@body))
16,002
Common Lisp
.l
350
38.668571
122
0.628281
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
eee262d446723d24b71648544904d15804e42415545cd6f10d0325c1a84680f6
33,978
[ -1 ]
33,979
special-vars.lsp
rwoldford_Quail/source/quail-kernel/basic/special-vars.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; special-vars.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1990 statistical computing laboratory, university of waterloo ;;; ;;; ;;; authors: ;;; r.w. oldford 1990. ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; miscellaneous quail system constants ;;; ;;; in this file a number of quail system constants are defined. ;;; note: not all system constants are defined here. only those which are not ;;; more reasonably placed in other files. ;;; ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*small-number-of-iterations* *reasonable-number-of-iterations* *max-reasonable-number-of-iterations* ))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; handy constants to use programmatically to ;;; determine number of iterations to perform before ;;; asking the user for more information. ;;; (defvar *small-number-of-iterations* 10) (defvar *reasonable-number-of-iterations* 100) (defvar *max-reasonable-number-of-iterations* 1000)
1,351
Common Lisp
.l
36
34.527778
128
0.493457
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b0f5d0cde2825d2e882164e3d0a245f9bc142ccf380b2e511d6bcc7272aa74b8
33,979
[ -1 ]
33,980
seq.lsp
rwoldford_Quail/source/quail-kernel/basic/seq.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; seq.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991 -1992, 1994. ;;; M.E. Lewis 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(iseq seq))) ;;; functions that produce a sequence of numbers ;;; ;;; (defun iseq (s &optional e) "Returns a list of integers from s to e. ~ If e is not specified, from 0 to s minus 1. ~ If e is less than s the count is down from s to e. ~ (:see-also seq)" (let ((start (if e s 0)) (end (if e e (- s 1)))) (if (< end start) (loop for i from start downto end collect i) (loop for i from start to end collect i)))) (defun seq (from to &optional (by 1)) "Returns a ref-array whose elements are the sequence ~ beginning at the first argument continuing to the second ~ argument in step size specified by the optional third argument ~ (default 1). (:see-also iseq)" (let ((end (truncate (abs (/ (- to from) by))))) (when (< by 0) (quail-error "SEQ: Optional arg by = ~s must be positive!" by)) (array (cond ((= to from) (list to)) ((< to from) (if (= 1 by) (loop for i from 0 to end collect (- from i)) (loop for i from 0 to end collect (- from (* i by))))) ((zerop from) (if (= by 1) (loop for i from 0 to end collect i) (loop for i from 0 to end collect (* i by)))) (t (if (= by 1) (loop for i from 0 to end collect (+ i from)) (loop for i from 0 to end collect (+ from (* i by))))) ) :dimensions (list (+ 1 end)))))
2,156
Common Lisp
.l
58
29.827586
80
0.459836
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cb35d55b73c35bd58b169e14f5cd786f609461c9eece3caa447f3b2dbab7f3aa
33,980
[ -1 ]
33,981
quail-object.lsp
rwoldford_Quail/source/quail-kernel/basic/quail-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; mel, rwo touched in places ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; quail-object ;;; proto-object ;;; quail-class-of ;;; quail-class-name ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(quail-object))) (defclass quail-object () ()) (push-extension-class 'quail-object) ;;; Sometimes quail-objects are not what they appear to be. These following ;;; generic functions can be useful in clearing this up. The major ;;; application of this is for dimensioned-ref-objects. (defgeneric quail-class-of (the-instance)) (defmethod quail-class-of ((self t)) (class-of self)) (defgeneric quail-class-name (the-instance)) (defmethod quail-class-name ((self t)) (class-name (quail-class-of self)))
1,325
Common Lisp
.l
36
32.944444
84
0.49166
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dea6b3019fb00ad59205f4c9a6140cade966636943485dee05ca657f895b9a70
33,981
[ -1 ]
33,985
function-info-sblx.lsp
rwoldford_Quail/source/quail-kernel/mop/function-info-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; function-info-sblx.lisp ;;; ;;; G.W.Bennett 2017 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail-kernel) (defun function-name (f) (declare (ignore f)) NIL)
382
Common Lisp
.l
13
27.384615
85
0.240437
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
511614a58842e048703e424861dbf51ad01d025ed7a1c9bb81c6cb36081f331a
33,985
[ -1 ]
33,986
mop-sblx.lsp
rwoldford_Quail/source/quail-kernel/mop/mop-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mop-sblx.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1994 ;;; Greg Anglin 1992 ;;; Greg Bennett 2017 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; BASED on mop-excl.lisp ;;; ;;; Meta-Object protocol interface ;;; ;;; This file imports to quail-kernel fundamental functions which I think are ;;; X3J13-proposed for the standard MOP, and exports them from quail-kernel, ;;; along with some older (perhaps redundant, now) covers for them. ;;; ;;; DGA ... upon arrival of MCL 2.0 final, Oct 92. ;;; ;;; The following are implemented in Allegro CL 4.1 and are imported to quail-kernel. ;;; Others are also present, but I haven't grabbed them ... ;;; ;;; y on N shows what aclwin recognises gwb 042097 ;;; ;;; class-direct-subclasses ;;; class-direct-superclasses ;;; class-precedence-list ;;; class-prototype ;;; class-direct-slots ;;; class-slots ;;; specializer-direct-methods ;;; specializer-direct-generic-functions ;;; generic-function-methods ;;; method-function ;;; method-generic-function ;;; method-specializers ;;; slot-definition-name ;;; #| ;;; Debugging stuff ? ;;; 28oct2005 gwb ;;; ACL7.0 has moved function-information to the sys package ;;; here we import it to common-lisp and common-lisp-user, ;;; then export it from both before proceeding as before. ;;; This has to be done early in the LOAD of Quail. (in-package "COMMON-LISP") (import 'sys::function-information) (export 'function-information) (in-package "COMMON-LISP-USER") (import 'sys::function-information) (export 'function-information) ;;; 28oct2005 |# (in-package :quail-kernel) ;; We're breaking the rules by putting import before export, so we ;; have to be careful and use eval-when. ;;; In aclwin there is no CLOS package <= ***** (eval-when (:compile-toplevel :load-toplevel :execute) (import '(sb-mop::class-direct-subclasses sb-mop::class-direct-superclasses sb-mop::class-direct-slots sb-mop::specializer-direct-methods sb-mop::specializer-direct-generic-functions sb-mop::generic-function-methods sb-mop::method-function sb-mop::method-generic-function sb-mop::method-specializers sb-mop::slot-definition-readers sb-mop::slot-definition-writers sb-mop::slot-definition-initargs sb-mop::slot-definition-initform sb-mop::slot-definition-type sb-mop::slot-definition-name sb-mop::slot-definition-allocation sb-mop::slot-definition-initfunction) )) (eval-when (:compile-toplevel :load-toplevel :execute) (shadow '(sb-mop::class-precedence-list sb-mop::class-prototype sb-mop::class-slots )) ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-direct-subclasses class-direct-superclasses class-direct-slots specializer-direct-methods specializer-direct-generic-functions generic-function-methods method-function method-generic-function method-specializers slot-definition-readers slot-definition-writers slot-definition-initargs slot-definition-initform slot-definition-type slot-definition-name slot-definition-allocation slot-definition-initfunction) ) ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-p direct-slots generic-function-p reader-method-p writer-method-p))) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collect-methods collect-accessors collect-slot-definitions ))) ;;; Had to ensure that the class was finalized before calling ;;; ;;; Added for the benefit of ACL6.0 for right-button problem (sb-ext:with-unlocked-packages (:sb-mop) (defmethod sb-mop::finalize-inheritance ((thing T)) )) (defmethod class-precedence-list ((thing standard-class)) (unless (sb-mop::class-finalized-p thing) (sb-mop::finalize-inheritance thing)) (sb-mop::class-precedence-list thing) ) ;; Added 02DEC98 for errors on right-button - see porting.lsp [57] (defmethod class-precedence-list ((thing T)) (unless (sb-mop::class-finalized-p thing) (sb-mop::finalize-inheritance thing)) (if (sb-mop::class-finalized-p thing) (sb-mop::class-precedence-list thing) (remove thing (sb-mop::compute-class-precedence-list thing)) ) ) (defmethod class-prototype ((thing standard-class)) (unless (sb-mop::class-finalized-p thing) (sb-mop::finalize-inheritance thing)) (sb-mop::class-prototype thing) ) (defmethod class-slots ((thing standard-class)) (unless (sb-mop::class-finalized-p thing) (sb-mop::finalize-inheritance thing)) (sb-mop::class-slots thing) ) #| ;;; There is sb-pcl::specializer-direct-methods (specialilzer) ;;; is this what is needed ? (defmethod class-methods ((thing standard-class)) (unless (sb-mop::class-finalized-p thing) (sb-mop::finalize-inheritance thing)) (cg::all-specializer-direct-methods thing) ) |# (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-prototype class-precedence-list class-slots class-direct-methods class-methods ) ) ) ;;; ----------------------------- (defun class-p (arg) "Return T if argument is a class." (typep arg 'standard-class)) (defun generic-function-p (arg) "Return T if argument is a generic-function." (typep arg 'generic-function)) (defgeneric method-name (method-object) (:documentation "Returns the name of the method.")) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod method-name ((thing sb-mop::standard-method)) (let ((gf (slot-value thing 'generic-function)) ) (when gf (slot-value gf 'sb-mop::name)) ) )) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod method-name ((thing sb-mop::standard-writer-method)) (let ((gf (slot-value thing 'generic-function)) name) (when gf (setf name (slot-value gf 'sb-mop::name))) (when (and name (listp name)) (setf name (second name))) name) )) (defun reader-method-p (method) "Tests whether method is a directly defined reader method." (let ((specializers (method-specializers method))) (and (= (length specializers) 1) (member method (slot-definition-readers (first specializers)) :test #'eq)))) (defun writer-method-p (method) "Tests whether method is a directly defined writer method." (let ((specializers (method-specializers method))) (and (= (length specializers) 2) (member method (slot-definition-readers (first specializers)) :test #'eq)))) (defmethod class-direct-class-slots ((self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-direct-slots self) when (not (eq (sb-mop::slot-definition-allocation slot) :instance)) collect slot)) (defmethod class-class-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-slots self) when (not (eq (sb-mop::slot-definition-allocation slot) :instance)) collect slot)) (defmethod class-instance-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-slots self) when (eq (sb-mop::slot-definition-allocation slot) :instance) collect slot)) (defmethod class-direct-instance-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-direct-slots self) when (eq (sb-mop::slot-definition-allocation slot) :instance) collect slot)) ;;; ;;; The following are mop specialized methods to prevent breakage ;;; (in the documentation system anyway) when ``classes'' like T ;;; are encountered where it makes no sense for them to have slots etc. ;;; (defmethod class-direct-class-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-class-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-instance-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-direct-instance-slots ((Self T)) "Call makes little sense. Returns NIL." ()) ;;; ;;; ;;; (defun collect-methods (fun) "Collects all the methods associated with the generic-function fun, ~ organizes these into an association list whose keys are the qualifier ~ lists for each method and whose values are the list of methods having ~ those qualifiers. Those methods which do not have qualifiers, i.e. ~ whose qualifer list is NIL, will be stored with key (\:primary)." (let ((methods (generic-function-methods (cond ((symbolp fun) (symbol-function fun)) (T fun)))) (result NIL) qualifiers ) (loop for method in methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers result :test #'equal) (push method (cdr (assoc qualifiers result :test #'equal))) (setf result (acons qualifiers (list method) result)))) result)) (defun collect-accessors (class) "Collects all the accessor methods associated with the class class, ~ organizes these into an association list whose keys are either ~ :readers or :writers. ~ The value associated with each key is a list of lists of reader or ~ writer methods respectively for all slots of class. The first element ~ in each value list is the list of method qualifiers; ~ The remaing elements are the method-objects themselves." (cond ((symbolp class) (setf class (find-class class))) ((stringp class) (setf class (find-class (with-input-from-string (s class) (read s))))) ) (let ((reader-methods (slot-definition-readers class)) (writer-methods (slot-definition-writers class)) qualifiers reader-list writer-list) (loop for method in reader-methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers reader-list :test #'equal) (push method (cdr (assoc qualifiers reader-list :test #'equal))) (setf reader-list (acons qualifiers (list method) reader-list)))) (loop for method in writer-methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers writer-list :test #'equal) (push method (cdr (assoc qualifiers writer-list :test #'equal))) (setf writer-list (acons qualifiers (list method) writer-list)))) (cond ((and reader-list writer-list) (list (cons :readers reader-list) (cons :writers writer-list)) ) (reader-list (list (cons :readers reader-list))) (writer-list (list (cons :writers writer-list))) (T NIL)) ) ) (defun collect-slot-definitions (class) "Collects all the slot-definitions associated with the class class, ~ organizes these into an association list whose keys are one of ~ :class-slots :instance-slots :direct-class-slots and :direct-instance-slots. ~ The value associated with each key is a list of slot-definitions of that type ~ for this class. ~ " (cond ((symbolp class) (setf class (find-class class))) ((stringp class) (setf class (find-class (with-input-from-string (s class) (read s))))) ) (let ((direct-class-slots (class-direct-class-slots class)) (direct-instance-slots (class-direct-instance-slots class)) (instance-slots (class-instance-slots class)) (class-slots (class-class-slots class)) ) (setf class-slots (cons :class-slots class-slots)) (setf instance-slots (cons :instance-slots instance-slots)) (setf direct-class-slots (cons :direct-class-slots direct-class-slots)) (setf direct-instance-slots (cons :direct-instance-slots direct-instance-slots)) (list class-slots instance-slots direct-class-slots direct-instance-slots))) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-readers ((thing T)) NIL)) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-writers ((thing T)) NIL)) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-readers ((thing standard-class)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'sb-mop::standard-reader-method) collect method)))) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-writers ((thing standard-class)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'sb-mop::standard-writer-method) collect method)))) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-readers ((thing sb-mop:standard-effective-slot-definition)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'sb-mop::standard-reader-method) collect method)))) (sb-ext:with-unlocked-packages (:sb-mop) (defmethod slot-definition-writers ((thing sb-mop:standard-effective-slot-definition)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'sb-mop::standard-writer-method) collect method))))
14,502
Common Lisp
.l
379
32.279683
89
0.645881
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
23041b19e70914329871e4fe62128d6081ad2efa1ecdc0ddc94605bed9cb373d
33,986
[ -1 ]
33,988
mixin-to-quail.lsp
rwoldford_Quail/source/quail-kernel/mop/mixin-to-quail.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mixin-to-quail.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 '(add-mixin-to-quail-object remove-mixin-from-quail-object))) (defun add-mixin-to-quail-object (super) "Add super to the front of the supers list of the ~ class quail-object. The value of the argument super ~ must be a symbol naming the class to be added." (let (supers) (setf supers (cons super (loop for s in (class-direct-superclasses (find-class 'quail-object)) collect (class-name s)) )) (eval `(defclass quail-object ,supers () (:documentation "A class which gathers the many different mixins which together ~ define a quail-object."))) ) ) (defun remove-mixin-from-quail-object (super) "Removes super from the supers list of the ~ class quail-object. The value of the argument super ~ must be a symbol naming the class to be removed." (let (supers) (setf supers (remove super (loop for s in (class-direct-superclasses (find-class 'quail-object)) collect (class-name s)) )) (eval `(defclass quail-object ,supers () (:documentation "A class which gathers the many different mixins which together ~ define a quail-object."))) ) )
1,987
Common Lisp
.l
58
26.534483
91
0.491855
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
71c8efdf2cb8f4198184177c2d58684af1f1e2b6eaa7c9d253727a9880819905
33,988
[ -1 ]
33,990
rlog.mop
rwoldford_Quail/source/quail-kernel/mop/rlog.mop
RCS file: RCS/function-info-excl.lsp,v Working file: function-info-excl.lsp head: 1.1 branch: locks: strict rwoldford: 1.1 access list: symbolic names: keyword substitution: kv total revisions: 1; selected revisions: 1 description: initial check in. ---------------------------- revision 1.1 locked by: rwoldford; date: 1994/08/13 13:59:03; author: rwoldford; state: Exp; Initial revision ============================================================================= RCS file: RCS/function-info-mcl.lsp,v Working file: function-info-mcl.lsp head: 1.1 branch: locks: strict rwoldford: 1.1 access list: symbolic names: keyword substitution: kv total revisions: 1; selected revisions: 1 description: initial check in. ---------------------------- revision 1.1 locked by: rwoldford; date: 1994/08/13 13:59:03; author: rwoldford; state: Exp; Initial revision ============================================================================= RCS file: RCS/function-info-pc.lsp,v Working file: function-info-pc.lsp head: 1.1 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 1; selected revisions: 1 description: Version for ACL inder W95 ---------------------------- revision 1.1 date: 1998/08/31 14:51:40; author: gwbennet; state: Exp; Initial revision ============================================================================= RCS file: RCS/mixin-to-quail.lsp,v Working file: mixin-to-quail.lsp head: 1.2 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 2; selected revisions: 2 description: Seems that this is the initial check in! ---------------------------- revision 1.2 date: 1998/01/09 19:06:26; author: rwoldfor; state: Exp; lines: +2 -2 direct-superclasses --> class-direct-super-classes ---------------------------- revision 1.1 date: 1994/06/20 14:48:36; author: rwoldford; state: Exp; Initial revision ============================================================================= RCS file: RCS/mop-excl.lsp,v Working file: mop-excl.lsp head: 1.6 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 6; selected revisions: 6 description: Seems that this is the initial check in! ---------------------------- revision 1.6 date: 1994/10/27 18:21:54; author: rwoldford; state: Exp; lines: +2 -2 Replaced (find-class 'foo) by (class-of thing). 2 places. ---------------------------- revision 1.5 date: 1994/08/26 21:01:24; author: rwoldford; state: Exp; lines: +172 -108 Added something from Catherine. ---------------------------- revision 1.4 date: 1994/06/24 14:56:28; author: rwoldford; state: Exp; lines: +40 -0 Added methods for self T for methods dealing with slots etc. to prevetn breakage. ---------------------------- revision 1.3 date: 1994/06/22 19:23:45; author: rwoldford; state: Exp; lines: +4 -1 Collect-methods will accept a symbol or a function as its arg. ---------------------------- revision 1.2 date: 1994/06/20 14:52:03; author: rwoldford; state: Exp; lines: +22 -2 Added collect-methods ---------------------------- revision 1.1 date: 1994/06/20 14:48:07; author: rwoldford; state: Exp; Initial revision ============================================================================= RCS file: RCS/mop-mcl.lsp,v Working file: mop-mcl.lsp head: 1.6 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 6; selected revisions: 6 description: Seems that this is the initial check in! ---------------------------- revision 1.6 date: 1994/10/27 18:21:54; author: rwoldford; state: Exp; lines: +3 -3 Replaced (find-class 'foo) by (class-of thing). 2 places. ---------------------------- revision 1.5 date: 1994/08/26 21:01:24; author: rwoldford; state: Exp; lines: +292 -137 Added something from Catherine. ---------------------------- revision 1.4 date: 1994/06/24 14:56:28; author: rwoldford; state: Exp; lines: +37 -0 Added methods for self T for methods dealing with slots etc. to prevetn breakage. ---------------------------- revision 1.3 date: 1994/06/22 19:23:45; author: rwoldford; state: Exp; lines: +4 -1 Collect-methods will accept a symbol or a function as its arg. ---------------------------- revision 1.2 date: 1994/06/20 14:52:37; author: rwoldford; state: Exp; lines: +21 -0 Added collect-methods ---------------------------- revision 1.1 date: 1994/06/20 14:47:21; author: rwoldford; state: Exp; Initial revision ============================================================================= RCS file: RCS/mop-pc.lsp,v Working file: mop-pc.lsp head: 1.2 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 2; selected revisions: 2 description: Version of mop-pc May 26 1998 (gwb) ---------------------------- revision 1.2 date: 1999/02/10 16:09:08; author: gwbennet; state: Exp; lines: +153 -123 replaced the entire file ---------------------------- revision 1.1 date: 1998/05/26 17:50:55; author: gwbennet; state: Exp; Initial revision =============================================================================
5,287
Common Lisp
.l
164
30.140244
78
0.58485
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5d4f0f1ff7d284c85fbb69c7b91e85f59b35eb1c0acbf5e9c0c40310c6f1a6a7
33,990
[ -1 ]
33,992
mop-pc.lsp
rwoldford_Quail/source/quail-kernel/mop/mop-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mop-pc.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1988-1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1994 ;;; Greg Anglin 1992 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; BASED on mop-excl.lisp ;;; ;;; Meta-Object protocol interface ;;; ;;; This file imports to quail-kernel fundamental functions which I think are ;;; X3J13-proposed for the standard MOP, and exports them from quail-kernel, ;;; along with some older (perhaps redundant, now) covers for them. ;;; ;;; DGA ... upon arrival of MCL 2.0 final, Oct 92. ;;; ;;; The following are implemented in Allegro CL 4.1 and are imported to quail-kernel. ;;; Others are also present, but I haven't grabbed them ... ;;; ;;; y on N shows what aclwin recognises gwb 042097 ;;; ;;; class-direct-subclasses ;;; class-direct-superclasses ;;; class-precedence-list ;;; class-prototype ;;; class-direct-slots ;;; class-slots ;;; specializer-direct-methods ;;; specializer-direct-generic-functions ;;; generic-function-methods ;;; method-function ;;; method-generic-function ;;; method-specializers ;;; slot-definition-name ;;; ;;; 28oct2005 gwb ;;; ACL7.0 has moved function-information to the sys package ;;; here we import it to common-lisp and common-lisp-user, ;;; then export it from both before proceeding as before. ;;; This has to be done early in the LOAD of Quail. ;(in-package "COMMON-LISP") ;; 12JUN2023 ;(import 'sys::function-information) ;; 12JUN2023 ;(export 'function-information) ;; 12JUN2023 ;(in-package "COMMON-LISP-USER") ;; 12JUN2023 ;(import 'sys::function-information) ;; 12JUN2023 ;(export 'function-information) ;; 12JUN2023 ;;; 28oct2005 (in-package :quail-kernel) ;; We're breaking the rules by putting import before export, so we ;; have to be careful and use eval-when. ;;; In aclwin there is no CLOS package <= ***** (eval-when (:compile-toplevel :load-toplevel :execute) (import '(clos::class-direct-subclasses clos::class-direct-superclasses clos::class-precedence-list clos::class-direct-slots clos::specializer-direct-methods clos::specializer-direct-generic-functions clos::generic-function-methods clos::method-function clos::method-generic-function clos::method-specializers clos::slot-definition-readers clos::slot-definition-writers clos::slot-definition-initargs clos::slot-definition-initform clos::slot-definition-type clos::slot-definition-name clos::slot-definition-allocation clos::slot-definition-initfunction) )) (eval-when (:compile-toplevel :load-toplevel :execute) (shadow '(clos::class-precedence-list clos::class-prototype clos::class-slots )) ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-direct-subclasses class-direct-superclasses class-precedence-list class-direct-slots specializer-direct-methods specializer-direct-generic-functions generic-function-methods method-function method-generic-function method-specializers slot-definition-readers slot-definition-writers slot-definition-initargs slot-definition-initform slot-definition-type slot-definition-name slot-definition-allocation slot-definition-initfunction) ) ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-p direct-slots generic-function-p reader-method-p writer-method-p))) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collect-methods collect-accessors collect-slot-definitions ))) ;;; Had to ensure that the class was finalized before calling ;;; ;;; Added for the benefit of ACL6.0 for right-button problem (excl:without-package-locks (defmethod clos::finalize-inheritance ((thing T)) )) ;; re-type the following two defmethods - cause acl10.1express to crash on loading the compiled code with them in #| (excl:without-package-locks (defmethod class-precedence-list ((thing standard-class)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (clos::class-precedence-list thing))) (excl:without-package-locks (defmethod class-precedence-list ((thing T)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (if (clos::class-finalized-p thing) (clos::class-precedence-list thing) (remove thing (clos::compute-class-precedence-list thing))))) (excl:without-package-locks (defmethod class-precedence-list ((thing standard-class)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (clos::class-precedence-list thing) )) ;; Added 02DEC98 for errors on right-button - see porting.lsp [57] (excl:without-package-locks (defmethod class-precedence-list ((thing T)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (if (clos::class-finalized-p thing) (clos::class-precedence-list thing) (remove thing (clos::compute-class-precedence-list thing)) ) )) |# (defmethod class-prototype ((thing standard-class)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (clos::class-prototype thing) ) (defmethod class-slots ((thing standard-class)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (clos::class-slots thing) ) (defmethod class-methods ((thing standard-class)) (unless (clos::class-finalized-p thing) (clos::finalize-inheritance thing)) (cg::all-specializer-direct-methods thing) ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(class-prototype class-precedence-list class-slots class-direct-methods class-methods ) ) ) ;;; ----------------------------- (defun class-p (arg) "Return T if argument is a class." (typep arg 'standard-class)) (defun generic-function-p (arg) "Return T if argument is a generic-function." (typep arg 'generic-function)) (defgeneric method-name (method-object) (:documentation "Returns the name of the method.")) (defmethod method-name ((thing clos::standard-method)) (let ((gf (slot-value thing 'generic-function)) ) (when gf (slot-value gf 'clos::name)) ) ) (defmethod method-name ((thing clos::standard-writer-method)) (let ((gf (slot-value thing 'generic-function)) name) (when gf (setf name (slot-value gf 'clos::name))) (when (and name (listp name)) (setf name (second name))) name) ) (defun reader-method-p (method) "Tests whether method is a directly defined reader method." (let ((specializers (method-specializers method))) (and (= (length specializers) 1) (member method (slot-definition-readers (first specializers)) :test #'eq)))) (defun writer-method-p (method) "Tests whether method is a directly defined writer method." (let ((specializers (method-specializers method))) (and (= (length specializers) 2) (member method (slot-definition-readers (first specializers)) :test #'eq)))) (defmethod class-direct-class-slots ((self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-direct-slots self) when (not (eq (clos::slot-definition-allocation slot) :instance)) collect slot)) (defmethod class-class-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-slots self) when (not (eq (clos::slot-definition-allocation slot) :instance)) collect slot)) (defmethod class-instance-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-slots self) when (eq (clos::slot-definition-allocation slot) :instance) collect slot)) (defmethod class-direct-instance-slots ((Self standard-class)) "Call makes little sense. Returns NIL." (loop for slot in (class-direct-slots self) when (eq (clos::slot-definition-allocation slot) :instance) collect slot)) ;;; ;;; The following are mop specialized methods to prevent breakage ;;; (in the documentation system anyway) when ``classes'' like T ;;; are encountered where it makes no sense for them to have slots etc. ;;; (defmethod class-direct-class-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-class-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-instance-slots ((Self T)) "Call makes little sense. Returns NIL." ()) (defmethod class-direct-instance-slots ((Self T)) "Call makes little sense. Returns NIL." ()) ;;; ;;; ;;; (defun collect-methods (fun) "Collects all the methods associated with the generic-function fun, ~ organizes these into an association list whose keys are the qualifier ~ lists for each method and whose values are the list of methods having ~ those qualifiers. Those methods which do not have qualifiers, i.e. ~ whose qualifer list is NIL, will be stored with key (\:primary)." (let ((methods (generic-function-methods (cond ((symbolp fun) (symbol-function fun)) (T fun)))) (result NIL) qualifiers ) (loop for method in methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers result :test #'equal) (push method (cdr (assoc qualifiers result :test #'equal))) (setf result (acons qualifiers (list method) result)))) result)) (defun collect-accessors (class) "Collects all the accessor methods associated with the class class, ~ organizes these into an association list whose keys are either ~ :readers or :writers. ~ The value associated with each key is a list of lists of reader or ~ writer methods respectively for all slots of class. The first element ~ in each value list is the list of method qualifiers; ~ The remaing elements are the method-objects themselves." (cond ((symbolp class) (setf class (find-class class))) ((stringp class) (setf class (find-class (with-input-from-string (s class) (read s))))) ) (let ((reader-methods (slot-definition-readers class)) (writer-methods (slot-definition-writers class)) qualifiers reader-list writer-list) (loop for method in reader-methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers reader-list :test #'equal) (push method (cdr (assoc qualifiers reader-list :test #'equal))) (setf reader-list (acons qualifiers (list method) reader-list)))) (loop for method in writer-methods do (setf qualifiers (or (method-qualifiers method) (list :primary))) (if (assoc qualifiers writer-list :test #'equal) (push method (cdr (assoc qualifiers writer-list :test #'equal))) (setf writer-list (acons qualifiers (list method) writer-list)))) (cond ((and reader-list writer-list) (list (cons :readers reader-list) (cons :writers writer-list)) ) (reader-list (list (cons :readers reader-list))) (writer-list (list (cons :writers writer-list))) (T NIL)) ) ) (defun collect-slot-definitions (class) "Collects all the slot-definitions associated with the class class, ~ organizes these into an association list whose keys are one of ~ :class-slots :instance-slots :direct-class-slots and :direct-instance-slots. ~ The value associated with each key is a list of slot-definitions of that type ~ for this class. ~ " (cond ((symbolp class) (setf class (find-class class))) ((stringp class) (setf class (find-class (with-input-from-string (s class) (read s))))) ) (let ((direct-class-slots (class-direct-class-slots class)) (direct-instance-slots (class-direct-instance-slots class)) (instance-slots (class-instance-slots class)) (class-slots (class-class-slots class)) ) (setf class-slots (cons :class-slots class-slots)) (setf instance-slots (cons :instance-slots instance-slots)) (setf direct-class-slots (cons :direct-class-slots direct-class-slots)) (setf direct-instance-slots (cons :direct-instance-slots direct-instance-slots)) (list class-slots instance-slots direct-class-slots direct-instance-slots))) (excl:without-package-locks (defmethod slot-definition-readers ((thing T)) NIL)) (excl:without-package-locks (defmethod slot-definition-writers ((thing T)) NIL)) (excl:without-package-locks (defmethod slot-definition-readers ((thing standard-class)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'clos::standard-reader-method) collect method)))) (excl:without-package-locks (defmethod slot-definition-writers ((thing standard-class)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'clos::standard-writer-method) collect method)))) (excl:without-package-locks (defmethod slot-definition-readers ((thing clos:standard-effective-slot-definition)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'clos::standard-reader-method) collect method)))) (excl:without-package-locks (defmethod slot-definition-writers ((thing clos:standard-effective-slot-definition)) (let ((direct-methods (specializer-direct-methods thing)) ) (loop for method in direct-methods when (typep method 'clos::standard-writer-method) collect method))))
15,092
Common Lisp
.l
400
31.4475
113
0.644432
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
048874400d2529564bb5a4e0eeb28f3d6a2f7660e55bcbeda1b63f141afb57d7
33,992
[ -1 ]
33,993
function-info-pc.lsp
rwoldford_Quail/source/quail-kernel/mop/function-info-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; function-info-pc.lisp ;;; ;;; G.W.Bennett 1997 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :quail-kernel) (defun function-name (f) (declare (ignore f)) ;24JUN2023 NIL)
410
Common Lisp
.l
13
28.076923
86
0.242967
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
26a51777f541e3568c831b3d39b8fcf29cda0ff9464b7e4b048e433cfd7b3f03
33,993
[ -1 ]
33,994
matrix-multiply.lsp
rwoldford_Quail/source/quail-kernel/math/matrix-multiply.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; matrix-multiply.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990, 1994 ;;; Statistical Computing Laboratory ;;; University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; R.W. Oldford 1994. ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; matmult ;;; dot-times-object ;;; .* ;;; (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(.* dot-times-object))) ;---------------------------------------------------------------------------------- ;;; matrix/vector/scalar by matrix/vector/scalar matrix multiplication (defun matmult (a b) "Matrix multiplication of two objects having dimensions." #-:sbcl(declare (optimize (speed 3)) (inline ext_+ ext_*) ) (let* ((dim-a (dimensions-of a)) (dim-b (dimensions-of b)) (len-a (length dim-a)) (len-b (length dim-b))) (case len-a (2 (case len-b (2 (let ((rows-in-a (first dim-a)) (cols-in-a (second dim-a)) (rows-in-b (first dim-b)) (cols-in-b (second dim-b))) (if (eq cols-in-a rows-in-b) (let ((result (make-dimensioned-result (list rows-in-a cols-in-b) a b))) (loop for i from 0 to (- rows-in-a 1) do (loop for j from 0 to (- cols-in-b 1) do (setf (eref result i j) (let ((accum 0)) (loop for k from 0 to (- cols-in-a 1) do (setf accum (ext_+ accum (ext_* (eref a i k) (eref b k j))))) accum)))) result) (quail-error "MATMULT: Cannot multiply matrix ~S by matrix ~S. ~&They are not conformable. ~&Dimensions are ~s and ~s respectively." a b dim-a dim-b)))) (1 (let ((rows-in-a (first dim-a)) (cols-in-a (second dim-a)) (rows-in-b (first dim-b))) (if (= cols-in-a rows-in-b) (let ((result (make-dimensioned-result (list rows-in-a) a b))) (loop for j from 0 to (- rows-in-a 1) do (setf (eref result j) (let ((accum 0)) (loop for i from 0 to (- cols-in-a 1) do (setf accum (ext_+ accum (ext_* (eref a j i) (eref b i))))) accum))) (if (= 1 rows-in-a ) (eref result 0 0) result)) (quail-error "MATMULT: Cannot multiply matrix ~S by column vector ~S. ~&They are not conformable. ~&Dimensions are ~s and ~s respectively." a b (matrix-dimensions-of a) (matrix-dimensions-of b))))) (0 (if (= (second dim-a) 1) (if (= (first dim-a) 1) (ext_* (eref a) (eref b)) (map-element #'ext_* nil a b)) (quail-error "MATMULT: Dimensions ~s and ~s do not conform. ~& Perhaps you meant to use the element-wise multiplication *" dim-a dim-b)) ))) (1 (case len-b (2 (let ((rows-in-a (first dim-a)) (rows-in-b (first dim-b)) (cols-in-b (second dim-b))) (if (= 1 rows-in-b) (if (= 1 rows-in-a) (if (= cols-in-b 1) (ext_* (eref a) (eref b)) (map-element #'ext_* nil a b)) (if (= cols-in-b 1) (map-element #'ext_* nil a b) (let ((result (make-dimensioned-result (list rows-in-a cols-in-b) a b))) (loop for j from 0 to (- cols-in-b 1) do (loop for i from 0 to (- rows-in-a 1) do (setf (eref result i j) (ext_* (eref a i) (eref b 0 j))))) result))) (quail-error "MATMULT: Cannot multiply column vector ~S by matrix ~S. ~&They are not conformable. ~&Dimensions are ~s and ~s respectively." a b (matrix-dimensions-of a) (matrix-dimensions-of b))))) (1 (if (= (first dim-b) 1) (if (= (first dim-a) 1) (ext_* (eref a) (eref b)) (map-element #'ext_* nil a b)) (quail-error "MATMULT: Dimensions ~s and ~s do not conform. ~& Perhaps you meant to use the element-wise multiplication *" (matrix-dimensions-of a) (matrix-dimensions-of b))) ) (0 (if (= (first dim-a) 1) (ext_* (eref a) (eref b)) (map-element #'ext_* nil a b))))) (0 (case len-b (2 (if (= (first dim-b) 1) (if (= (second dim-b) 1) (ext_* (eref a) (eref b)) (map-element #'ext_* nil a b)) (quail-error "MATMULT: Dimensions ~s and ~s do not conform. ~& Perhaps you meant to use the element-wise multiplication *" dim-a dim-b))) (1 (quail-error "MATMULT: Dimensions ~s and ~s do not conform. ~& Perhaps you meant to use the element-wise multiplication *" (matrix-dimensions-of a) (matrix-dimensions-of b))) (0 (ext_* (eref a) (eref b)))) ) ))) ;;; ;;; defun for .* ;;; (defun .* (&rest args) "The matrix multiplication operator or \"dot-product\".~ Takes arbitrary number of arguments whose dimensions must conform. Implemented recursively, calling dot-times-object at each level. (:see-also (* :function) (dot-times-object :generic-function))" (case (length args) (0 1) (1 (dot-times-object :identity (first args))) (2 (dot-times-object (first args) (second args))) (t (apply #'.* (dot-times-object (first args) (second args)) (rest (rest args)))))) ;;; ; DEFMETHODs of dot-times-object for basic classes ; (defgeneric dot-times-object (a b) (:documentation "The generic binary operator for dot product. (:see-also .*)" )) (defmethod dot-times-object ((a t) (b t)) (missing-method 'dot-times-object a b)) (defmethod dot-times-object ((a (eql :identity)) (b number)) b) (defmethod dot-times-object ((a (eql :identity)) (b symbol)) (ext_* 1 b 'dot-times-object)) (defmethod-multi dot-times-object ((a (eql :identity)) (b (sequence array dimensioned-ref-object))) (let ((result (make-dimensioned-result (dimensions-of b) b))) (setf (ref result) b) result)) ;;; added for symmetry 05SEP2023 (defmethod-multi dot-times-object ((a (sequence array dimensioned-ref-object)) (b (eql :identity))) (let ((result (make-dimensioned-result (dimensions-of a) a))) (setf (ref result) a) result)) (defmethod dot-times-object ((x1 number) (x2 number)) (declare (inline *)) (* x1 x2)) (defmethod-multi dot-times-object ((x1 (number symbol)) (x2 symbol)) (ext_* x1 x2 'dot-times-object)) (defmethod dot-times-object ((x1 symbol) (x2 number)) (ext_* x1 x2 'dot-times-object)) #| (defmethod-multi dot-times-object ((a (symbol number sequence array dimensioned-ref-object)) (b (symbol number sequence array dimensioned-ref-object))) (matmult a b)) |# ;;; Added to replace the immediate above 05SEP2023. To avoid multiple defintions complaint (defmethod-multi dot-times-object ((a (sequence array dimensioned-ref-object)) (b (sequence array dimensioned-ref-object))) (matmult a b)) (defmethod-multi dot-times-object ((a (symbol number)) (b (sequence array dimensioned-ref-object))) (matmult a b)) (defmethod-multi dot-times-object ((a (sequence array dimensioned-ref-object)) (b (symbol number))) (matmult a b)) ;;; and for symmetry (defmethod-multi dot-times-object ((a ((eql :identity) symbol number)) (b (eql :identity))) a)
9,704
Common Lisp
.l
231
27.220779
102
0.432395
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e896d6b4ff569f66e271de1b791f08e1c22d2351df9884d6693c1564a38035bb
33,994
[ -1 ]
33,995
ops-low.lsp
rwoldford_Quail/source/quail-kernel/math/ops-low.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ops-low.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; Includes: ;;; v-op-s ;;; m-op-s ;;; v-op-v ;;; m-op-mv ;;; op-error ;;; ;;; Has routines for (op a b) when a and b have <= 2 dimensions each. ;;; This allows extra speed and special behavior for matrices. ;;; (in-package :quail-kernel) ;---------------------------------------------------------------------------------- ;;; vector with scalar (defun v-op-s (op op-name v s &optional (dim-v (dimensions-of v))) (declare (optimize (speed 3))) (declare (ignore op-name)) (let* ((result (make-dimensioned-result dim-v v s)) (s-eref (eref s))) (loop for i from 0 to (- (first dim-v) 1) do (setf (eref result i) (funcall op (eref v i) s-eref))) result)) ;;; matrix with scalar (defun m-op-s (op op-name m s &optional (dim-m (dimensions-of m))) (declare (optimize (speed 3))) (declare (ignore op-name)) (let* ((result (make-dimensioned-result dim-m m s)) (s-eref (eref s))) (loop for i from 0 to (- (first dim-m) 1) do (loop for j from 0 to (- (second dim-m) 1) do (setf (eref result i j) (funcall op (eref m i j) s-eref)))) result)) ;;; vector with vector (defun v-op-v (op op-name a b &optional (dim-a (dimensions-of a)) (dim-b (dimensions-of b))) (declare (optimize (speed 3))) (let* ((len (first dim-a))) (if (eq len (first dim-b)) (let ((result (make-dimensioned-result dim-a a b))) (loop for i from 0 to (- len 1) do (setf (eref result i) (funcall op (eref a i) (eref b i)))) result) (op-error op-name a b "The vectors are not the same length.~%")))) ;;; matrix with matrix/vector (including subcases: n x p with n x 1, etc) (defun m-op-mv (op op-name a b &optional (dim-a (dimensions-of a)) (dim-b (dimensions-of b))) (declare (optimize (speed 3))) (let* ((num-dim-b (length dim-b)) (rows-in-a (first dim-a)) (cols-in-a (second dim-a)) (rows-in-b (first dim-b)) (cols-in-b (ecase num-dim-b (1 1) (2 (second dim-b)))) result) (cond ((eq rows-in-a rows-in-b) (cond ((eq cols-in-b 1) ;; then b is a 1-dim or 2-dim column-vector (setf result (cglue-replicates cols-in-a b a))) ((eq cols-in-a cols-in-b) ;; then a and b have same shape, with cols-in-b > 1 (setf result (sel b :shape t))) (t (op-error op-name a b)))) ((eq cols-in-a cols-in-b) (cond ((eq rows-in-b 1) ;; then b is a 2-dim row-vector (setf result (rglue-replicates rows-in-a b a))) (t (op-error op-name a b)))) ((eq cols-in-a rows-in-b) (cond ((eq cols-in-b 1) ;; then b is a 1-dim row-vector (setf result (rglue-replicates rows-in-a b a))) (t (op-error op-name a b)))) (t (op-error op-name a b))) (loop for i from 0 to (- rows-in-a 1) do (loop for j from 0 to (- cols-in-a 1) do (setf (eref result i j) (funcall op (eref a i j) (eref result i j))))) result)) #| ;;; num-array with scalar (defun n-op-s (op op-name a b &optional (dim-a (dimensions-of a)) (dim-b (dimensions-of b))) ) ;;; num-array with num-array (defun n-op-n (op op-name a b &optional (dim-a (dimensions-of a)) (dim-b (dimensions-of b))) ) |# ;;; ; The op-error generic function ; (defgeneric op-error (op-name a b &optional more-comments)) ;; This provides a default method for most symbols ... ;; usually do (defmethod ((op-name (eql 'op)) a b) ...) etc. (defmethod op-error ((op-name symbol) a b &optional more-comments) (if more-comments (quail-error "Error attempting to perform ~S with operands ~S and ~S. ~A" op-name a b (format nil more-comments)) (quail-error "Error attempting to perform ~S with operands ~S and ~S." op-name a b)))
5,211
Common Lisp
.l
133
28.240602
84
0.442812
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b637b980d94214eada066912331785a9a51299799cb4f34265c48d21b8932f37
33,995
[ -1 ]
33,996
adjust-array.lsp
rwoldford_Quail/source/quail-kernel/array/adjust-array.lsp
;;; -*- Mode: LISP / Syntax: Common Lisp / Package: :test (in-package "TEST") (defgeneric adjust-array (array new-dimensions &rest keyword-args) (:documentation "Returns an array of the same type and rank as array, ~ with the specified new-dimensions. ~ This function may either alter the given array ~ or create and return a new one.")) (defmethod adjust-array ((a array) new-dimensions &rest keyword-args) (apply #'common-lisp:array a new-dimensions keyword-args)) (defmethod adjust-array ((a ref-array) new-dimensions &rest keyword-args) (let ((contents (contents-of a))) (with-slots (specs dimensions) a (setf (slot-value a 'contents) (if (adjustable-array-p contents) (apply #'adjust-array contents new-dimensions keyword-args) (apply #'adjust-array (make-array (array-dimensions contents) :displaced-to contents :adjustable t) new-dimensions keyword-args))) (setf dimensions new-dimensions) (setf specs (mapcar #'min specs new-dimensions))))) (defmethod min-object ((x cons) (y number)) (mapcar #'(lambda (z) (min z y)) x)) (defmethod min-object ((x number) (y cons)) (mapcar #'(lambda (z) (min z y)) y))
1,438
Common Lisp
.l
33
32.666667
74
0.582315
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fde5bdbbbe5ba425b6711162f4c2749e157d875ccb1089adfca82bc13fea2b0e
33,996
[ -1 ]
33,997
mk-array.lsp
rwoldford_Quail/source/quail-kernel/array/mk-array.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mk-array.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990, 1991, 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1991. ;;; M.E. LEWIS 1991. ;;; R.W. Oldford 1992. ;;; Greg Anglin 1993, 1994. ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mk-array make-ref-array shape-as-array))) ;------------------------------------------------------------------------------ #| (defun mk-array (dimensions &rest rest) (multiple-value-bind (class extra) (interpret-keys-only rest '((:class num-array)) 'mk-array t) (apply #'make-ref-array class dimensions extra))) |# ;; The implementation of make-ref-array is a bit bizarre. It accepts as its ;; argument one of three things: ;; ;; 1. the name of a class (as a symbol) ;; 2. the class itself (ie. an instance of standard class) ;; 3. an instance of the class, which will be modified and returned ;; ;; In cases 1 and 2, case 3 is eventually invoked, although ;; in case 1, the class of interest may change in the meantime ;; [ see (defmethod make-ref-array ((class-name (eql 'num-array)) ...) ...) ] (defgeneric make-ref-array (thing dimensions &rest rest)) (defmethod make-ref-array ((self T) dimensions &rest rest) (declare (ignorable self dimensions rest)) ;(declare (ignore self dimensions rest)) 25JUL2023 T) ;; added May29 98 gwb (defmethod make-ref-array :around ((self T) dimensions &rest rest) (declare (ignorable dimensions rest)) ;(declare (ignore dimensions rest)) 25JUL2023 (error "Called the Quail function MAKE-REF-ARRAY, which is supposed to be ~ deprecated. Contact [email protected].")) #| (defmethod make-ref-array ((thing t) dimensions &rest rest) (declare (ignore dimensions rest)) (missing-method 'make-ref-array thing)) (defmethod make-ref-array ((class-name symbol) dimensions &rest rest) (apply #'make-ref-array (make-instance class-name :proto :ignore :dimensions dimensions) dimensions rest)) (defmethod make-ref-array ((class standard-class) dimensions &rest rest) (apply #'make-ref-array (make-instance class :proto :ignore :dimensions dimensions) dimensions rest)) (defmethod make-ref-array ((self ref-array) dimensions &rest rest) (multiple-value-bind (initial-element initial-contents extra) (interpret-keys-only rest '(:initial-element :initial-contents) 'make-ref-array t) (cond ((and initial-contents initial-element) (quail-error "Must specify only one of :initial-element ~ or :initial-contents")) (initial-contents #| (if (and (typep initial-contents 'sequence) (not (= (length initial-contents) (first dimensions)))) (setf initial-contents (shape-as-array initial-contents dimensions))) |# (progn (reinitialize-instance self :dimensions dimensions :proto initial-contents) (apply #'initialize-contents self initial-contents extra))) (initial-element (progn (reinitialize-instance self :dimensions dimensions) (apply #'initialize-contents self nil :initial-element initial-element extra))) (t (progn (reinitialize-instance self :dimensions dimensions) (apply #'initialize-contents self :empty extra))))) self) |# (defun shape-as-array (sequence dimensions &optional seq-type) "Returns a sequence having the same elements as sequence but shaped ~ according to the list dimensions." (unless seq-type (setf seq-type (type-of sequence))) (cond ((eq 'cons seq-type) (setf seq-type 'list)) ((listp (type-of sequence)) (setf seq-type (first (type-of sequence)))) ) (let* ((first-dim (first dimensions)) (rest-dim (rest dimensions)) (new-seq (make-sequence seq-type first-dim))) (if rest-dim (replace new-seq (loop for i from 0 to (- first-dim 1) with length = (apply #'* rest-dim) collect (shape-as-array (subseq sequence (* i length) (* (+ 1 i) length)) rest-dim seq-type))) (replace new-seq sequence)) new-seq))
5,814
Common Lisp
.l
130
30.823077
98
0.481947
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
098495e155a8c708525f4a4e1ab6647740b63d6968cf5f160bdcb04108427b13
33,997
[ -1 ]
33,998
ranks.lsp
rwoldford_Quail/source/quail-kernel/array/ranks.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ranks.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992, 1994. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(ranks))) (defun ranks (object predicate &key (key nil) (slices :elements) (type :exterior)) "Ranks contents of object from smallest to largest according to the predicate ~ function~ (smallest has rank 0, increasing by 1 thereafter). The value returned is a list ~ of the ranks or a list of lists of ranks (for interior ranks on slices). ~ (:elaboration The arguments predicate and key are to be interpreted ~ exactly as the same named arguments in the Common Lisp sort function.) ~ (:see-also sort sort-position order) ~ (:required ~ (:arg object The object to be ranked. Typically object or sequence.) ~ (:arg predicate A function of two arguments which returns non-NIL if and only ~ if the first argument should be considered as preceding the second.))~ (:key ~ (:arg key NIL If non-NIL this is a function that when applied to an element ~ will return ~ the key for that element. The keys are then compared by the predicate.) ~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ object. ~ Similarly, if slices is '(0 1) then a slice of object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.)~ (:arg type :interior Two types of ranking are possible: :interior and :exterior. ~ The interior ranking ranks the elements within the specified slices and ~ the predicate should be a function that compares elements of slices. The exterior ranking ranks the slices and not the elements within each one and ~ the predicate should be a function that compares slices.) ~ )" (cond ((eql type :exterior) (sort-position (sort-position object predicate :key key :slices slices :type :exterior) #'<)) ((eql type :interior) (mapcar #'(lambda (x) (sort-position x #'<)) (sort-position object predicate :key key :slices slices :type :interior)))))
3,269
Common Lisp
.l
66
42.121212
86
0.593348
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6f5d3ae5c1130c51561be95256133d2cbb7ae06c4f0cfcec61d377719a7dd757
33,998
[ -1 ]
33,999
find-slices.lsp
rwoldford_Quail/source/quail-kernel/array/find-slices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; find-slices.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(find-slices find-slices-if))) ;-------------------------------------------------------------------------------- (defun find-slices (item ref-object &key (order :row) (slices :elements) (test #'ref-eq)) "Finds all slices in ref-object which match item when the function test ~ is applied to item and the slice of ref-object.~ It returns a list of the slices found.~ (:see-also find-slices-if find doslices collect-slices)~ (:required ~ (:arg item The item to be compared to each slice in ref-object.)~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg order :row The order in which the slices are to be searched. ~ Column-major by specifying :column, row-major by specifying :row.)~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ (:arg test #'ref-eq The function to be called on item and slice. If it returns ~ non-NIL then that slice is returned.)~ )~ (:returns The list of slices which were found in the order they were found.) ~ " (if (eq order :col) (setf order :column)) (when (numberp slices) (setf slices (list slices))) (cond ((eq order :column) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (column-major-ref-slice ref-object slices i)) (funcall test item slice)) collect slice))) ((eq order :row) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (row-major-ref-slice ref-object slices i)) (funcall test item slice)) collect slice))) (T (quail-error "Illegal order given to find-slices -- ~s ~%~ Order must be one of (:column :row)." order)))) (defun find-slices-if (pred ref-object &key (order :row) (slices :elements)) "Finds every slice in ref-object which returns non-NIL ~ when the function pred is applied to it. ~ It returns a list of the slices found. ~ (:see-also find-slices find-if doslices collect-slices)~ (:required ~ (:arg pred The predicate function to be applied to each slice.) ~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg order :row The order in which the slices are to be searched. ~ Column-major by specifying :column, row-major by specifying :row.)~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ )~ (:returns The list of slices which were found in the order they were found.) ~ " (if (eq order :col) (setf order :column)) (when (numberp slices) (setf slices (list slices))) (cond ((eq order :column) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (column-major-ref-slice ref-object slices i)) (funcall pred slice)) collect slice))) ((eq order :row) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (row-major-ref-slice ref-object slices i)) (funcall pred slice)) collect slice))) (T (quail-error "Illegal order given to find-slices-if -- ~s ~%~ Order must be one of (:column :row)." order))))
5,706
Common Lisp
.l
123
38.439024
95
0.580889
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
006d523d4cd3298621626ca6b6a780b21d7a571b545c9d436e2ea9a766e0e05a
33,999
[ -1 ]
34,000
slice-positions.lsp
rwoldford_Quail/source/quail-kernel/array/slice-positions.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; slice-positions.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(slice-positions slice-positions-if))) ;-------------------------------------------------------------------------------- (defun slice-positions (item ref-object &key (order :row) (slices :elements) (test #'ref-eq)) "Finds all slices in ref-object which match item when the function test ~ is applied to item and the slice of ref-object.~ It returns a list of the positions of the slices found.~ (:see-also slice-positions-if position doslices collect-slices)~ (:required ~ (:arg item The item to be compared to each slice in ref-object.)~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg order :row The order in which the slices are to be searched. ~ Column-major by specifying :column, row-major by specifying :row.)~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ (:arg test #'ref-eq The function to be called on item and slice. If it returns ~ non-NIL then the position of that slice is returned.)~ )~ (:returns The list of positions of all slices found.) ~ " (if (eq order :col) (setf order :column)) (when (numberp slices) (setf slices (list slices))) (cond ((eq order :column) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (column-major-ref-slice ref-object slices i)) (funcall test item slice)) collect i))) ((eq order :row) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (row-major-ref-slice ref-object slices i)) (funcall test item slice)) collect i))) (T (quail-error "Illegal order given to slice-positions -- ~s ~%~ Order must be one of (:column :row)." order)))) (defun slice-positions-if (pred ref-object &key (order :row) (slices :elements)) "Finds the position of every slice in ref-object which returns non-NIL ~ when the function pred is applied to it.~ It returns a list of the positions of the slices found.~ (:see-also slice-positions position-if doslices collect-slices)~ (:required ~ (:arg pred The predicate function to be applied to each slice.) ~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg order :row The order in which the slices are to be searched. ~ Column-major by specifying :column, row-major by specifying :row.)~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ )~ (:returns The list of positions of all slices found.) ~ " (if (eq order :col) (setf order :column)) (when (numberp slices) (setf slices (list slices))) (cond ((eq order :column) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (column-major-ref-slice ref-object slices i)) (funcall pred slice)) collect i))) ((eq order :row) (let (slice) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) when (progn (setf slice (row-major-ref-slice ref-object slices i)) (funcall pred slice)) collect i))) (T (quail-error "Illegal order given to slice-positions-if -- ~s ~%~ Order must be one of (:column :row)." order))))
5,752
Common Lisp
.l
123
38.813008
103
0.58433
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6497752c8bb881aa45a33d91696bca69735e2da54f554ea9810a8afa5e9a200b
34,000
[ -1 ]
34,001
doodles.lsp
rwoldford_Quail/source/quail-kernel/array/doodles.lsp
(defun foo (list predicate key) (let ((indexed-list (loop for i from 0 by 1 as l in list collect (cons i l)))) (mapcar #'car (cl:sort indexed-list predicate :key (if key #'(lambda (x) (funcall key (cdr x))) #'cdr))))) fixed-dimensions ---> slice (rank '((6 5) (4 3) (2 1)) #'< ) ===> ((5 4) (3 2) (1 0)) (rank '((6 5) (4 3) (2 1)) #'(lambda (x y) (< (sum x) (sum y))) :slice 0) ==========>>>>>>>>> (2 1 0) (rank '((6 5) (4 3) (2 1)) #'(lambda (x y) (< (sum x) (sum y))) :slice 1) ==========>>>>>>>>> (1 0) (order '((6 5) (4 3) (2 1)) :order '(2 1 0 5 4 3)) =========>>>>>>>>>>>> '((4 5) (6 1) (2 3)) (order '((6 5) (4 3) (2 1)) :order '(2 1 0) :slice '(0)) =========>>>>>>>> '((2 1) (4 3) (6 5)) (defun rank (object predicate &key (key nil) (fixed-dimensions nil) (type :interior) (store-in NIL)) "Ranks the sub-arrays of fixed-dimensions of ref-object into an order ~ determined by predicate. The arguments predicate and key are to be interpreted ~ exactly as the same named arguments in the Common Lisp sort function. ~ The argument stable? is NIL (the default) or non-NIL depending on whether ~ it is desirable that stability be guaranteed in the sense of the Common Lisp function ~ stable-sort. ~ These types of sort are possible: ~ 1. If the arguments permit, then sort follows the Common Lisp standard. ~ 2. If object is a ref-object and type is :exterior, then, for example, ~ (sort A #'< :key #'sum :fixed-dimensions 1 :type :exterior) rearranges the ~ columns (fixed-dimensions 1) ~ of the matrix A ~ so that the column with the greatest total is the 0-th column, and so forth. ~ 3. If object is a ref-object and type is :interior, then, for example, ~ (sort A #'< :fixed-dimensions 1 :type :interior) rearranges each column ~ (fixed-dimensions 1) of the matrix A ~ so that the greatest element is in the first row, and so forth. ~ 4. In all of the above, destructive sorts are preformed if copy? is nil ~ (the default). ~ If copy? is t, then a non-destructive sort is performed." (if (not (listp fixed-dimensions)) (setf fixed-dimensions (list fixed-dimensions)) (setf fixed-dimensions (cl:sort (remove-duplicates fixed-dimensions) #'<))) (rank-object object predicate key fixed-dimensions type store-in) ) (defmethod rank-object (object predicate key fixed-dimensions type store-in) (missing-method 'sort object predicate key fixed-dimensions type store-in)) (defmethod rank-object :around ((object T) predicate key fixed-dimensions (type (eql :interior)) (store-in null)) (if object (rank-object object predicate key fixed-dimensions type (sel object)))) (defmethod rank-object ((object sequence) (predicate function) key (fixed-dimensions null) (type (eql :interior)) store-in) (declare (ignore fixed-dimensions type)) (let ((indexed-list (loop for i from 0 to (- (length self as l in list collect (cons i l)))) (mapcar #'car (cl:sort indexed-list predicate :key (if key #'(lambda (x) (funcall key (cdr x))) #'cdr)))))) (defmethod-multi rank-object ((object (dimensioned-ref-object array)) (predicate function) (key (function null)) (fixed-dimensions null) (type (eql :interior))) (declare (ignore fixed-dimensions type)) (basic-sort-by-eref object predicate :key key)) (defmethod-multi rank-object ((object (dimensioned-ref-object array)) (predicate function) key (fixed-dimensions list) (type (eql :interior))) (loop for index from 0 to (- (number-of-slices (dimensions-of object) fixed-dimensions) 1) collect (rank-object (apply #'row-major-ref-slice object index fixed-dimensions) predicate key NIL type)) )
4,989
Common Lisp
.l
115
29.843478
91
0.50438
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0521c18e33a4823f5594a016e82ea27ffed4888371197a3a53b5140317294482
34,001
[ -1 ]
34,002
sort-object.lsp
rwoldford_Quail/source/quail-kernel/array/sort-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; sort-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992, 1994. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(basic-sort-by-eref sort-object))) ;;;---------------------------------------------------------------------------- ;;; ;;; The following is just what it says ;;; ;;; Should anyone write a new sort function that uses eref to access the ;;; elements of its argument, they should call it basic-sort-by-eref. ;;; ;;; N.B. The present version uses the system defined sort. ;;; ;;;---------------------------------------------------------------------------- (defun basic-sort-by-eref (object predicate &key key stable?) "This is the basic sort function for ref'able objects. ~ It is always destructive -- resetting the elements of its first argument. ~ (:see-also sort sort-position ranks order eref) ~ (:required ~ (:arg object The object to be sorted. Something whose elements can be ~ accessed by the eref function.) ~ (:arg predicate A function of two arguments which returns non-NIL if and only ~ if the first argument should be considered as preceding the second.))~ (:key ~ (:arg key NIL If non-NIL this is a function that when applied to an element ~ will return ~ the key for that element. The keys are then compared by the predicate.) ~ (:arg stable? NIL If NIL, the sorting operation is not guaranteed to be stable. ~ If elements x and y are considered to be equal by the predicate as in ~ the predicate returning NIL when presented with x y in either order, ~ then there is no guarantee that the elements will stay in their original order ~ in object. ~ If stable? is non-NIL then in the case of ties the original order will be ~ preserved but the sort will be slower.) ~ )~ (:elaboration Should anyone write a new sort function that uses eref to ~ access the ~ elements of its argument, they should call it basic-sort-by-eref. ~%~ N.B. The present version uses the Common Lisp system defined sort.)" (cond (key (cond (stable? (row-major-set-elements object (cl:stable-sort (row-major-list-elements object) predicate :key key))) (T (row-major-set-elements object (cl:sort (row-major-list-elements object) predicate :key key))))) (T (cond (stable? (row-major-set-elements object (cl:stable-sort (row-major-list-elements object) predicate))) (T (row-major-set-elements object (cl:sort (row-major-list-elements object) predicate))))))) (defgeneric sort-object (object predicate key slices type stable?) (:documentation "Just like sort, except that keyword arguments are converted to required ~ arguments. This helps with argument typing. And the sort is always destructive ~ to the object.")) (defmethod sort-object (object predicate key slices type stable?) "Missing method for all unclassified cases." (missing-method 'sort-object object predicate key slices type stable?) ) (defmethod-multi sort-object ((object (symbol number character)) (predicate function) key slices type stable?) "Returns object since sorting doesn't quite make sense here." (declare (ignorable predicate key slices type stable?)) ;(declare (ignore predicate key slices type stable?)) 25JUL2023 object) ;;; This appears to be covered by the order sort-position as well! (defmethod-multi sort-object ((object (dimensioned-ref-object sequence array)) (predicate function) key (slices T) ;;(eql :elements)) (type (eql :interior )) stable?) "Implements the interior sort as an exterior sort for every slice. " (doslices (slice object slices object) (sort-object slice predicate key :elements :exterior stable?) )) (defmethod sort-object ((object sequence) (predicate function) key (slices (eql :elements)) (type (eql :exterior)) stable?) "In this situation the usual Common Lisp sort function applies." (declare (ignorable slices type)) ;(declare (ignore slices type)) 25JUL2023 (if key (if stable? (cl:stable-sort object predicate :key key) (cl:sort object predicate :key key)) (if stable? (cl:stable-sort object predicate) (cl:sort object predicate))) ) (defmethod-multi sort-object ((object (T sequence dimensioned-ref-object array)) (predicate function) key (slices null) (type (eql :exterior)) stable?) (declare (ignorable predicate key slices type stable?)) ;(declare (ignore predicate key slices type stable?)) 25JUL2023 object) (defmethod-multi sort-object ((object (dimensioned-ref-object array)) (predicate function) key (slices (eql :elements)) (type (eql :exterior)) stable?) "In this situation the basic-sort-by-eref is used." (declare (ignorable slices type)) ;(declare (ignore slices type)) 25JUL2023 (basic-sort-by-eref object predicate :key key :stable? stable?)) (defmethod-multi sort-object ((object (dimensioned-ref-object sequence array)) (predicate function) key (slices list) (type (eql :exterior)) stable?) (declare (ignorable stable?)) ;(declare (ignore stable?)) 25JUL2023 (order object (sort-position object predicate :key key :slices slices :type :exterior) :slices slices :type :exterior :copy? NIL))
7,218
Common Lisp
.l
169
30.91716
123
0.52561
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
899ffc06861e3dcbeeb18795019006adb59ca9219bbd615150260071ad100694
34,002
[ -1 ]
34,004
slice.lsp
rwoldford_Quail/source/quail-kernel/array/slice.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; slice.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992, 1994. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(doslices collect-slices))) (defmacro doslices ((slice-var object &optional (slices :elements) return-form (order :row)) &body body) "Provides straightforward iteration over selected slices of a refable object. ~&~ Syntax: (doslices (slice-var object {[slices] | [return-form] | [order]}) {form}*) ~ (:elaboration ~ First doslices evaluates the form object, which should produce a refable object. ~ It then executes the body once for each slice in the object as determined by ~ slices argument with slice-var being the value of the current slice. ~ The order of iteration is determined by the optional argument order. ~ Upon completion, slice-var is bound to NIL and the return-form is evaluated.) ~ (:required ~ (:arg slice-var The symbol to be bound to the current slice for use in the body ~ of the form.) ~ (:arg object The ref'able object whose slices are to be iterated over.) )~ (:optional ~~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of object. ~ Similarly, if slices is '(0 1) then a slice of object is the set of all elements ~ of object having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole ofobject is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ (:arg return-form NIL The form to be evaluated and returned upon completion of ~ the loop.) ~ (:arg order :row The order in which the slices are to be iterated over. ~ If :row, then iteration proceeds in row major order changing the index of ~ last dimension defining the slice fastest. If :column or :col, then iteration ~ is in column major order and the index of the first dimension given in slices ~ changes fastest.) ~ )~ (:body The body of the iteration. As many forms as you would like.)~ (:see-also collect-slices loop do dolist row-major-ops column-major-ops)~ " (let ((slices-var (gensym "SLICES-VAR-"))) `(cond ((or (eql ,order :col) (eql ,order :column)) (let ((,slices-var (cond ((eq ,slices :elements) :elements) ((numberp ,slices) (list ,slices)) ((null ,slices) NIL) ((listp ,slices) (remove-duplicates (sort ,slices #'<))) (t ,slices)))) (loop for index from 0 to (- (number-of-slices ,object ,slices-var) 1) do (let ((,slice-var (column-major-ref-slice ,object ,slices-var index))) (declare (ignorable ,slice-var)) ,@body) finally (let* ((,slice-var NIL) (result ,return-form)) (declare (ignorable ,slice-var)) (return result))) )) (t (let ((,slices-var (cond ((eq ,slices :elements) :elements) ((numberp ,slices) (list ,slices)) ((null ,slices) NIL) ((listp ,slices) (remove-duplicates (sort ,slices #'<))) (t ,slices)))) (loop for index from 0 to (- (number-of-slices ,object ,slices-var) 1) do (let ((,slice-var (row-major-ref-slice ,object ,slices-var index))) (declare (ignorable ,slice-var)) ,@body) finally (let* ((,slice-var NIL) (result ,return-form)) (declare (ignorable ,slice-var)) (return result)))))))) (defmacro collect-slices ((slice-var object &optional (slices :elements) (order :row)) &body body) "Provides straightforward iterations over selected slices of a refable object. ~&~ Syntax: (collect-slices (slice-var object {[slices] | [order]}) {form}*) ~&~ First collect-slices evaluates the form object, which should produce a refable object. ~ It then executes the body once for each slice in the object as determined by ~ the optional argument slices. ~ The order of iteration is determined by the optional argument ~ order: either :row (the default) for row major order, or :col for column ~ major order. The result of each iteration is collected into a list and returned ~ as the value of the collect-slices form. (:required ~ (:arg slice-var The symbol to be bound to the current slice for use in the body ~ of the form.) ~ (:arg object The ref'able object whose slices are to be iterated over.) )~ (:optional ~~ (:arg slices :elements ~ The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of object. ~ Similarly, if slices is '(0 1) then a slice of object is the set of all elements ~ of object having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole ofobject is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them.) ~ (:arg order :row The order in which the slices are to be iterated over. ~ If :row, then iteration proceeds in row major order changing the index of ~ last dimension defining the slice fastest. If :column or :col, then iteration ~ is in column major order and the index of the first dimension given in slices ~ changes fastest.) ~ )~ (:body The body of the iteration. As many forms as you would like.)~ (:see-also doslices loop do dolist row-major-ops column-major-ops)~ " (let ((slices-var (gensym "SLICES-VAR-"))) `(cond ((or (eql ,order :col) (eql ,order :column)) (let ((,slices-var (cond ((eq ,slices :elements) :elements) ((numberp ,slices) (list ,slices)) ((null ,slices) NIL) ((listp ,slices) (remove-duplicates (sort ,slices #'<))) (t ,slices)))) (loop for index from 0 to (- (number-of-slices ,object ,slices-var) 1) collect (let ((,slice-var (column-major-ref-slice ,object ,slices-var index))) (declare (ignorable ,slice-var)) ,@body)))) (t (let ((,slices-var (cond ((eq ,slices :elements) :elements) ((numberp ,slices) (list ,slices)) ((null ,slices) NIL) ((listp ,slices) (remove-duplicates (sort ,slices #'<))) (t ,slices)))) (loop for index from 0 to (- (number-of-slices ,object ,slices-var) 1) collect (let ((,slice-var (row-major-ref-slice ,object ,slices-var index))) (declare (ignorable ,slice-var)) ,@body)))))))
9,018
Common Lisp
.l
173
38.115607
92
0.533478
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e759120d862d9aeb065d3b951028b531440b064a0eaa959ccc87d8b1ce24e180
34,004
[ -1 ]
34,005
remove-slices.lsp
rwoldford_Quail/source/quail-kernel/array/remove-slices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; remove-slices.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(remove-slices remove-slices-if))) ;-------------------------------------------------------------------------------- (defun remove-slices (item ref-object &key (slice 0) (test #'ref-eq)) "Removes all slices from ref-object which match item when the function test ~ is applied to item and the slice of ref-object.~ It is non-destructive to ref-object and returns an appropriately tailored ~ ref of ref-object.~ (:see-also remove-slices-if remove doslices collect-slices)~ (:required ~ (:arg item The item to be compared to each slice in ref-object.)~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg slice 0 The dimension that defines the slices. Because a slice is being ~ completely removed, it only makes sense to specify a single dimension here. ~ Note however that if the (number-of-dimensions ref-object) is <= 1 ~ then the slicing is taken over all elements, not refs of them.) ~ (:arg test #'ref-eq The function to be called on item and slice. If it returns ~ non-NIL then that slice is removed, otherwise it remains.)~ )~ (:returns If no slices are removed, ref-object is returned. If all slices are ~ removed it returns NIL. Otherwise ~ a ref of the original ref-object is returned.) ~ " (let ((slices (if (<= (number-of-dimensions ref-object) 1) :elements (list slice))) locs result) (setf locs (loop for i from 0 to (- (number-of-slices ref-object slice) 1) when (funcall test item (column-major-ref-slice ref-object slices i)) collect i)) (setf result (if locs (let ((indices (make-sequence 'list (length (dimensions-of ref-object)) :initial-element T))) (setf (eref indices slice) (cons :c locs)) (apply #'ref ref-object indices)) ref-object)) (if (zerop (number-of-elements result)) NIL result))) (defun remove-slices-if (pred ref-object &key (slice 0)) "Removes every slice from ref-object which returns non-NIL ~ when the function pred is applied to it.~ It is non-destructive to ref-object and returns an appropriately tailored ~ ref of ref-object.~ (:see-also remove-slices remove-if doslices collect-slices)~ (:required ~ (:arg pred The predicate function to be evaluated at each slice ~ in ref-object.)~ (:arg ref-object The source of the slices which will be compared to item.) ~ ) ~ (:key ~ (:arg slice 0 The dimension that defines the slices. Because a slice is being ~ completely removed, it only makes sense to specify a single dimension here. ~ Note however that if the (number-of-dimensions ref-object) is <= 1 ~ then the slicing is taken over all elements, not refs of them.) ~ )~ (:returns If no slices are removed, ref-object is returned. ~ If all slices are removed it returns NIL. Otherwise ~ a ref of the original ref-object is returned.) ~ " (let ((slices (if (<= (number-of-dimensions ref-object) 1) :elements (list slice))) locs result) (setf locs (loop for i from 0 to (- (number-of-slices ref-object slice) 1) when (funcall pred (column-major-ref-slice ref-object slices i)) collect i)) (setf result (if locs (let ((indices (make-sequence 'list (length (dimensions-of ref-object)) :initial-element T))) (setf (eref indices slice) (cons :c locs)) (apply #'ref ref-object indices)) ref-object)) (if (zerop (number-of-elements result)) NIL result)))
4,681
Common Lisp
.l
104
35.394231
99
0.545495
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e125602022f8b89ab53766f3eb9d35b9084ba80a6b3bf4726c2caf29b90cff34
34,005
[ -1 ]
34,006
accumulate.lsp
rwoldford_Quail/source/quail-kernel/array/accumulate.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; accumulate.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; M.E. Lewis 1991. ;;; R.W. Oldford 1991. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(accumulate))) ;-------------------------------------------------------------------------------- (defgeneric accumulate (x margin fun &key init) (:documentation "Like Common Lisp reduce function. Example: if x is an object ~ of dimensions (2 3 4 5 6), ~ then (accumulate x '(t nil t nil t) #'foo) returns a (3 5) ~ dimensional array. The (i j)th element of the new array ~ is the result of ~ accumulating the elements of a (ref x '(t i t j t)) pairwise using the ~ binary function foo. ~ If margin is T, then the function is applied to the entire array. ~ If margin is shorter than the number of dimensions, it is appended with NILs.")) (defmethod-multi accumulate ((x (symbol number list array ref-array dimensioned-ref-object)) margin fun &key (init nil init-supplied?)) (let* ((dim (dimensions-of x)) (num-dim (length dim)) (m (if (listp margin) (length margin) 0))) (if (> m num-dim) (quail-error "~&Margin ~S specifies ~S dimensions, but accumulated ~ object ~S has only ~S dimensions." margin m x num-dim)) (setf margin (if (eq margin t) (pad-list '() num-dim t) (pad-list margin num-dim nil) )) (let* ((margin-dim (list-if-t dim margin)) (current (make-sequence 'list (length margin-dim) :initial-element 0)) (d-start 0) (answer init)) (if (not init-supplied?) (case (apply #'* margin-dim) (1 (let* ((indices (expand-list current margin t))) (setf answer (funcall fun (apply #'ref x indices))) (setf d-start 1))) (t (let* ((indices-1 (expand-list current margin t)) (next-current (row-major-next-subscript current margin-dim)) (indices-2 (expand-list next-current margin t))) (setf answer (funcall fun (apply #'ref x indices-1) (apply #'ref x indices-2))) (setf d-start 2) (setf current (row-major-next-subscript next-current margin-dim)))))) (loop for d from d-start to (- (apply #'* margin-dim) 1) do (let* ((indices (expand-list current margin t))) (setf answer (funcall fun answer (apply #'ref x indices))) (setf current (row-major-next-subscript current margin-dim)))) answer)))
3,295
Common Lisp
.l
73
34.575342
85
0.479089
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
baad08e770f3953bfcab7ebd8a68a17ec0da9111cefdbf7a773f6a7d587afe0b
34,006
[ -1 ]
34,007
collapse.lsp
rwoldford_Quail/source/quail-kernel/array/collapse.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; collapse.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collapse))) ;-------------------------------------------------------------------------------- (defun collapse (fun ref-object &key (slices NIL) (order :row)) "Calls the function fun on each slice of ref-object having indices ~ in the dimensions identified by the list slices. ~ Collapse tries to return an object like ref-object but having fewer dimensions. ~ The dimensions of the returned object will match those of ref-object as identified ~ by slices. For example if ref-object is a 2 by 3 by 4 by 5 array and slices is (0 1), ~ then the returned object will be a 2 by 3 array. ~ Each element of the returned object will be the result of calling fun on ~ the corresponding slice. In our example, the 0 0 element of the returned object ~ will be the result of calling fun on (ref ref-object 0 0 T T). ~ The elements of the returned object are filled in the same order that the slices ~ of ref-object are traversed: either :row or :column major order.~ (:required ~ (:arg fun A function of one argument, namely a single slice.)~ (:arg ref-object The refable object over which slicing is to take place.) ~ )~ (:key ~ (:arg slices NIL The slices over which the collapse is to take place. ~ One way to think of it is that the slices identify the dimensions of ref-object ~ that are to be preserved. The value of slices is typically ~ an integer or list of fixed dimensions. ~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will then be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them. In this special case, ~ the elements themselves are collapsed according to fun.) ~ (:arg order :row The order in which iteration is to take place over slices.) ~ )~ (:returns A ref-object of the same class as the ~ argument ref-object but with dimensions the same as its slices.)~ (:see-also reduce-slices doslices map-slices)~ " (if (eq order :col) (setf order :column)) (when (numberp slices) (setf slices (list slices))) (cond ((null slices) ;; The whole thing is the slice (funcall fun ref-object)) (T ;;try and make a structure of the same type as ref-object ;; and the same dimsneions as a single slice and stuff the results ;; in the cells. ;; The way this is now achieved is by copying a single slice ;; and filling it. ;; There has to be a more efficient way to do this ;; ******* rwo (let (result) (if (listp slices) ;; then sort out the right size to return (let ((complement-dims (iseq (length (dimensions-of ref-object))))) (loop for i in slices do (setf complement-dims (remove i complement-dims))) (setf result (sel (column-major-ref-slice ref-object complement-dims 0))) ) (setf result (sel ref-object))) (cond ;;row-order ((eq order :row) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) do (setf (row-major-eref result i) (funcall fun (row-major-ref-slice ref-object slices i))) ) result) ;; column-order ((eq order :column) (loop for i from 0 to (- (number-of-slices ref-object slices) 1) do (setf (column-major-eref result i) (funcall fun (column-major-ref-slice ref-object slices i))) ) result) (T (quail-error "Illegal order given to collapse -- ~s ~%~ Order must be one of (:column :row)." order)))) )))
5,060
Common Lisp
.l
115
35.652174
93
0.564794
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8e19adb544753457e1fa7fcefed6bc1c95f6ef66a22b9791e944c2f0c719d1e9
34,007
[ -1 ]
34,008
order.lsp
rwoldford_Quail/source/quail-kernel/array/order.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; order.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; copyright (c) 1992 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; M.E. Lewis 1992. ;;; R.W. Oldford 1992. ;;; ;;; ;;;---------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(order))) (defun order (object positions &key (slices :elements) (copy? NIL) (type :exterior) (order :row)) "Repositions the sub-arrays of the fixed-dimensions of object into an order ~ determined by the second argument in conjunction with the information ~ given by the keyword arguments slices types and order. ~ (:see-also sort sort-position ranks indices) ~ (:required ~ (:arg object The object to be sorted. Typically a ref-object or sequence.) ~ (:arg positions A list of indices of the elements or slices in the desired order.~ For example, the first element in positions is the index of the slice of ~ object which will be in the first position of the ordered object.) ~ ) ~ (:key ~ (:arg slices NIL A list specifying which slice dimensions are ~ to be fixed -- if null, no dimensions are fixed.) ~ (:arg copy? NIL Unless this flag is non-NIL, the ordering ~ will be destructive to the original object. ~ If non-NIL, the object is copied before ordering takes place.) ~ (:arg type :exterior The keyword type specifies whether the ordering is to be done between slices, i.e. :exterior, or within slices, i.e. :interior.)~ (:arg order :row The major ordering in which the slices and their interiors are to ~ be indexed. :row means row major ordering and the last index changes ~ fastest. :column means column major order with the first index changing ~ most rapidly.)~ )" (when (numberp slices) (setf slices (list slices))) (if copy? (setf object (sel object))) (cond ((eq order :row) (cond ((eq type :exterior) (loop for thing in (loop for i in positions collect (sel (row-major-ref-slice object slices i))) as i from 0 do (setf (row-major-ref-slice object slices i) thing))) ((eq type :interior) (loop for indices in positions as i from 0 do (order (row-major-ref-slice object slices i) indices :slices :elements :type :exterior)) ))) ((or (eq order :column) (eq order :col)) (cond ((eq type :exterior) (loop for thing in (loop for i in positions collect (sel (column-major-ref-slice object slices i))) as i from 0 do (setf (column-major-ref-slice object slices i) thing))) ((eq type :interior) (loop for indices in positions as i from 0 do (order (column-major-ref-slice object slices i) indices :slices :elements :type :exterior :order :column)) ))) ) object)
3,490
Common Lisp
.l
89
30.764045
86
0.542882
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6c16fff99558ca69ccef406096aa046aafb84639ffef9d3a7b02cc62681fe027
34,008
[ -1 ]
34,009
map-slices.lsp
rwoldford_Quail/source/quail-kernel/array/map-slices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; map-slices.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :quail-kernel) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(map-slices))) ;-------------------------------------------------------------------------------- (defun map-slices (fun slices order ref-object &rest more-ref-objects) "The function must take as many arguments as there are ref-objects ~ provided. The result is a list such that element j of the list ~ is the result of applying fun to the j'th slice of each of the argument ~ ref-objects. Note that therefore the slices argument must be sensible ~ for all argument ref-objects. ~ (:see-also map-element doslices collect-slices)~ (:required ~ (:arg fun The function to be applied to slices of all ref-objects.~ It must accept as many arguments as there are ref-objects in the arguments.) ~ (:arg slices The integer or list of fixed dimensions that identifies a slice.~ For example if slices is 0 then a slice is defined to be the set of all ~ elements of a ref-object having a common value of the zeroth index. ~ There will be as many slices as the size of the zeroth dimension of the ~ ref-object. ~ Similarly, if slices is '(0 1) then a slice of a ref-object ~ is the set of all elements ~ having common zeroth and first index and there will be as many slices ~ as there are pairs of zeroth and first indices. ~ If NIL then the whole of the ref-object is taken to be the slice. ~ Slices may also be the keyword :elements in which case the elements ~ are accessed directly as opposed to a ref of them. In this special ~ case, map-slices will be much like map-element but not nearly as clever.)~ (:arg order The order of iteration over the slices -- :column for ~ column major order, :row for row-major order.)~ (:arg ref-object The source of the slices which will be the first argument ~ to fun.)~ ) ~ (:rest more-ref-objects The remaining ref-objects.) ~ (:returns A list such that element j of the list ~ is the result of applying fun to the j'th slice of each of the argument ~ ref-objects. The length of the list will be as long as the minimum ~ number-of-slices in any of the ref-objects.)~ " (when (numberp slices) (setf slices (list slices))) (let* ((size (if more-ref-objects (reduce #'(lambda (x y) (min x (number-of-slices y slices))) more-ref-objects :initial-value (number-of-slices ref-object slices)) (number-of-slices ref-object slices)))) (cond ((or (eq order :column) (eq order :col)) (if more-ref-objects (loop for i from 0 to (- size 1) collect (apply fun (column-major-ref-slice ref-object slices i) (loop for obj in more-ref-objects collect (column-major-ref-slice obj slices i)))) (loop for i from 0 to (- size 1) collect (funcall fun (column-major-ref-slice ref-object slices i))) )) ((eq order :row) (if more-ref-objects (loop for i from 0 to (- size 1) collect (apply fun (row-major-ref-slice ref-object slices i) (loop for obj in more-ref-objects collect (row-major-ref-slice obj slices i)))) (loop for i from 0 to (- size 1) collect (funcall fun (row-major-ref-slice ref-object slices i))) )) (T (quail-error "Illegal order for Map-slices ~s. ~%~ Must be either :row or :column." order)))))
4,322
Common Lisp
.l
88
39.534091
84
0.550735
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1849b3f57eab5e8a2e20b9b4b7bf537c132c930aac82d90247f395fe91dbf621
34,009
[ -1 ]