Re: How to write *include* like Ruby?

lijie <[email protected]> Sun, 20 May 2012 09:33:34 +0800
Newsgroups gmane.comp.lang.io
Message-ID <CABQ_Gq=nxA2P08c4XN0v2JBxh9OcmnLLvenpEQHLVKmMJPfQMA@mail.gmail.com>
Hi Jeremy,

Agree to ignore the type slot, most of the time it just makes me feel a bit
better when logging and debugging.


Li Jie

On Sun, May 20, 2012 at 4:23 AM, Jeremy Tregunna <[email protected]>wrote:

> **
>
>
> This happens because if an object doesn't have a type slot (which a fresh
> Object clone won't) we copy over the type slot in the trait. If this is
> really not a big deal at all, since anyone doing type comparison based on
> the type slot should have more common sense. I'd like to deprecate the type
> slot actually, but it's presently used in output in the REPL.
>
> Alternatively, you can always ignore the type slot, but that will require
> changing A0_Object.io in libs/iovm/source/io and I would strongly not
> recommend this at all.
>
> Regards,
>
> Jeremy Tregunna
>
> On Saturday, 19 May, 2012 at 8:48 AM, lijie wrote:
>
>
>
> Hi,
>
> I want to write Io code like Ruby meta programming. *Module#include* is an
> important method to extend classes.
>
> In Io, I wrote some code:
>
> include := method (module,
>   call sender addTrait(module)
> )
>
> Validations := Object clone do (
>   validate := method(args,
>     "validate" println
>   )
> )
>
> Person := Object clone do (
>   include(Validations)
> )
>
> Person println
>
>
> outputs:
>
>  Validations_0x7fd8a8c8d440:
>   type             = "Validations"
>   validate         = method(args, ...)
>
>
>
> The type of Person is "Validations".
>
> Then I try to call *include* after create Person:
>
> Person := Object clone
>
> Person do (
>   include(Validations)
> )
>
>
> outputs:
>
>  Person_0x7f90ab496ee0:
>   type             = "Person"
>   validate         = method(args, ...)
>
>
> This is my expectation. But I want to do all things in the prototype
> creation. How to write the corrective *include* method?
>
>
>
>   
>