And a double howdy back to you too, pilgrim!:
> Well, howdy back, pardner!
[ . . . ]
> ... but look at the way REBOL encourages use of the
> basic REBOL datatype, the block.
>
> Commands such as APPEND, INSERT, REMOVE, CHANGE, CLEAR,
> POKE, REPLACE, REVERSE, SORT, are provided in REBOL.
> Commands that iterate over blocks like FOR, FOREACH,
> FORALL, are also provided.
(also PICK, SELECT, SWITCH, -- FORSKIP )
> However, expressions that map
> from blocks to values or blocks to blocks are not present
> in the language (as an example, consider the following
> hypothetical expressions:
>
> map func [x] [1 + x] [1 2 3] => [2 3 4] filter odd? [1 2
> 3 4 5 6] => [1 3 5] interleave [1 2 3 4 5] [a b c d e] =>
> [1 a 2 b 3 c 4 d 5 e] prepend 'a [b c d] => [a b c d]
Hmm... I think UNION, INTERSECT, and DIFFERENCE meet your
criteria. How's COMPOSE work for you?
> Note that these expressions would return new blocks rather
> than modify existing ones.) These are the sort of
> expressions that one would expect to find in a functional
> language.
>
> Granted, you could probably write these functions in REBOL
> (although with the funky scoping rules, it might be
> trickier than it looks),
Hay-- that's a great idea! Here's my cut at the above:
map: func [f blk][
either empty? blk [blk][append reduce [f first blk] map :f next blk]
]
filter: func [f blk][
any [all [empty? blk blk]
all [f first blk append reduce [first blk] filter :f next blk]
filter :f next blk]
] ;- filter :odd? [1 2 3 4 5 6] => [1 3 5]
interleave: func [blk1 blk2][
any [all [empty? blk1 blk2]
all [empty? blk2 blk1]
append reduce [first blk1 first blk2] interleave
next blk1 next blk2
]
]
prepend: func [item blk][head insert copy blk item]
Hmm.. those didn't feel very tricky to do. Your aim is to
bash REBOL for it's lack of functional purity, no? :-)
value? 'Hair-splitting == true
Can't please 'em all... )-:
-jeff