REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
The compose function is handy for creating blocks from dynamic values. It can be used for creating both data and code.
The compose function takes a block as an argument and returns a block that has each value in the argument block. Values in parentheses are evaluated before the block is returned. For example:
probe compose [1 2 (3 + 4)]
[1 2 7]
probe compose ["The time is" (now/time)]
["The time is" 10:32:45]
If the values in parentheses return a block, that block's individual values are used:
probe compose [a b ([c d])]
[a b c d]
To prevent this, you need to enclose the result in an extra block:
probe compose [a b ([[c d]])]
[a b [c d]]
An empty block inserts nothing:
probe compose [a b ([]) c d]
[a b c d]
When compose is given a block that contains sub-blocks, the sub-blocks are not evaluated, even if they contain parentheses:
probe compose [a b [c (d e)]]
[a b [c (d e)]]
If you would like the sub-blocks to be evaluated, use the /deep refinement. The /deep refinement causes all parentheses to be evaluated, regardless of where they are:
probe compose/deep [a b [c (d e)]]
[a b [c d e]]
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |