What does copy/types do?

Started by rex on 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?
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
Added that one to Rebol.org :)
Thanks Nick. Now I know how to define my own copy-types function :)
I find a R3 function which do similar things: to remove all email address from a block: remove-each value block [email? value]
'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.
Oh I see :) A recursion is needed to handle the nested blocks.

Reply