[Main page] [Overview]     /sefun /fold_right

SYNOPSIS
mixed fold_right( closure c, mixed args, mixed begin)

FILE
/kernel/simul_efun/array.h

DESCRIPTION
fold_right works like fold_left, with the difference, that the evaluation
is begun with the begin-element passed as second argument, and the
most right (last) element of the list as first argument to the function,
which the list shall be folded over, passing the result again as second
argument and the element before the last used one of the list, as first.

this could for instance be useful for a multiplikation of a list
of matrices with a vector (begin)
other example:
string kons(int letter, string str) {
return to_string( ({ letter }) + to_array ( str ) );
}

then the call fold_right ( #'kons, "Hello, ", "world!" );
would return the same as
kons('H', kons('e', kons('l', kons('l', kons('o', kons(',',
kons(,' ',"world!"))))))), which again would be a sophisticated way of
doing "Hello, "+"world!" (in lpc) P-)