stable.pl 391 Bytes
% == No, Emacs this is -*-Prolog-*- code, not what you thought... =============

% -- Symbol table -------------------------------------------------------------

st_lookup([K=V|_], K, V).
st_lookup([_|ST], K, V) :- st_lookup(ST, K, V).

st_insert([], K, V, [K=V]) :- !.
st_insert([K=_|_], K, _, _) :- !, throw(duplicate(K)).
st_insert([KV0|ST], K, V, [KV0|STx]) :- st_insert(ST, K, V, STx).