[REBOL] Re: Block building
From: carl:cybercraft at: 25-Nov-2002 17:53
On 25-Nov-02, Ted and Suzanne Landis wrote:
> Hi all,
> I am relatively new to REBOL and would like to know what is
> considered best practice in the following situation:
> Given the following object:
>>> probe Object1
> make object! [
> String1: "ABC"
> Block1: ["DEF" "GHI"]
> Block2: ["JKL" "MNO" "PQRSTUVWXYZ"]
> ]
> I need to build a block containing all of the string fields:
> ["ABC" "DEF" "GHI" "JKL" "MNO" "PQRSTUVWXYZ"]
> I have found two ways to do it:
>>> compose [(Object1/String1) (Object1/Block1) (Object1/Block2)]
> and
>>> head insert (union Object1/Block1 Object1/Block2)
> Object1/String1
> Comments? Suggestions?
As someone said, there's lots of ways to choose from. Here's a couple
more...
>> head insert join object1/block1 object1/block2 object1/string1
== ["ABC" "DEF" "GHI" "JKL" "MNO" "PQRSTUVWXYZ"]
That works, but isn't easily modified. This one's better I think...
>> extract reduce [Object1/String1 Object1/Block1 Object1/Block2] 1
== ["ABC" "DEF" "GHI" "JKL" "MNO" "PQRSTUVWXYZ"]
Even so, your compose version is hard to beat, assuming you've no need
for a general-purpose routine to extract arbitary strings and blocks
of strings from an object.
--
Carl Read