-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric-env.lisp
30 lines (25 loc) · 944 Bytes
/
generic-env.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
;;;; generic-env.lisp
;;;; full generality of kernel environments
(in-package #:mother)
(defclass generic-env (environment)
((flat :accessor generic-flat :initarg :flat
:type flat-env)
(parents :accessor generic-parents :initarg :parents
:type list)))
(defun bindings->generic-env (bindings parents)
(make-instance 'generic-env
:flat (bindings->flat-env bindings)
:parents parents))
(defmethod flat-lookup ((env generic-env) key)
(flat-lookup (generic-flat env) key))
(defmethod (setf flat-lookup) (val (env generic-env) key)
(setf (flat-lookup (generic-flat env) key) val))
(defmethod lookup ((env generic-env) key)
(flet ((maybe (env)
(multiple-value-bind (val bound?) (lookup env key)
(when bound?
(return-from lookup (values val t))))))
(maybe (generic-flat env))
;; depth-first (why did i think it was breadth-first?)
(mapc #'maybe (generic-parents env))
(values nil nil)))