[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] tinyclos value matching?
From: |
Topher Cyll |
Subject: |
Re: [Chicken-users] tinyclos value matching? |
Date: |
Thu, 16 Mar 2006 19:38:34 -0800 |
Ah! Interesting, Alex. I'll have a look and try it out.
-Toph
On 3/16/06, Alex Shinn <address@hidden> wrote:
> At Thu, 16 Mar 2006 10:20:45 +0100, felix winkelmann wrote:
> >
> > On 3/15/06, Topher Cyll <address@hidden> wrote:
> > >
> > > Is there any way to specify generic methods on values instead of class
> > > in Chicken's tinyclos, like CLOS's (eql value) or Swindle's (singleton
> > > value) or (name = value) forms?
> >
> > TinyCLOS doesn't have anything like this built-in, I'm afraid.
> > But I think it might be possible with MOP hacking, since classes
> > can be generated easily.
>
> The attached allows you to write code like the following:
>
> (define-generic shortcut-add <value-generic>)
>
> (define-method (shortcut-add (x <number>) (y <number>))
> (print 'x+y)
> (+ x y))
>
> (define-method (shortcut-add (x <number>) (zero 0))
> (print 'x+zero)
> x)
>
> (define-method (shortcut-add (zero 0) (x <number>))
> (print 'zero+x)
> x)
>
> In general, you can specify any non-class value instead of a class.
> It matches if it's EQUAL? to the argument, and is always more specific
> than being an INSTANCE-OF? a class.
>
> The implementation overrides three methods: COMPUTE-METHOD (to match
> values), COMPUTE-METHOD-MORE-SPECIFIC? (to determine value matches are
> more specific), and COMPUTE-APPLY-GENERIC (to remove caching). You
> could put value-aware caching back in if you want.
>
> Unfortunately Chicken currently segfaults when you MAKE an inherited
> instance of <generic>:
>
> $ csi -q
> #;1> (define x (make-class (list <generic>) (list)))
> #;2> (make x)
> $
>
> so <value-generic> above is just an alias for <generic>, and the
> overrides apply to *all* methods. Once this is fixed, you'll be able
> to use the extension only for your chosen generics without any
> slowdown to tinyclos in general.
>
> --
> Alex
>
>
>
>
- [Chicken-users] tinyclos value matching?, Topher Cyll, 2006/03/15
- Re: [Chicken-users] tinyclos value matching?, felix winkelmann, 2006/03/16
- Re: [Chicken-users] tinyclos value matching?, Alex Shinn, 2006/03/16
- [Chicken-users] state of tinyclos ?, Rick Taube, 2006/03/20
- Re: [Chicken-users] state of tinyclos ?, felix winkelmann, 2006/03/21
- Re: [Chicken-users] state of tinyclos ?, Alex Shinn, 2006/03/24
- Re: [Chicken-users] state of tinyclos ?, Alex Shinn, 2006/03/27