Skip to content

Embedded python function not getting argument (if it is the "name" of an instance) #9

@gitttt

Description

@gitttt

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions