Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Series of objects

From: joel:neely:fedex at: 22-Aug-2003 10:30

Hi, Matt, Matt MacDonald wrote:
> clients[i].user = "Bob" > > I'm trying to use a command like: clients/i/user: "Bob" but REBOL tries to > look for a path named i rather than the ith element. Any pointers? BTW I > am very new to REBOL and I'm sure this is an easy problem >
There are at least two answers... * The quick one: clients/:i/user: "Bob" uses the value of I rather than the word I as the path selector. * The longer one: How are you establishing the value of I to begin with? If you are examining the objects for the one that meets some criterion, and then changing an attribute of that object, you don't need to use an index at all, as illustrated by copying the followind and pasting into a REBOL console. ================================================================ protoClient: make object! [ id: 0 user: "" greet: func [] [ print ["Hello to" user "(" id ")"] ] ] clients: [] append clients make protoClient [id: 123 user: "George"] append clients make protoClient [id: 234 user: "Martha"] append clients make protoClient [id: 345 user: "Abe"] append clients make protoClient [id: 456 user: "Mary"] setUserWithID: func [id [integer!] user [string!]] [ foreach client clients [ if client/id = id [client/user: user exit] ] ] print mold clients setUserWithID 345 "Abraham" print mold clients ================================================================== -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 Counting lines of code is to software development as counting bricks is to urban development.