Hallo,
I've questions dealing with the calls system underlying numbers:
Is it possible to extend this class system, let me say by intervall
arithmetics in way which enables me to use intervalls instead of
numbers without changing my own defined number crunching functions?
Is it possible to define a class 'intervall' as subclass of 'number'?
If so how can I do it ?
Thanks
Jens
--------------------------------------------------------------------------------
Dipl.-Ing. Jens Franzen Tel. +49-511-762-5039
Laboratorium fuer Informationstechnologie Fax. +49-511-762-5051
University of Hannover Telex. 923868 unihn d
Schneiderberg 32 Email
D-30167 Hannover ·······@scoop.ims.uni-hannover.dbp.de
Fed. Rep. of Germany
--------------------------------------------------------------------------------
In article <·····················@newsserver.rrzn.uni-hannover.de> ·······@mars.lfi-main.uni-hannover.de (Jens Franzen) writes:
>I've questions dealing with the calls system underlying numbers:
>
> Is it possible to extend this class system, let me say by intervall
> arithmetics in way which enables me to use intervalls instead of
> numbers without changing my own defined number crunching functions?
> Is it possible to define a class 'intervall' as subclass of 'number'?
I assume you're talking about Common Lisp and CLOS.
No, there is no mechanism for defining subclasses of any classes of
metaclass BUILT-IN-CLASS. Also, none of the standard mathematical
functions are required to be CLOS generic functions, so even if you could
define subclasses of NUMBER, you wouldn't be able to pass instances of them
to functions like +.
In article <··················@telecaster.think.com>, ······@think.com (Barry Margolin) writes:
> In article <·····················@newsserver.rrzn.uni-hannover.de> ·······@mars.lfi-main.uni-hannover.de (Jens Franzen) writes:
> >I've questions dealing with the calls system underlying numbers:
> >
> > Is it possible to extend this class system, let me say by intervall
> > arithmetics in way which enables me to use intervalls instead of
> > numbers without changing my own defined number crunching functions?
> > Is it possible to define a class 'intervall' as subclass of 'number'?
>
> I assume you're talking about Common Lisp and CLOS.
>
> No, there is no mechanism for defining subclasses of any classes of
> metaclass BUILT-IN-CLASS. Also, none of the standard mathematical
> functions are required to be CLOS generic functions, so even if you could
> define subclasses of NUMBER, you wouldn't be able to pass instances of them
> to functions like +.
The following is an untested example of a workaround:
define a class INTERV (intervall) and define arithmetic
operations (+ - * etc.) as generic function in your own
application package then specialize these arithmetic methods
on the first argument to implement your own version of arithmetic
operation on intervall objects. Of course this assumes the rest
arguments are all from the same class (e.g. INTERV).
(defpackage "INTV" (:use "COMMON-LISP")
(:shadow "+" "-" "*" "/" ">" "<" "=" "MIN" "MAX"))
(defclass intv ()
((inf :initform 0 :accessor intv-inf)
(sup :initform 0 :accessor intv-sup)))
;;; If you need to use + on numbers in this package as well INTV.
;;; [and repeat for each arithmetic operation supported on INTV]
(defmethod + ((num t) &rest more-nums)
(apply #'common-lisp::+ num more-nums))
(defmethod + ((intv intv) &rest more-intvs)
;; Write your own definition of what it means to add two intervalls
(let ((result (make-instance 'intv :inf (intv-inf intv)
:sup (intv-sup intv))))
(mapc #'(lambda (x)
;; note incf is not shadowed
(incf (intv-inf result) (intv-inf x))
(incf (intv-sup result) (intv-sup x)))
more-intvs)
result))