rex — 10-Feb-2014/6:55:45-8:00
I tried
copy/deep/types block string!
But it still copies all values in the block, whether they are strings or not. I am wondering how does copy/types work?
Nick — 10-Feb-2014/20:11:37-8:00
That refinement doesn't exist in R2, and doesn't appear to be implemented in R3 (at least not in the current Saphirion release or the versions published at http://www.rebolsource.net/).
Try this:
R E B O L []
remove-type: func [lst my-type] [
foreach item lst [
if block! = (type? item) [remove-type item my-type]
repeat i (length? lst) [if my-type = type? pick lst i [remove at lst i]]
]
]
x: [12 "ads" 343 "sodf" $12.23 [123 4343 "sdadfdf" "idsf" 2-feb-2014 ["asdafdf" "sduf" 25 23]]]
y: copy/deep x
z: copy/deep x
remove-type y string!
remove-type z integer!
probe y
probe z
halt
Nick — 10-Feb-2014/21:48:39-8:00
Added that one to Rebol.org :)
Rex — 11-Feb-2014/6:37:21-8:00
Thanks Nick.
Now I know how to define my own copy-types function :)
Rex — 14-Feb-2014/8:14:35-8:00
I find a R3 function which do similar things:
to remove all email address from a block:
remove-each value block [email? value]
Nick — 14-Feb-2014/22:00-8:00
'remove-each is also found in all versions of R2, but it will not remove items from nested blocks. Try the example above:
x: [12 "ads" 343 "sodf" $12.23 [123 4343 "sdadfdf" "idsf" 2-feb-2014 ["asdafdf" "sduf" 25 23]]]
y: copy/deep x
remove-each val y [string? val]
The point of the 'remove-type function above is that it recursively searches through any number and/or level of sub-blocks in a given block, and performs the evaluation and series alteration within all nested blocks, no matter how many levels deep.
Rex — 16-Feb-2014/6:54:37-8:00
Oh I see :) A recursion is needed to handle the nested blocks.