Antsan
2/8/2016 3:04:00 PM
Am Montag, 8. Februar 2016 15:59:55 UTC+1 schrieb Taoufik Dachraoui:
> On Monday, February 8, 2016 at 3:21:36 PM UTC+1, Antsan wrote:
> > Am Montag, 8. Februar 2016 15:04:58 UTC+1 schrieb Taoufik Dachraoui:
> > > Hi
> > >
> > > I find that it is unfortunate that + (- * / ...) are non generic functions
> > >
> > > I wanted to create a new subtype of number and use it in my programs
> > > without modifying the code, but being unable to define the method +,*,..
> > > on the new type is a stopper.
> > >
> > > what do you think about this?
> > >
> > > Kind regards
> > > Taoufik
> >
> > It's a well-known problem.
> > To work around this, you can do something like this:
> >
> > (defpackage #:generic-arithmetic
> > (:use #:cl)
> > (:shadow #:+ #:- #:* #:/)
> > (:export #:+ #:- #:* #:/))
> >
> > (in-package #:generic-arithmetic)
> >
> > (defgeneric + (a b) ; because it would be kind of hard to define
> > ; this correctly for &rest parameters - although it
> > ; probably is possible
> > (:method ((a number)
> > (b number))
> > (cl:+ a b)))
> >
> > and so on.
>
> Thanks
>
> Is it possible to redefine ccl::%make-ratio, such that (/ 2 3) will call the redefined %make-ratio?
>
> Kind regards
> Taoufik
I have no idea. I don't think so. This wouldn't be portable either way.