% foldcols :; 
%    ([[M]], [[N]] -> [[M]])   ~'folding function',
%    [[M]]                     ~'initial value',
%    [[N,L]]                   ~'data to scan, sequence of length L'
% -> [[M]].

function y=foldrcols(f,y,X,varargin)
	if nargin>3
		opts=prefs('draw',0,varargin{:});
		for i=size(X,2):-1:1
			y1=f(y,X(:,i));
			if opts.draw
				opts.plotfn(i,y,X(:,i),y1); 
			end
			optpause(opts);
			y=y1;
		end
	else % streamlined version
		for i=size(X,2):-1:1, y=f(y,X(:,i)); end
	end
	

