;;; Lisplab, level1-constructors.lisp ;;; A symbolic naming scheme for matrix construction. ;;; Copyright (C) 2009 Joern Inge Vestgaarden ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License along ;;; with this program; if not, write to the Free Software Foundation, Inc., ;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ;;; TODO: maybe I should store constructors rather than symbols. ;;;; Then it would be possible to use this also for arrays. (in-package :lisplab) (defgeneric make-matrix-class (element-type structure implementation) (:documentation "Create a matrix class from the three description elements. Overload with eql specializers if you want to speed up for some particular classes." )) ;;;; Matrix constructors (defmethod make-matrix-class (element-type structure implementation) (let* ((args (list element-type structure implementation))) (make-instance 'standard-class :direct-superclasses args))) (defmethod make-matrix-instance ((type standard-class) dim value) (make-instance type :dim dim :value value)) (defmethod make-matrix-instance ((type symbol) dim value) (make-matrix-instance (find-class type) dim value)) (defmethod make-matrix-instance ((description list) dim value) (assert (= 3 (length description))) (make-matrix-instance (apply #'make-matrix-class description) dim value))