close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 2201


Ignore:
Timestamp:
2015-06-18T09:27:32-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/monom.lisp

    r2200 r2201  
    6464  (princ (slot-value m 'exponents) stream))
    6565
    66 (defun make-monom (&key
    67                      (dimension nil dimension-suppied-p)
    68                      (initial-exponents nil initial-exponents-supplied-p)
    69                      (initial-exponent  nil initial-exponent-supplied-p)
    70                    &aux
    71                      (dimension (cond (dimension-suppied-p dimension)
    72                                       (initial-exponents-supplied-p (length initial-exponents))
    73                                       (t (error "You must provide DIMENSION or INITIAL-EXPONENTS"))))
    74                      (exponents (cond
    75                                   ;; when exponents are supplied
    76                                   (initial-exponents-supplied-p
    77                                    (when (and dimension-suppied-p (/= dimension (length initial-exponents)))
    78                                      (error "INITIAL-EXPONENTS must have length DIMENSION"))
    79                                    (make-array (list dimension) :initial-contents initial-exponents
    80                                                :element-type 'exponent))
    81                                   ;; when all exponents are to be identical
    82                                   (initial-exponent-supplied-p
    83                                    (make-array (list dimension) :initial-element initial-exponent
    84                                                :element-type 'exponent))
    85                                   ;; otherwise, all exponents are zero
    86                                   (t
    87                                    (make-array (list dimension) :element-type 'exponent :initial-element 0)))))
     66(defmethod initialize-instance ((self monom)
     67                                (dimension nil dimension-suppied-p)
     68                                (initial-exponents nil initial-exponents-supplied-p)
     69                                (initial-exponent  nil initial-exponent-supplied-p))
    8870  "A constructor (factory) of monomials. If DIMENSION is given, a
    8971sequence of DIMENSION elements of type EXPONENT is constructed, where
     
    9173to 0.  Alternatively, all elements may be specified as a list
    9274INITIAL-EXPONENTS."
    93   (make-instance 'monom :dimension dimension :exponents exponents))
     75  (with-slots (dimension exponents)
     76      self
     77    (setf dimension (cond (dimension-suppied-p dimension)
     78                          (initial-exponents-supplied-p (length initial-exponents))
     79                          (t (error "You must provide DIMENSION or INITIAL-EXPONENTS")))
     80          exponents (cond
     81                      ;; when exponents are supplied
     82                      (initial-exponents-supplied-p
     83                       (when (and dimension-suppied-p (/= dimension (length initial-exponents)))
     84                         (error "INITIAL-EXPONENTS must have length DIMENSION"))
     85                       (make-array (list dimension) :initial-contents initial-exponents
     86                                   :element-type 'exponent))
     87                      ;; when all exponents are to be identical
     88                      (initial-exponent-supplied-p
     89                       (make-array (list dimension) :initial-element initial-exponent
     90                                   :element-type 'exponent))
     91                      ;; otherwise, all exponents are zero
     92                      (t
     93                       (make-array (list dimension) :element-type 'exponent :initial-element 0)))))
     94  (call-next-method))
    9495
    9596;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Note: See TracChangeset for help on using the changeset viewer.