samer@44: function X=cfold(fn,x) samer@44: % fold - Fold combinator for cells samer@44: % samer@44: % fold :: (X,X->X), cells(A) -> X. samer@44: % samer@44: % This function applies an associative operator to a list of arguments, samer@44: % as if the list was written out with the operator between consecutive samer@44: % elements, eg fold(@plus,{1,2,3,4}) = 1+2+3+4. samer@44: samer@44: if isempty(x), X={}; else X=cfoldl(fn,head(x),next(x)); end