Menu ▾ ▴

#45 Feature request: deftemplate inheritance

1.0
new
nobody
None
2017-11-15
2017-11-15
noxdafox
No

As discussed here, I'd like to have deftemplate inheritance to minimize the amount of duplicated code.

The core reason is classes are noticeably slower than facts and the only reason for me to use them is to reduce the amount of code duplication when dealing with deftemplates.

(deftemplate event
    (slot timestamp (type FLOAT) (default-dynamic (time))))

(deftemplate windows-event (is-a event)
    (slot computer-id (type STRING))
    (slot thread-id (type STRING))
    (slot process-id (type STRING)))

(deftemplate create-file (is-a windows-event)
    (slot basename (type STRING))
    (slot dirname (type STRING))
    (multislot permissions))

I have not tested yet if rules can fire on parent classes but I'd expect such behaviour with facts.

(defrule forget-event
   ; retract the event if older than 10 minutes
   ?event <- (event (timestamp ?timestamp))
   (test (> (- (time) ?timestamp) 600))
   =>
   (retract ?event))

Discussion


Log in to post a comment.