logs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Logs-devel] fixing (removing) dynamically bound variables


From: Vijay Lakshminarayanan
Subject: Re: [Logs-devel] fixing (removing) dynamically bound variables
Date: Tue, 9 Jan 2007 19:56:14 -0600

On 1/7/07, Jim Prewett <address@hidden> wrote:

> How would we pass the ENVIRONMENT to the actions?

I was thinking of modifying run-actions in rule.lisp in partiucular to
remove the IN-GIVEN-ENVIRONMENT references and instead funcall the action
functions with an additional argument: This is the simplest thing I can
think of to do.

I'm not sure this is exactly possible.  In cases where the action is
specified as a function (as in your example to Aashish), we would have
to do something like

((lambda (message environment)
  (declare (ignorable environment))
  (funcall action message))
message
environment)

which, I think, is inefficienct.  I think we can still use
IN-GIVEN-ENVIRONMENT and i've given an example below.

I also think that such a change would make testing a ruleset simpler as,
instead of having variables bound, they would be passed in in a
predictable way.

It should also make all of that scoping stuff we were talking about
resolve itself very nicely.  Variables bound by in/the Lisp code would be
clearly separated from things bound by the match functions.  Lisp already
does its scoping right and LoGS already maintains the ENVIRONMENT list
correctly; My concern before was in how these "variables" could co-exist
in the sensibly in the same namespace, which, possibly, they cannot in any
sensible way.

:-)

I've done a little playing with this and I think the modifications should
be pretty small.

Here is one way I can think of using IN-GIVEN-ENVIRONMENT but the
bound variables are not available in sub-actions.

(defmacro in-given-environment (env action &rest args)
 (let ((body-result (gensym "BODY-RESULT"))
       (environment (gensym "ENVIRONMENT")))
   `(let ((,environment ,env))          ; <-- not GENSYM'd
     (flet ((getvar (var) (cadr (assoc var ,environment))))
       (let ((,body-result ,action))
         (if (functionp ,body-result)
             (funcall ,body-result ,@args)
             ,body-result))))))

CL-USER> (in-given-environment '((a "one") (b 'ii))
          #'(lambda (arg)
              (list (getvar 'a) (getvar 'b) arg))
          3)
("one" 'II 3)

So A and B of this ENVIRONMENT will not be available below.  But as we
discussed earlier, that is possible only with dynamic variables.

Of course, the above macro won't work in real application code.  It
needs a slight modification.  We cannot write (flet ((GETVAR (var)...)
It would have to be (flet ((,(intern "GETVAR") (var) ...) so that
GETVAR is available in the current package.

Or we could have ORG.PREWETT.LOGS export GETVAR, I think.

What do you think, Jim?

Thanks
Vijay




reply via email to

[Prev in Thread] Current Thread [Next in Thread]