function [dir] = popd(directory)

% POPD		pop a directory from the direcory stack
%   POPD removes the top element on the directory stack.
%   DIR = POPD returns the popped directory in DIR.

global directory_stack
if isempty(directory_stack),  error('Directory stack empty.');  end

% pop top of stack, chdir. (lossage = pop)
current = cd;
last = directory_stack{1};
directory_stack = directory_stack(2:length(directory_stack));
cd(last);
if nargout > 0,
  dir = current;
end

disp(cd);
for d = 1:length(directory_stack),
  disp(directory_stack{d});
end
