% $Id: env.mod,v 1.1 1994/04/27 15:23:27 leavens Exp leavens $
%
% Environments as in Watt's book "Programming Languages: Syntax and Semantics"
% (Prentice-Hall, 1991), section 3.3.1.
%
% AUTHOR: Gary T. Leavens

module env.

import lists.

kind	environ		type -> type -> type.

type	empty_environ	(environ Identifier Bindable).
type	bind		Identifier -> Bindable
				-> (environ Identifier Bindable).
type	overlay		(environ Identifier Bindable)
				-> (environ Identifier Bindable)
				-> (environ Identifier Bindable).

type	find		(environ Identifier Binadable)
				-> Identifier -> Bindable -> o.

(find (bind I B) I B) :- !.
(find (overlay Env1 Env2) I B) :- (find Env1 I B), !.
(find (overlay Env1 Env2) I B) :- (find Env2 I B).


type	range		(environ Identifier Bindable)
				-> (list Bindable) -> o.

(range (bind I B) (B::nil)).
(range (overlay Env1 Env2) L) :-
	(range Env1 L1),
	(range Env2 L2),
	(append L1 L2 L).
