function [g,s,l,seq]=table(f,varargin)
	opts=options('nargin',nargin(f),'nargout',nargout(f),'file',[],varargin{:});
	nin=opts.nargin;
	nout=opts.nargout;

	Table=cell(0,nin+nout);

	g=@lookup;
	s=@saver;
	l=@loader;
	seq=@getrows;
 
	function s=getrows, s=slices(Table,1); end
	function saver(file), 
		if nargin<1, file=opts.file; end
		fprintf('saving %d tabled rows of %s to %s\n',size(Table,1),tostring(f),file);
		d.table=Table;
		save(file,'-struct','d'); 
	end
	function loader(file), 
		if nargin<1, file=opts.file; end
		d=load(file);
		Table=d.table;
		fprintf('loading %d tabled rows of %s from %s\n',size(Table,1),tostring(f),file);
	end

	function varargout=lookup(varargin)
		for i=1:size(Table,1)
			if isequal(varargin,Table(i,1:nin)),
				varargout=Table(i,nin+(1:nout));
				return;
			end
		end
		[varargout{1:nout}]=f(varargin{:});
		Table=vertcat(Table,[varargin,varargout]);
	end
end

