From a492f6e21f55974a21f2f8ec5ccf105fb3f1a832 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Wed, 24 Apr 2013 19:33:39 +0100 Subject: [PATCH] Define lexenv with def!struct --- ecmalisp.lisp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ecmalisp.lisp b/ecmalisp.lisp index bcf192a..9fd5cba 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1364,31 +1364,32 @@ value declarations) -(defun make-lexenv () - (list nil nil nil nil)) +(def!struct lexenv + variable + function + block + gotag) -(defun copy-lexenv (lexenv) - (copy-list lexenv)) +(defun lookup-in-lexenv (name lexenv namespace) + (find name (ecase namespace + (variable (lexenv-variable lexenv)) + (function (lexenv-function lexenv)) + (block (lexenv-block lexenv)) + (gotag (lexenv-gotag lexenv))) + :key #'binding-name)) (defun push-to-lexenv (binding lexenv namespace) (ecase namespace - (variable (rplaca lexenv (cons binding (car lexenv)))) - (function (rplaca (cdr lexenv) (cons binding (cadr lexenv)))) - (block (rplaca (cddr lexenv) (cons binding (caddr lexenv)))) - (gotag (rplaca (cdddr lexenv) (cons binding (cadddr lexenv)))))) + (variable (push binding (lexenv-variable lexenv))) + (function (push binding (lexenv-function lexenv))) + (block (push binding (lexenv-block lexenv))) + (gotag (push binding (lexenv-gotag lexenv))))) (defun extend-lexenv (bindings lexenv namespace) (let ((env (copy-lexenv lexenv))) (dolist (binding (reverse bindings) env) (push-to-lexenv binding env namespace)))) -(defun lookup-in-lexenv (name lexenv namespace) - (find name (ecase namespace - (variable (first lexenv)) - (function (second lexenv)) - (block (third lexenv)) - (gotag (fourth lexenv))) - :key #'binding-name)) (defvar *environment* (make-lexenv)) -- 1.7.10.4