Hi Sabu
maybe something like this
search-obj: func [
obj member
/deep
/local val result son
] [
result: make block! 2
if val: get in obj member [
append result val
]
if deep [
val: third obj
while [val: find val object!] [
if not empty? son: search-obj/deep first val member [
append/only append result to-word first back val son
]
val: next val
]
]
result
]
But then you could easily use a block structure instead of an object.
AR
Sabu Francis wrote:
> Hi:
> I have a tree object wherein I want to search the value of a member (or
> return none). I have got this function "getValInObject"
> but it searches shallowly. I want an option so that it can either search
> shallow or deep (breadth first, or depth first) through the tree structure.
> Forgive me if I am a bit lazy in working this out myself.
>
> I would be grateful if someone can point correct this. Also I would be even
> more grateful if I can get a function where I can take the possible value of
> a member and return the parent object where the member is nested into. For
> e.g. In the example below I should have a function which will return the
> object "Me" when asked to search that object where the clan is "Vadukkut"
> (Something like a reverse search?)
>
> Forgive my terminologies. I am not a computer programmer in the traditional
> sense.
>
> Regards
> SF
>
>
> clanobj: make object! [clan: none Name: "Ahem"]
>
> Me: make object! [ Name: "Sabu" Surname: "Francis" Family: make clanobj [
> clan: "Vadukkut"] ]
>
> ;Get a Value anywhere inside the object ... searches shallowly all nested
> objects
>
> getValInObject: func [object Member /local val v][
>
> val: get in object Member
> either val <> none [return val]
> [
> foreach word next first object [
> v: get in object word
> if object! = type? v [
> return getValInObject v Member
> ]
> ]
> ]
>
> ]
>
> ;this gets the right result
> print getValInObject Me 'clan
>
> ;but I want this result to come as "Ahem"
> print getValInObject Me 'Name
>
>
>
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.