Hi, Rebols, sending the version 3.0.0.0 of Methods,
using some of Elan's suggestions (thx!).
It look qiute nice, thx to Rebol.

To Elan: the nonreentrant version of ! doesn't work in the example written
at the end of this.
(Comment - your method of static storage is a "cheap currying", but it's got
some problems...
To be fair, my currying has some problems too - see curried functions
thread, so i decided not to use currying, but instead hide the argument
passing process under ! implementation)

-Ladislav

Rebol[
    Title: "Methods"
    File: %methods.r
    Author: "Ladislav Mecir, used some Elan's suggestions"
    Email: [EMAIL PROTECTED]
    Date: 3/12/1999
    Version: 3.0.0.0
    ]

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

;Function to call methods
!: func [self [object!]  'method [word!] param [block!]] [
    do append reduce [in self/methods method self] param
    ]

;end of %methods.r

;now the example:
a: make object! [
    num: 1
    methods: make object! [
        get-num: makemethod [ ] [self/num]
        sumnum: makemethod [other [object!]] [(! self get-num []) + (! other
get-num [])]
        ]
    ]
b: make a [num: num + 1]
print ! a sumnum [b]

Reply via email to