anchor.diff:  -module(elixir_fn).
  --export([capture/3, expand/3]).
  --import(elixir_errors, [compile_error/3, compile_error/4]).
  +-export([capture/3, expand/3, format_error/1]).
  +-import(elixir_errors, [form_error/4]).
   -include("elixir.hrl").
   
   %% Anonymous functions
  
positive.code:     [_] ->
        {{fn, Meta, EClauses}, E};
      _ ->
        compile_error(Meta, ?key(E, file),
                      "cannot mix clauses with different arities in anonymous functions")
    end.
  
  fn_arity([{'when', _, Args}]) -> length(Args) - 1;
  
negative.code: is_sequential([{'&', _, [Int]} | T], Int) -> is_sequential(T, Int + 1);
  is_sequential([], _Int) -> true;
  is_sequential(_, _Int) -> false.
  
  format_error(clauses_with_different_arities) ->
    "cannot mix clauses with different arities in anonymous functions";
  format_error({block_expr_in_capture, Expr}) ->
    io_lib:format("invalid args for &, block expressions are not allowed, got: ~ts",
                  ['Elixir.Macro':to_string(Expr)]);
  format_error({nested_capture, Arg}) ->
    io_lib:format("nested captures via & are not allowed: ~ts", ['Elixir.Macro':to_string(Arg)]);
  format_error({invalid_arity_for_capture, Arity}) ->
    io_lib:format("invalid arity for &, expected a number between 0 and 255, got: ~b", [Arity]);
  format_error({capture_arg_outside_of_capture, Integer}) ->
    io_lib:format("unhandled &~B outside of a capture", [Integer]);
  format_error({capture_arg_without_predecessor, Pos, Expected}) ->
    io_lib:format("capture &~B cannot be defined without &~B", [Pos, Expected]);
  format_error({unallowed_capture_arg, Integer}) ->
    io_lib:format("capture &~B is not allowed", [Integer]);
  format_error({invalid_args_for_capture, Arg}) ->
    Message =
      "invalid args for &, expected an expression in the format of &Mod.fun/arity, "
      "&local/arity or a capture containing at least one argument as &1, got: ~ts",
    io_lib:format(Message, ['Elixir.Macro':to_string(Arg)]).
  