anchor.diff:  %% Author  : Robert Virding
   %% Purpose : A simple Lisp Flavoured Erlang shell.
   
  +%% We keep two environments, the BaseEnv which contains the predefined
  +%% shell variables and shell macros, and a current environment. The
  +%% BaseEnv is used when we need to revert to an "empty" environment.
  +%% When we slurp in a file the functions are stored in the BaseEnv and
  +%% the current environment is thrown away.
  +
   -module(lfe_shell).
   
   -export([start/0,start/1,server/0,server/1]).
  
positive.code: 	false -> "> "
      end.
  
  %% eval_form(Form, EvalEnv, BaseEnv) -> {Value,Env}.
  
  eval_form(Form, Env, Benv) ->
      eval_exp_form(lfe_macro:expand_expr_all(Form, Env), Env, Benv).
  
  eval_exp_form([set,Pat,Expr], Env0, Benv) ->
      %% Special case to lint pattern.
      case lfe_lint:pattern(Pat, Env0) of
  	{ok,Ws} -> list_warnings(Ws);
  	{error,Es,Ws} ->
  	    list_errors(Es),
  	    list_warnings(Ws)
      end,
      {yes,Value,Env1} = set([Pat,Expr], Env0, Benv),
      {Value,Env1};
  eval_exp_form(Eform, Env0, Benv) ->
      case eval_internal(Eform, Env0, Benv) of
  	{yes,Value,Env1} -> {Value,Env1};
  	no ->
  	    %% Normal evaluation of form.
  	    {lfe_eval:expr(Eform, Env0),Env0}
      end.
  
  list_errors(Es) ->
  
negative.code: server(_) ->
      io:fwrite("LFE Shell V~s (abort with ^G)\n",
  	      [erlang:system_info(version)]),
      %% Create a default base env of predefined shell variables with
      %% default nil bindings and basic shell macros.
      Base0 = add_shell_macros(lfe_env:new()),
      Base1 = add_shell_vars(Base0),
      St = #state{env=Base1,base=Base1},
      server_loop(St).
  
  server_loop(St0) ->
      StX = try
  	      %% Read the form
  	      Prompt = prompt(),
  	      io:put_chars(Prompt),
  	      Form = lfe_io:read(),
  	      Ee1 = update_vbinding('-', Form, St0#state.env),
  	      %% Macro expand and evaluate it.
  	      {Value,St1} = eval_form(Form, St0#state{env=Ee1}),
  	      %% Print the result, but only to depth 30.
  	      VS = lfe_io:prettyprint1(Value, 30),
  	      io:requests([{put_chars,VS},nl]),
  	      %% Update bindings.
  	      Ee2 = update_shell_vars(Form, Value, St1#state.env),
  	      %% lfe_io:prettyprint({Env1,Env2}), io:nl(),
  	      St1#state{env=Ee2}
  	  catch
  	      %% Very naive error handling, just catch, report and
  	      %% ignore whole caboodle.
  	      Class:Error ->
  		  %% Use LFE's simplified version of erlang shell's error
  		  %% reporting but which LFE prettyprints data.
  		  Stk = erlang:get_stacktrace(),
  		  Sf = fun ({M,_F,_A}) ->	%Pre R15
  			       %% Don't want to see these in stacktrace.
  			       (M == lfe_eval) or (M == lfe_shell)
  