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

[REBOL] [SCRIPT] select/deep

From: coussement:c:itc:mil:be at: 2-Feb-2001 9:07

Hi REBOLians: Because the dat I use are stored into deep-nested blocks, I had to use multiple select statement to acces it:
>> b: [label1 [label2 [label3 [data1 label4 [data2]]]]] >> select select select b 'label1 'label2 'label3
== [data1 label4 [data2]] It works fine, but it does not help readability and takes a lot of place ! SO, I thought of: select-deep: func [ data [block!] arg1 [any-word!] arg2 [any-word! unset!] arg3 [any-word! unset!] arg4 [any-word! unset!] arg5 [any-word! unset!] ][ either value? 'arg2 [ either value? 'arg3 [ either value? 'arg4 [ either value? 'arg5 [ return select select select select select data arg1 arg2 arg3 arg4 arg5 ][ return select select select select data arg1 arg2 arg3 arg4 ] ][ return select select select data arg1 arg2 arg3 ] ][ return select select data arg1 arg2 ] ][ return select data arg1 ] ] which could be used:
>> select-deep b 'label1
== [label2 [label3 [data1 label4 [data2]]]]
>> select-deep b 'label1 'label2
== [label3 [data1 label4 [data2]]]
>> select-deep b 'label1 'label2 'label3
== [data1 label4 [data2]]
>> first select-deep b 'label1 'label2 'label3
== data1
>> select-deep b 'label1 'label2 'label3 'label4
== [data2]
>> first select-deep b 'label1 'label2 'label3 'label4
== data2 which seems a little bit more practical to me. I like this approach, but there's for sure a more elegant solution to it... Any idea ? Regards, chr==