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

Series of objects

 [1/8] from: mattsmac:hot:mail at: 22-Aug-2003 10:54


I have a series of connections calles clients, what I want to do is find a particular one of those connections, with index i, and change the user name etc. In C or other languages it would be somewhat in the form: 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 Matt

 [2/8] from: tomc:darkwing:uoregon at: 22-Aug-2003 8:12


clients/:i/user: ^ | On Fri, 22 Aug 2003, Matt MacDonald wrote:

 [3/8] from: g:santilli:tiscalinet:it at: 22-Aug-2003 17:19


Hi Matt, On Friday, August 22, 2003, 4:54:53 PM, you wrote: MM> I'm trying to use a command like: clients/i/user: "Bob" but REBOL tries to MM> look for a path named i rather than the ith element. Any pointers? clients/:i/user: "Bob" A less concise way to do the same is: set in pick clients i 'user "Bob" In case you find it more readable With parenthesis, set (in (pick clients i) 'user) "Bob" Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [4/8] from: petr:krenzelok:trz:cz at: 22-Aug-2003 17:20


Matt MacDonald wrote:
>I have a series of connections calles clients, what I want to do is find a >particular one of those connections, with index i, and change the user name >etc. >In C or other languages it would be somewhat in the form: > >clients[i].user = "Bob" > >I'm trying to use a command like: clients/i/user: "Bob" but REBOL tries to >
clients/:i/user -pekr-

 [5/8] from: maximo:meteorstudios at: 22-Aug-2003 11:31


> clients/:i/user: > ^ > |
hi all, has this always been possible, or was is added at/after v2.0 of core? I can't remember reading about it before... maybe when I saw it the first time I hadn't understood and simply forgot about it.. I which I'd known about this a long time ago. ( realized it just a little while ago ). I wonder all the other tricks I have yet to discover... I wonder if RT will ever add this functionality too: :path/thing instead of get in path 'thing -MAx

 [6/8] from: greggirwin:mindspring at: 22-Aug-2003 9:38


Welcome to REBOL Matt! MM> I have a series of connections calles clients, what I want to do is find a MM> particular one of those connections, with index i, and change the user name MM> etc. MM> In C or other languages it would be somewhat in the form: MM> clients[i].user = "Bob" MM> I'm trying to use a command like: clients/i/user: "Bob" but REBOL tries to MM> look for a path named i rather than the ith element. Any pointers? BTW I MM> am very new to REBOL and I'm sure this is an easy problem It's simple, but not obvious. :) You need to prepend a colon to the word you want REBOL to "dereference". clients: [Joe Bob Sue Sandra] repeat i length? clients [ print clients/:i ] clients: [ [id #001 user Joe] [id #002 user Sue] ] repeat i length? clients [ print [clients/:i/id clients/:i/user] ] This mailing list is perhaps the best resource for REBOL. Great folks here. Happy REBOLing! -- Gregg

 [7/8] 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.

 [8/8] from: maximo:meteorstudios at: 22-Aug-2003 11:55


> >I'm trying to use a command like: clients/i/user: "Bob" > but REBOL tries to > > > > > clients/:i/user >
might I add (just for education's sake) that you can also use the trick to point in an object using a word's value as its attribute. ;=========================================================== familly: make object! [ dad: "Mr. grumpy" mom: "Ms. smiley" sister: none ] member: 'mom print familly/:member ;=========================================================== also, I usually do:
>> do load clipboard://
to load code on the os clipboard, instead doing paste... it doesn't print all the code and if you press the up arrow, you do not have to skip all the code line by line, in order to get back to your last commands... HTH! -MAx