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

Nested Series

 [1/5] from: eric:mccinc at: 20-Oct-2000 9:46


Hey Guys, I hope yall can help me with this one. I realize that this may be a simple concept that I just may be missing the boat on. (I sure hope so, I would hate to think I was stupid. lol) Anyway, I have data that is best represented by a nested structure in the form of [document [node1 [Subnode1 data1 data2] [Subnode2 [subnode3 data2 data2 data3] ] ] [node2 data1 data2] [node3 [subnode1 data1 data2] ] ] This is much like the values returned by the parse-xml function. I hade in fact considered using the xml to represent my data in a file. My problem is that I need to manipulat this structure based in the node names. I need the capability to insert update and delete. Like I said I may be just missing something here but for the life of me I can't figure it out. I had thought of using index values off of the find or select but that is not support. I realize that this is basic core stuff to rebol, I am just having real trouble getting my mind around. The structure keeps behaving in ways that I do not expect, I realize this is a fault on my part, but I could use a little explanation. Please realize that I am new to rebol (though an instant convert) and this is VERY diffrent from the java code I usually wright. Thanks every one.

 [2/5] from: eric_merritt/rh/mccinc%mccinc:mcc-associates at: 19-Oct-2000 23:48


Hey Guys, I hope yall can help me with this one. I realize that this may be a simple concept that I just may be missing the boat on. (I sure hope so, I would hate to think I was stupid lol) Anyway, I have data that is best represented by a nested structure in the form of [document [node1 [Subnode1 data1 data2] [Subnode2 [subnode3 data2 data2 data3] ] ] [node2 data1 data2] [node3 [subnode1 data1 data2] ] ] This is much like the values returned by the parse-xml function. I hade in fact considered using the xml to represent my data in a file. My problem is that I need to manipulat this structure based in the node names. I need the capability to insert update and delete. Like I said I may be just missing something here but for the life of me I can't figure it out. I had thought of using index values off of the find or select but that is not support. Please realize that I am new to rebol (though an instant convert) and this is VERY diffrent from the java code I usually right. Thanks every one.

 [3/5] from: ryanc::iesco-dms::com at: 20-Oct-2000 11:17


-- Unable to decode HTML file!! --

 [4/5] from: govergard::hotmail at: 20-Oct-2000 14:29


I just finished dealing with a problem like this. The viability of the solution depends on whether you know what contains what. If it is totally free format, it is slightly more complex (still doable, just need to include additional information). Basically the solution is to declare the structures you need with the paths they would require in a flat format, for example
>> outside: [ path1 none path2 none]
== [path1 none path2 none]
>> inside: [ element1 none element2 none ]
== [element1 none element2 none]
>> to: copy outside
== [path1 none path2 none]
>> ti: copy inside
== [element1 none element2 none]
>> ti/element1: "hello"
== [element1 "hello" element2 none]
>> to/path1: ti
== [path1 [element1 "hello" element2 none] path2 none]
>> to/path1/element1
== "hello" --hope this helps Gary

 [5/5] from: ryanc:iesco-dms at: 20-Oct-2000 13:45


Hello Eric, your data structure appears a bit "loose" to me. Perhaps if it was more strict it might be easier to manipulate. I would consider a data structure such as this: data-structure: [ document [ node1 [ Subnode1 ["data1" "data2"] Subnode2 [ Subnode3 ["data1" "data2" "data3"] ] ] node2 ["data1" "data2" "data3"] node3 [ subnode1 ["data1" "data2"] ] ] ] The methodology behind the data structure I have shown is that any word! follows a block of data. Therefore a node would be of type word. Your "data" is limited to not being a word, blocks could be ok, I shown only strings in my example for simplicity. If blocks of nodes would only contain nodes, and blocks of data only individual data elements, then parsing this structure would be very easy. Example functions: node?: func [b [block!]] [word? first b] data?: func [b [block!]] [not word? first b] list-thingy: func [ b [block!] /recursion depth [integer!] ] [ if not recursion [ depth: 0 ] either node? b [ foreach [nd blk] b [ for I 0 depth .2 [prin "-"] print nd list-thingy/recursion blk (depth + 1) ] ][ foreach d b [ for I 0 depth .2 [prin "-"] print d ] ] ] And the data structure can be used as such:
>> data-structure/document/node2
== ["data1" "data2" "data3"]
>> >> select data-structure 'document
== [ node1 [ Subnode1 ["data1" "data2"] Subnode2 [ Subnode3 ["data1" "data2" "data3"] ] ...
>>
If this structure does not work for you, it at least is a good demonstration of how to use rebols numerous data types to your advantage. When I work with data in rebol I think alot about types, quite the contrary to other languages. Data types are one of the 7 sacred powers in rebol. --Ryan [eric--mccinc--com] wrote: Hey Guys, I hope yall can help me with this one. I realize that this may be a simple concept that I just may be missing the boat on. (I sure hope so, I would hate to think I was stupid. lol) Anyway, I have data that is best represented by a nested structure in the form of [document [node1 [Subnode1 data1 data2] [Subnode2 [subnode3 data2 data2 data3] ] ] [node2 data1 data2] [node3 [subnode1 data1 data2] ] ] This is much like the values returned by the parse-xml function. I hade in fact considered using the xml to represent my data in a file. My problem is that I need to manipulat this structure based in the node names. I need the capability to insert update and delete. Like I said I may be just missing something here but for the life of me I can't figure it out. I had thought of using index values off of the find or select but that is not support. I realize that this is basic core stuff to rebol, I am just having real trouble getting my mind around. The structure keeps behaving in ways that I do not expect, I realize this is a fault on my part, but I could use a little explanation. Please realize that I am new to rebol (though an instant convert) and this is VERY diffrent from the java code I usually wright. Thanks every one. -- To unsubscribe from this list, please send an email to [rebol-request--rebol--com] with "unsubscribe" in the subject, without the quotes. -- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400 I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world. -Einstein