anchor.diff:  %% Programming", Aug 2012
   %% @private
   %%------------------------------------------------------------------------------
  -t0_fn([], E) ->
  -  t0(E);
  -t0_fn([{b_param,_}|_]=Params, E) ->
  +t0_fn([], E, NPs) ->
  +  t0(E, NPs);
  +t0_fn([{b_param,_}|_]=Params, E, NPs) ->
     %% Group consecutive initial base params
  -  {BPs, Ps} = lists:splitwith(fun({Type,_}) -> Type == b_param end, Params),
  -  {b_abs, [], lists:map(fun({b_param, BP}) -> BP end, BPs), t0_fn(Ps, E)};
  -t0_fn([{v_param, Param}|Ps], E) ->
  -  {v_abs, [], [Param], t0_fn(Ps, E)};
  -t0_fn([{n_param, Param}|Ps], E) ->
  -  %%------------------------------------------------------------------------------
  -  %% FIXME -- Here we need to replace Param in E with an intension
  -  %% application.  Proposition 9 in Aug 2012 semantics paper:
  +  {BPs0, Ps} = lists:splitwith(fun({Type,_}) -> Type == b_param end, Params),
  +  {_, BPs1} = lists:unzip(BPs0),
  +  {b_abs, [], BPs1, t0_fn(Ps, E, tset:difference(NPs, BPs1))};
  +t0_fn([{v_param, Param}|Ps], E, NPs) ->
  +  {v_abs, [], [Param], t0_fn(Ps, E, tset:difference(NPs, [Param]))};
  +t0_fn([{n_param, Param}|Ps], E, NamedParams) ->
  +  %%------------------------------------------------------------------------------
  +  %% Replace Param in E with an intension application.  Ref
  +  %% proposition 9 in Aug 2012 semantics paper:
     %%   [ \\ {Ei} x -> E0 ] == [ \ {Ei} x -> E0[x/↓x] ]
  -  %% FIXME -- Do the same in anonymous v_abs
  -  %%------------------------------------------------------------------------------
  -  {v_abs, [], [Param], t0_fn(Ps, E)}.
  +  %% FIXME -- Do the same in anonymous n_abs
  +  %%------------------------------------------------------------------------------
  +  {v_abs, [], [Param], t0_fn(Ps, E, tset:union(NamedParams, [Param]))}.
   
   %%------------------------------------------------------------------------------
   %% @doc Transform function call.
  
positive.code:   {v_apply, t0_fn_call(FnE, Ps), [Param]};
  t0_fn_call(FnE, [{n_param, Param}|Ps]) ->
    %%------------------------------------------------------------------------------
    %% FIXME -- Here we need to replace the n_param with a v_param that
    %% is an intension abstraction of Param.  Proposition 8 in Aug 2012
    %% semantics paper:
    %%   [ E0 E1 ] == [ E0 ! (↑{} E1) ]
    %%------------------------------------------------------------------------------
    t0_fn_call(FnE, Ps).
  
  %%------------------------------------------------------------------------------
  %% @doc Transform a where clause into wherevar / wheredims.
  %% @private
  %%------------------------------------------------------------------------------
  t0_where([], [], E0) ->
    t0(E0);
  t0_where([], Dims, E0) ->
    {wheredim, t0(E0), Dims};
  t0_where(Vars, [], E0) ->
    {wherevar, t0(E0), Vars};
  t0_where(Vars, Dims, E0) ->
    {wheredim, {wherevar, t0(E0), Vars}, Dims}.
  
  %%------------------------------------------------------------------------------
  %% Instant Tests - Please improve these
  
negative.code: %% {i_abs, [FrozenDimName], E}
  %% {i_apply, E}
  %%------------------------------------------------------------------------------
  transform0(E) -> t0(E, []).
  
  %%------------------------------------------------------------------------------
  %% Constants
  %%------------------------------------------------------------------------------
  t0(Const, _) when is_number(Const) orelse is_boolean(Const) ->
    Const;
  
  t0({string, Str}, _) ->
    {string, Str};
  
  t0({char, Char}, _) ->
    {char, Char};
  
  %%------------------------------------------------------------------------------
  %% Primop
  %%------------------------------------------------------------------------------
  t0({primop, F, Eis}, NPs) ->
    {primop, F, lists:map(fun(Ei) -> t0(Ei, NPs) end, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Tuple Expression
  %%------------------------------------------------------------------------------
  t0({t, E0E1is}, NPs) ->
    {t, lists:map(fun({E0,E1}) -> {t0(E0, NPs), t0(E1, NPs)} end, E0E1is)};
  
  %%------------------------------------------------------------------------------
  %% Context Perturbation
  %%------------------------------------------------------------------------------
  t0({'@', E0, E1}, NPs) ->
    {'@', t0(E0, NPs), t0(E1, NPs)};
  
  %%------------------------------------------------------------------------------
  %% Conditional
  %%------------------------------------------------------------------------------
  t0({'if', E0, E1, E2}, NPs) ->
    {'if', t0(E0, NPs), t0(E1, NPs), t0(E2, NPs)};
  
  %%------------------------------------------------------------------------------
  %% Dimensional Query
  %%------------------------------------------------------------------------------
  t0({'#', E0}, NPs) ->
    {'#', t0(E0, NPs)};
  
  %%------------------------------------------------------------------------------
  %% Base Abstraction
  %%------------------------------------------------------------------------------
  t0({b_abs, Is, Params, E}, NPs) ->
    {b_abs, [t0(I, NPs) || I <- Is], Params, t0(E, NPs)};
  
  t0({b_apply, E0, Eis}, NPs) ->
    {b_apply, t0(E0, NPs), lists:map(fun(Ei) -> t0(Ei, NPs) end, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Value Abstraction
  %%------------------------------------------------------------------------------
  t0({v_abs, Is, Params, E}, NPs) ->
    {v_abs, [t0(I, NPs) || I <- Is], Params, t0(E, NPs)};
  
  t0({v_apply, E0, Eis}, NPs) ->
    {v_apply, t0(E0, NPs), lists:map(fun(Ei) -> t0(Ei, NPs) end, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Intension Abstraction
  %%------------------------------------------------------------------------------
  t0({i_abs, Is, E}, NPs) ->
    {i_abs, [t0(I, NPs) || I <- Is], t0(E, NPs)};
  
  t0({i_apply, E}, NPs) ->
    {i_apply, t0(E, NPs)};
  
  %%------------------------------------------------------------------------------
  %% Function
  %%------------------------------------------------------------------------------
  t0({fn, Params, E}, NPs) ->
    t0_fn(Params, E, NPs);
  
  t0({fn_call, FnE, Params}, NPs) ->
    t0_fn_call(
      t0(FnE, NPs),
      lists:reverse(lists:map(fun({Type, P}) -> {Type, t0(P, NPs)} end, Params)));
  
  %%------------------------------------------------------------------------------
  %% Where
  %%------------------------------------------------------------------------------
  t0({where, E0, VDisEis}, NPs0) ->
    Dims = [{Xi, t0(Ei, NPs0)} || {dim,Xi,Ei} <- VDisEis],
    NPs1 = tset:difference(NPs0, element(1, lists:unzip(Dims))),
    Vars0 = [{Xi,Ei} || {var,Xi,Ei} <- VDisEis],
    NPs2 = tset:difference(NPs1, element(1, lists:unzip(Vars0))),
    Vars1 = [{Xi, t0(Ei, NPs2)} || {Xi,Ei} <- Vars0],
    %% We should probably signal an error when the body contains other elements..
    t0_where(Vars1, Dims, E0, NPs2);
  
  %%------------------------------------------------------------------------------
  %% Identifiers
  %%------------------------------------------------------------------------------
  t0(Xi, NamedParams) when is_list(Xi) orelse is_atom(Xi) ->
    case lists:member(Xi, NamedParams) of
      true  -> {i_apply, Xi};
      false ->           Xi
    end.
  
  %%------------------------------------------------------------------------------
  %% @doc Transform function declaration.
  