Hi, Rebols, sending the version 3.0.0.1 of Methods.

Is there anyone wanting to write a Rebol Class Hierarchy?

Rebol[
    Title: "Methods"
    File: %methods.r
    Author: "Ladislav Mecir"
    Email: [EMAIL PROTECTED]
    Date: 5/1/2000
    Version: 3.0.0.1
]

;Function to create methods, adds the hidden SELF argument
meth: func [args body] [
    func append copy [self] args body
]

; a helper function used to get object and method
obj-meth: func[self [object!] method [word!]] [
    reduce [in self/class method self]
]

;Function implementing a method calling dialect
!: func [meth-dialect [block!] /local state] [
    state: do/next append copy [obj-meth] meth-dialect
    do append first state second state
]

;end of %methods.r

;now the example:

some-class: make object! [
    ; Methods
    sumnum: meth [which [integer!] other [object!]] [
         switch which [
            1 [self/num]
            2 [(! [other 'sumnum 1 self]) + (! [self 'sumnum 1
other])]
        ]
    ]
    ; "Static" attribute
    statnum: 0
    ; Constructor
    inst: func [] [
        statnum: statnum + 1
        make object! [class: some-class num: statnum]
    ]
]

a: some-class/inst
b: some-class/inst
! [a 'sumnum 1 b]
! [b 'sumnum 1 a]
! [a 'sumnum 2 b]





Reply via email to