How to keep (print text) as it disappears when using compose ?
s: {hello test1 parse test2}
t1: "test1"
t2: "test2"
rule: compose [ thru (t1) mark: copy text to (t2) (print text)]
parse s rule
same question for compose/deep if it's different answer:
s: {hello test1 parse test2. hello second test for test1 parse test2.}
t1: "test1"
t2: "test2"
rule: compose/deep [ any [thru (t1) mark: copy text to (t2) (print text)]]
parse s rule
You aren't limited to what's in the box, so you could make your own COMPOSE-like construct that does other patterns.
For instance, here's a composeII which only substitutes for cases where there are nested parentheses. So it will leave (x) alone but evaluate ((x)).
composeII: function [block /only /deep] [
collect [
foreach item block [
case [
all [
paren? :item
1 = length? item
paren? first item
][
either only [
keep/only do first item
][
keep do first item
]
]
all [
deep
block? :item
][
either only [
keep/only composeII/deep/only item
][
keep/only composeII/deep item
]
]
true [
keep/only :item
]
]
]
]
]
So for your case:
>> t1: "test1"
>> t2: "test2"
>> composeII/deep [
any [thru ((t1)) mark: copy text to ((t2)) (print text)]
]
== [
any [thru "test1" mark: copy text to "test2" (print text)]
]
You can either convert block to paren, or quote paren:
>> compose [something here (to paren! [print text])]
== [something here (print text)]
>> compose [something here (quote (print text))]
== [something here (print text)]
It's the same for compose/deep .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With