Finding all objects derived from a specific object.
[1/9] from: wayne:knowngood at: 28-Oct-2006 12:30
I am working on some code where a series of objects will be derived from a central object called 'attribute'. Is there a way to list all of the new objects derived from 'attribute'? I have thought about using a global list that gets updated when a new attribute is created. So long as the update function is called it would work, but I was curious if there was an existing way to query the object hierarchy. Thanks for any help, Wayne
[2/9] from: lmecir::mbox::vol::cz at: 28-Oct-2006 11:42
Wayne Pierce napsal(a):
> I am working on some code where a series of objects will be derived > from a central object called 'attribute'. Is there a way to list all > of the new objects derived from 'attribute'? >
REBOL2 does not keep "hieararchy" informations, so you need to arrange it as you described below.
[3/9] from: wayne::knowngood::com at: 28-Oct-2006 16:46
I have been working on code to add or remove an value from a global variable, but can't get the removal portion working. When I remove an entry everything appears to be working fine in that no errors are given, but the value remains in the list. The returned value is 'g-profiles' with no modification. This is what my 'profile' object looks like: g-profiles: to-list  profile: make object! [ name: modified: desc: attribs: none init: func [ "Returns a new profile and registers the profile" p-name [string!] "Profile name" p-desc [string!] "Profile description" ][ name: p-name modified: now/date desc: p-desc attribs: to-list  g-profiles: append g-profiles name ] unset: func [ "Unregister the profile and clear all values" ][ g-profiles: exclude g-profiles to-list name modified: now/date name: desc: attribs: none ] ] When I create a profile with: t: make profile  t/init "Name" "Desc" Name is added to g-profiles successfully if the 'init' function is called. When I type: t/unset All of the variables except 'modified' are set to 'none', but "Name" is not removed from g-profiles. At first I was thinking this might be a name space issue, but adding the profile to g-profiles works with no problems. The same commands also work when typed into the console without using an object with no problems. I'm out of ideas on where to look next, does anyone have any suggestions on what the problem might be or where I should look? Thanks for any help, Wayne
[4/9] from: anton::wilddsl::net::au at: 29-Oct-2006 1:43
Hi Wayne, It looks like the misunderstanding is of EXCLUDE, which makes a copy. Have a look:
>> blk: [10 20 30]
== [10 20 30]
>> blk2: exclude blk 
== [20 30]
>> same? blk blk2
== false The solution is probably, first of all, to use a block! instead of a list!. Most of us use blocks for just about everything. I personally have never seen a great need for using a list! yet. Maybe you have good reasons for choosing list!, but g-profiles: copy  to replace this line: g-profiles: exclude g-profiles to-list name with this: remove find g-profiles name Also, you don't need to set 'g-profiles again in this line: g-profiles: append g-profiles name So removing the set-word, this is all that's left: append g-profiles name Let us know how it goes, Regards, Anton.
[5/9] from: volker:nitsch:gm:ail at: 29-Oct-2006 13:49
Am Samstag, den 28.10.2006, 16:46 +0300 schrieb Wayne Pierce: snip
> unset: func [ > "Unregister the profile and clear all values" > ][ > g-profiles: exclude g-profiles to-list name
The 'to-list is the problem. rebol checks types when searching. It looks for a list now, not a string.
> modified: now/date > name: desc: attribs: none > ] > ] >
[6/9] from: anton::wilddsl::net::au at: 30-Oct-2006 1:00
Not so, Volker. Exclude is one of those 'set' functions and it expects both its arguments to be the same type.
>> list: make list! [a b c]
== make list! [a b c]
>> exclude list to-list 'c
== make list! [a b] Regards, Anton.
[7/9] from: volker::nitsch::gmail::com at: 29-Oct-2006 17:27
Am Montag, den 30.10.2006, 01:00 +1100 schrieb Anton Rolls:
> Not so, Volker. > Exclude is one of those 'set' functions and it expects
<<quoted lines omitted: 3>>> >> exclude list to-list 'c > == make list! [a b]
Oh, right. But still, to-list loads, turning the string in a word. !>> to-list "a" == make list! [a] Better: !>> to-list reduce["a"] == make list! ["a"] And lists move the position silently, better to use 'head everywhere.
> Regards, > > Anton. >
[8/9] from: wayne::knowngood::com at: 31-Oct-2006 12:13
Anton, Thank you very much for the help, the code works as desired with your suggestions. I never had any practical reason for using a list over a block, I think it is just that I am used to using 'lists' in other languages. :/ From what I could tell in the Rebol/Core documentation the two appear to be very similar. Is there any reason you use blocks over lists? Thanks again for your help, Wayne On 10/28/06, Anton Rolls <anton-wilddsl.net.au> wrote:
[9/9] from: anton::wilddsl::net::au at: 1-Nov-2006 21:02
Wayne, Glad to be of assistence. Yes, blocks load more directly into rebol. By that I mean it's easy to write just  which loads as a block!, rather than having to write make list!  all over the place. So your code will be more concise and easier to read when using blocks. Trust me, we all use blocks 99% of the time. List!s and block!s have different time characterstics for each supported operation (insert, remove, etc.). I can't remember the details, because it's never been an issue for me, however a quick search on google for: list block insert remove "constant time" rebol found me this page: http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-message.r?m=rmlMFRQ There have been discussions on this subject in the past, try rebol.org mail list search some more, should yield more detail. list! also behaves a bit differently than other series! with regard to INSERT; Using INSERT moves the list series index to the end of the inserted data. Which can be confusing, eg: list: make list! ["b"] insert list "a" list ;== make list! ["b"] ; <-- what ? head list ;== make list! ["a" "b"] ; <-- oh, I see list: head list ; <-- let's fix it permanently Compare to block (and other series): blk: copy ["b"] insert blk "a" blk ;== ["a" "b"] ; <-- ok, series index is still at the head There might be other differences as for INSERT. I don't know, I don't use list at all. Regards, Anton.
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted