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

Object "names" ?

 [1/4] from: kpeters::otaksoft::com at: 28-May-2009 18:22


Thanks guys - here's another question: template: make object! [ count: 0 ] a: make template [] b: make template [] c: make template [] objs: [] append objs a append objs b append objs c probe objs [make object! [ count: 0 ] make object! [ count: 0 ] make object! [ count: 0 ]] == [make object! [ count: 0 ] make object! [ count: 0 ] make object! [ count: 0 ]]
>>
Now I want to cycle though the objects in the objs block and print their names: foreach obj obs [ print ???? ] I cannot seem to get at it - but find has no problems finding them by 'name' as in probe first find objs a TIA Kai

 [2/4] from: moliad:gm:ail at: 29-May-2009 0:34


kai when you add the objects, you aren't adding the word which refers to the object, you are adding the objects themselves. if you need the words which refer to the objects instead try this: template: make object! [ count: 0 ] a: make template [] b: make template [] c: make template [] objs: [a b c] probe objs foreach item objs [print item probe get item] but the above can be problematic in some circumstances, so it depends on the context of how/when you are using the above. -Max On Thu, May 28, 2009 at 9:22 PM, Kai Peters <kpeters-otaksoft.com> wrote:

 [3/4] from: sqlab:gmx at: 29-May-2009 8:15


You could append the unevaluated object names in addition too as in append append objs 'a a .. then you can cycle with foreach [name obj] objs [print name] Kai Peters wrote:

 [4/4] from: carl:cybercraft at: 29-May-2009 19:03


Hi Kai, Taking a guess at what you might be doing with this, an approach like this might be better... template: make object! [ count: 0 ] objs: [] append objs reduce [ 'a make template [] ] append objs reduce [ 'b make template [] ] append objs reduce [ 'c make template [] ] That creates a block of word/object pairs which can then be accessed like this...
>> objs/a/count
== 0
>> objs/b/count
== 0
>> objs/b/count: 2
== 2
>> objs/b/count
== 2
>> objs/a/count
== 0 It sounds like you're creating some kind of database, and there's a limit to the number of words that REBOL can handle when they reference a value. (Others can rephrase that more correctly...) There's no limit to the number of words that can be stored in a block though. And being in a block, you'd be able to sort them by name as well, if required. ie...
>> foreach [word object] objs [print word]
a b c
>> sort/reverse/skip objs 2
== [c make object! [ count: 0 ] b make object! [ count: 2 ] a make object! [ count: 0 ]]
>> foreach [word object] objs [print word]
c b a Oh, and the reason your... probe first find objs a seemed to work is it was looking in objs for the object referenced by 'a and not for the word 'a. ie, this would fail... probe first find objs 'a Hope that helps. -- Carl Read. On Thursday, 28-May-2009 at 18:22:48 Kai Peters wrote,