chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] coops


From: Felix
Subject: Re: [Chicken-users] coops
Date: Tue, 25 Jan 2011 13:41:08 +0100 (CET)

From: address@hidden
Subject: Re: [Chicken-users] coops
Date: Wed, 19 Jan 2011 03:09:22 +0100

>> The version you install is 1.1
> 
> Then a new version does not solve my problem. Here is some code:
> 
> (define-generic (show s))
> 
> (define-method (show (s <number>))
>   (number->string s))
> 
> (define-method (show (s <symbol>))
>   (symbol->string s))
> 
> (define-method (show (s <pair>))
>   (string-append "(" (show (car s)) "," (show (cdr s)) ")"))
> 
> (define-method (show (s <list>))
>     (apply string-append (map show s)))
> 
> I expected that (show '(1 2 3 4)) is evaluated to "123". But the
> specialized method for <list> is only called if the value of s is
> <null>. Instead the method for <pair> is called and is evaluated to
> "(1,(2,(3,(4,(5,)))))". My problem is that <pair> is always preferred
> because <pair> is a subclass of <list>. If i change some lines in
> coops-primitive-objects.scm so that <list> is a subclass of <pair>
> everything works fine.

I have tagged yet another version (1.4), which should work better.
The problem was (IMHO), that `<list>' should be an abstract supertype,
and not a primitive type, which is checked for by a predicate. Since
the type-predicate is not disjoint from the one for `<pair>' (and
`<null>'), this leads to one type being preferred over the other,
even if this is not desired.

So you example above should basically work, but note that the method
for `<pair>' will always override the one for `<list>', since the
latter is a supertype of the former.


cheers,
felix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]