-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
Description
The below code returns None, and not the name of the instance.
It seems clipspy embedded python functions cannot handle clips variables (starting with an ?).
EDIT: It works for other slots, but not for the name slot.
import clips
def python_print(string_to_print):
print(string_to_print)
def build_instance(clips_class_name, clips_instance_name, slots=None):
instance_string = "(make-instance " + clips_instance_name + " of " + clips_class_name + ")"
env.eval(instance_string)
i = env.find_instance(clips_instance_name)
return i
if __name__ == "__main__":
env = clips.Environment()
class_string = """
(defclass A (is-a USER)
(slot One)
(slot Two))
"""
rule_string = """
(defrule my_rule
(object (is-a A)
(name ?name_of_an_A))
=>
(python_print ?name_of_an_A))
"""
env.build(class_string)
env.define_function(python_print)
env.build(rule_string)
klass = env.find_class("A")
i_1 = build_instance(klass.name, "i1")
i_1["One"] = "one"
env.run()