Fast transformation?
[1/8] from: kpeters:otaksoft at: 27-Nov-2007 12:17
What is a good way to transform blocks like
[ [ "Bill" 50 ] [ "Jane" 45 ]]
to
[ "Bill" 50 "Jane" 45 ]
TIA,
Kai
[2/8] from: tom:conlin:g:mail at: 27-Nov-2007 12:30
Kai Peters wrote:
> What is a good way to transform blocks like
>
> [ [ "Bill" 50 ] [ "Jane" 45 ]]
>
> to
>
> [ "Bill" 50 "Jane" 45 ]
>
> TIA,
> Kai
>
[3/8] from: gregg:pointillistic at: 27-Nov-2007 13:31
Hi Kai,
KP> What is a good way to transform blocks like
KP> [ [ "Bill" 50 ] [ "Jane" 45 ]]
KP> to
KP> [ "Bill" 50 "Jane" 45 ]
flatten: func [blk [block!] /local res rule value] [
res: copy[]
rule: [some [into rule | set value skip (append res value)]]
parse blk rule
res
]
-- Gregg
[4/8] from: tom::conlin::gmail::com at: 27-Nov-2007 12:35
Kai Peters wrote:
> What is a good way to transform blocks like
>
> [ [ "Bill" 50 ] [ "Jane" 45 ]]
>
> to
>
> [ "Bill" 50 "Jane" 45 ]
>
> TIA,
> Kai
>
for speed I might try
flat: to block! form nested-blocks
[5/8] from: gregg::pointillistic::com at: 27-Nov-2007 14:59
Hi Tom,
>> [ [ "Bill" 50 ] [ "Jane" 45 ]]
t> flat: to block! form nested-blocks
That won't preserve the data though; it can change things.
-- Gregg
[6/8] from: tom:conlin:g:mail at: 27-Nov-2007 14:10
hmmm I am not seeing mail I sent to the list via gmail
and yes that only has a chance in the simplest of conditions
>> nested-blocks: [[1][2][3]]
== [[1] [2] [3]]
>> flat: to block! form nested-blocks
== [1 2 3]
but sometimes that is all that is needed.
Gregg Irwin wrote:
[7/8] from: dhsunanda::gmail at: 25-Nov-2007 6:06
Kai:
> What is a good way to transform blocks like
>
> [ [ "Bill" 50 ] [ "Jane" 45 ]]
May have fewer side effects than some of the solutions to date:
new-block: copy []
foreach b [ [ "Bill" 50 ] [ "Jane" 45 ]] [
append new-block b
]
>> new-block
== ["Bill" 50 "Jane" 45]
Though if you want to deblock more nested structures, some more
work is needed.
Sunanda
[8/8] from: Izkata::Comcast::net at: 28-Nov-2007 2:21
Similar to the strategy I was thinking, except I'm a fan of the funnier
looking stuff - taking advantage of the "code is data" idea:
(Copied from console then re-spaced for clarity)
>> NewBlock: foreach Val Others: [
[{Bill} 50] [{Jane} 45] [[{Dan} 19] [{Rich} 20]]
] copy/deep [
either block? Val [
append Others Val
][
append [] Val
]
]
== ["Bill" 50 "Jane" 45 "Dan" 19 "Rich" 20]
On Sun, 2007-11-25 at 06:06 +0000, Sunanda wrote: