Proposed Change to the LoGS API
Filed Under:
Changes proposed in the LoGS API for version 0.2.0.
LoGS has, for quite some time, used dynamically bound variables to maintain information that needs to be passed between a match function and an action function.
Here is an example of how that worked (previous to 0.2.0):
(make-instanceAccording to The CL-Cookbook , each thread in a Lisp program will have its own bindings for dynamic variables. This may be a problem if LoGS wants to become multi-threaded (something I view as being highly probable). We probably won't be able to to do what we want under a multi-threaded model using dyamic variable bindings like this. Also, it seems to me that when referring to a variable, you likely want the most recent one from the stack of variable bindings in the LoGS "environment" (those variable bindings produced by match functions, etc. This means that either we must wait to evaluate all variables until the very last possible instant at run-time. Therefore, compilation buys us very little (I think). To remedy these problems, I'm proposing a separation between Lisp variables and those in the LoGS environment. Each of the match, delete, and action functions should now accept the parameter ENVIRONMENT. This parameter will contain a list of lists representing the stack of variable bindings. Each sub-list will have a CAR of the variable name and a CADR of the binding of that variable. I further propose adding an accessor function, GET-LoGS-ENV-VAR which will take the name of a variable and will return its value and a value indicating if the key was found (simular to CL's GETHASH). The previous rule would then be written as:
'rule
:match
(lambda (message)
(multiple-value-bind (matches sub-matches)
(cl-ppcre::scan-to-strings
"nfs server (\\S+) not responding"
(message message))
(when matches
(values
t
`((NFS-SERVER ,(aref sub-matches 0)))))))
:actions
(list
(lambda (message)
(declare (special NFS-SERVER) (ignore message))
;; NFS-SERVER is a dynamically bound variable
(format t "NFS problem on server: ~A~%" NFS-SERVER))))
(make-instance
'rule
:match
(lambda (message environment)
(declare (ignore environment))
(multiple-value-bind (matches sub-matches)
(cl-ppcre::scan-to-strings
"nfs server (\\S+) not responding"
(message message))
(when matches
(values
t
`((NFS-SERVER ,(aref sub-matches 0)))))))
:actions
(list
(lambda (message environment)
(declare (ignore message))
;; NFS-SERVER is no longer a dynamically bound variable
(format t "NFS problem on server: ~A~%"
(GET-LoGS-ENV-VAR 'NFS-SERVER))))
test