(***********************************************************************)
(** ** Scoped stacks                                                    *)
(***********************************************************************)
(** We also care about the free variables that can appear in stacks. (We will use this in the definition of well-scoped configurations below.) *)
Fixpoint fv_stack s :=
match s with
nil => {}
| n_app2 e :: s => fv_exp (nom_to_exp e) \u fv_stack s
end.
(** Stacks that are well-scoped can discard irrelevant bindings from the heap. *)

(* LATER *)
(* TODO: how do we get inductive proofs to automatically rewrite with the IH? *)
(* /LATER *)
Lemma apply_stack_fresh_eq : forall s x e1 h ,
x `notin` fv_stack s ->
apply_stack ((x, e1) :: h) s = apply_stack h s.