anchor.diff:          error -> Def
       end.
   
  -%% (defmacro safe_fetch (key d def)
  -%%   `(case (find ,key ,d)
  -%%      ((tuple 'ok val) val)
  -%%      ('error ,def)))
  -
   %% The LFE shell command functions.
   %%  These are callable from outside the shell as well.
   
  
positive.code: server(default) ->
      server(lfe_env:new());
  server(Env) ->
      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.
      St = new_state("lfe", [], Env),
      server_loop(St).
  
  server_loop(St0) ->
      StX = try
                %% Read the form
                Prompt = prompt(),
                io:put_chars(Prompt),
                case lfe_io:read() of
                    {ok,Form} ->
                        Ce1 = add_vbinding('-', Form, St0#state.curr),
                        %% Macro expand and evaluate it.
                        {Value,St1} = eval_form(Form, St0#state{curr=Ce1}),
                        %% Print the result, but only to depth 30.
                        VS = lfe_io:prettyprint1(Value, 30),
                        io:requests([{put_chars,VS},nl]),
                        %% Update bindings.
                        Ce2 = update_shell_vars(Form, Value, St1#state.curr),
                        St1#state{curr=Ce2};
                    {error,E} ->
                        list_errors([E]),
                        St0
                end
            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)
                                     or (M == lfe_macro) or (M == lists);
                             ({M,_F,_A,_L}) ->    %R15 and later
                                 %% Don't want to see these in stacktrace.
                                 (M == lfe_eval) or (M == lfe_shell)
                                     or (M == lfe_macro) or (M == lists)
                         end,
                    Ff = fun (T, I) -> lfe_io:prettyprint1(T, 15, I, 80) end,
                    Cs = lfe_lib:format_exception(Class, Error, Stk, Sf, Ff, 1),
                    io:put_chars(Cs),
                    io:nl(),
                    %% lfe_io:prettyprint({'EXIT',Class,Error,St}), io:nl(),
                    St0
            end,
      server_loop(StX).
  
  %% new_state(ScriptName, Args [,Env]) -> State.
  %%  Generate a new shell state with all the default functions, macros
  %%  and variables.
  
  new_state(Script, Args) -> new_state(Script, Args, lfe_env:new()).
  
  new_state(Script, Args, Env0) ->
      Env1 = add_vbinding('script-name', Script, Env0),
  
negative.code: %% Copyright (c) 2008-2015 Robert Virding
  %%
  %% Licensed under the Apache License, Version 2.0 (the "License");
  %% you may not use this file except in compliance with the License.
  