% horzcat - function combinator, 
%
% horzcat ::
%    (A{1:N} => B{1}{:}),
%    (A{1:N} => B{2}{:}),
%    ...
% -> (A{1:N} => B{1}{:}, B{2}{:}, ...).
%
% [f,g,h,...] is the function which calls f,g,h etc in order
% with given arguments and returns all their values as multiple
% return values.
% eg, [a,b,c]=feval([@zeros,@ones,@eye],2)
% Returns a=[0,0;0,0], b=[1,1;1,1], c=[1,0;0,1].

function h=horzcat(varargin)
	funs=varargin;
	nouts=cell2mat(map(@nargout,varargin));
	NN=sum(nouts); N=length(funs);
	fns = { @q1n; @qnn };
	h=fns{acount(nargin(funs{1}),1)};

	function varargout=q1n(x), 
		varargout=cell(1,NN);
		j=0; for i=1:N
			k=j+nouts(i);
			[varargout{j+1:k}]=funs{i}(x); 
			j=k;
		end
	end
	function varargout=qnn(varargin), 
		varargout=cell(1,NN);
		j=0; for i=1:N
			k=j+nouts(i);
			[varargout{j+1:k}]=funs{i}(varargin{:}); 
			j=k;
		end
	end
end
