% vecedit - Graphical editor for real-valued vector
%
% vecedit ::
%    [[N]] ~'initial value of editable vector',
%    options {
%       fig :: handle/gcf ~'figure to use';
%    }
% -> arrow({},{[[N]]},vecedit_state) ~'arrow that generates vectors'.
%
% vecedit takes all options accepted by emousepos and plotter.
function o=vecedit(x0,varargin)
	N=length(x0); x0=x0(:);
	opts=prefs(varargin{:});
	o = emousepos(opts) * erate(loop(@edit,@(z)x0) * obs_with(plotter(opts)),{[2,1]}) * alatch(x0);

	function [f,g]=edit(m,f)
		i=round(m(1));
		if i>=1 && i<=N, f(i)=m(2); end
		g=f;
	end
end
