Hi, again, Carl,

OBTW...

I gave the link to the end of the thread.  If you'd like to see how
we got there, you can start with

    http://www.escribe.com/internet/rebol/m2952.html

It's a great example of how the REBOL user community can jump in
and help refine something into a much better state than it began!

To atone for my omission, let me pitch in another higher-order
function that can be quite handy.  (This name is taken from the
corresponding idea in Smalltalk, but the concept has been all over
the place in the comp sci world...)  The simplest version is:

    inject: func [
        fun [any-function!] val [any-type!] blk [block!]
    ][
        foreach itm blk [val: fun val itm]
        val
    ]

which "chains" the values in the block onto a starting value via
the supplied function.  For example:

    >> balance: 123.45                 == 123.45
    >> credits: [15.24 37.46 93.84]    == [15.24 37.46 93.84]
    >> debits:  [35.44 13.22 1.95]     == [35.44 13.22 1.95]

after which

    >> inject :subtract inject :add balance credits debits    == 219.38
    >> inject :add balance credits                            == 269.99
    >> inject :subtract balance debits                        == 72.84

and finally, the ambitious

    >> inject :subtract inject :add balance credits debits    == 219.38

Of course, INJECT and MAP can be combined in fun ways...

    >> bbllkk: [
    [    [1 3 5 7 9]
    [    [0 2 4 6 8]
    [    [0 1 4 9]
    [    [0 1 8]
    [    ]
    == [
        [1 3 5 7 9]
        [0 2 4 6 8]
        [0 1 4 9]
        [0 1 8]
    ]
    >> map :length? bbllkk
    == [5 5 4 3]
    >> inject :+ 0 map :length? bbllkk
    == 17

with many more variations possible.

Have fun!

-jn-


Joel Neely wrote:
> 
> Hi, Carl,
> 
> PMJI...
> 
> Carl Read wrote:
> >
> > map ?  Is that a REBOL/Command word?  View says it knows nothing
> > about it.
> >
> 
> We had a long discussion about MAP and other higher-order functions
> almost exactly a year ago.  One other demonstration of MAP that I
> had fun with (pardon the pun! ;-) is given in
> 
>     http://www.escribe.com/internet/rebol/m2959.html
> 
> I highly recommend Ladislav's "highfun.r" page, at
> 
>     http://www.sweb.cz/LMecir/highfun.r
> 
> which contains a generous collection of related REBOL code.
> 
> -jn-
> 
> --
> ; Joel Neely  [EMAIL PROTECTED]  901-263-4460  38017/HKA/9677
> REBOL []  foreach [order string]  sort/skip reduce [ true "!"
> false  head reverse "rekcah"  none "REBOL "  prin "Just " "another "
> ] 2 [prin string] print ""
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.

-- 
; Joel Neely  [EMAIL PROTECTED]  901-263-4460  38017/HKA/9677
REBOL []  foreach [order string]  sort/skip reduce [ true "!"
false  head reverse "rekcah"  none "REBOL "  prin "Just " "another "
] 2 [prin string] print ""
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to