Funny, that's almost exactly what I came up with when I implemented
it, except mine is a bit more involved, because mixins come with
associated generic words, and mixins can inherit from each other, and
there's a delegation mechanism, and a few other things. But a more
minimal solution like you have might be better. Here's the code:
http://wee-url.com/responder/pastebin/show-paste?n=220
On 8/1/07, Slava Pestov <[EMAIL PROTECTED]> wrote:
> Hi Dan.
>
> I have a somewhat different proposal.
>
> Tested, but might not be 100% correct.
>
> --------8<----------
>
> : mixin-predicate-quot ( class -- quot )
> "members" word-prop [ >r class r> memq? ] curry ;
>
> : define-mixin ( word -- )
> dup V{ } clone "members" set-word-prop
> dup define-class
> dup predicate-word over mixin-predicate-quot
> define-predicate ;
>
> : add-instance ( class mixin -- )
> tuck "members" word-prop push define-class ;
>
> : MIXIN: CREATE define-mixin ; parsing
>
> : INSTANCE: scan-word scan-word add-instance ; parsing
>
> ! Example
>
> MIXIN: sequence
> INSTANCE: array sequence
>
> M: sequence nth bounds-check nth-unsafe ;
>
> --------8<----------
>
> Slava
>
> On 31-Jul-07, at 8:13 AM, Daniel Ehrenberg wrote:
>
> > Dharmatech's idea of a fully class-based object system is a good one,
> > but here's another idea: bringing Factor's object system a little
> > closer to Haskell type classes. I, unlike Ed, don't have any code on
> > it yet (which is a bad thing), but I have the proposal at
> > http://useless-factor.blogspot.com/2007/07/how-to-make-ad-hoc-
> > polymorphism-less-ad.html
> > (Apologies for the grandiose title.) Comments?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk