Question

When you use REDUCE you basically operate in the DO dialect, where PAREN! groups can be used for precedence on items:

>> reduce ["Hello" (3 + 4) * 5]
== ["Hello" 35]

While in the COMPOSE dialect, PAREN! is used to call out which parts of the block you want to evaluate with the DO dialect, leaving the rest alone:

>> compose ["Hello" (3 + 4) * 5]
== ["Hello" 7 * 5]

But if you want to run reduce or compose and have a few things you want to leave in as literal parentheses, is there another idiom for it besides to-paren and a block?

>> reduce ["Hello" (3 + 4) * 5 to-paren ["inside!"]]
== ["Hello" 35 ("inside")]

Sidenote: I wonder what sort of craziness would result from LIT-PAREN?

>> reduce ["Hello" (3 + 4) * 5 '("inside!")]
== ["Hello" 35 ("inside")]

...then again, I don't know that I want to think about it. :-)

Was it helpful?

Solution

The more general way to achieve what you want is to rely on quote:

>> reduce ["Hello " (3 + 4) * 5 quote ("inside!")]
== ["Hello " 35 ("inside!")]

QUOTE is available in R3 and in R2 since 2.7.7.

OTHER TIPS

Another idiom, yes:

>> reduce ["Hello" (3 + 4) * 5 first [("inside!")]]
== ["Hello" 35 ("inside")]

Not sure it's any better, but it is a different animal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top