Hi, Arnoux

It's simple (simpler than that, actually ;-)

Arnoux Vincent wrote:
> Hi List,
> I have a list of objects:
> /l: copy []
> obj: make object! [ a: none calc: does [self/a: (self/a + 1)]]
> append l make obj [a: 1]
> append l make obj [a: 2]/
> 
> I would like to write a function like:
> /inc-obj: func [arg][
>     arg/calc
> ]/
> 
> That would allow me to do:
> /foreach o l [
>     inc-obj o
> ]
> /
> And output:
> /probe (first l)/a/
> /2
> //probe (second l)/a/
> /3
> 
> /Is it possible ?
> 

Yes, and you don't need the overhead of INC-OBJ or the repeated uses
of SELF within the method on your objects.  See transcript below:

 >> proto: make object! [
[    count: 0
[    bump: func [] [count: count + 1]
[    ]
 >> obj-block: []
== []
 >> repeat i 4 [append obj-block make proto [count: i]]
== [
     make object! [
         count: 1
         bump: func [][count: count + 1]
     ]
     make object! [
         count: 2
        ...
 >> foreach obj obj-block [obj/bump]
== 5
 >> foreach obj obj-block [print obj/count]
2
3
4
5
 >>


-- 
----------------------------------------------------------------------
Joel Neely            joelDOTneelyATfedexDOTcom           901-263-4446

Counting lines of code is to software development as
counting bricks is to urban development.


-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to