Skip to content

[CONSTRCT1] error when calling Environment.clear(): #72

@sjvega0

Description

@sjvega0

Encountered the following error while using the (excellent) clipspy library, after asserting facts that activate a rule with a particular set of CEs and attempting to clear the environment with Environment.clear():

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\site-packages\clips\environment.py", line 185, in clear
    raise CLIPSError(self._env)
clips.common.CLIPSError: [CONSTRCT1] Some constructs are still in use. Clear cannot continue.

This occurs while using Python v3.10, clipspy v1.0.5, and CLIPS v6.4.2 . The problem may not lie in clipspy itself, but I was not able to replicate the same error using the CLIPS IDE or CLIPS DOS so this was my first stop. The concern is not as much about the clear() command itself, but that it might be a reflection of a deeper issue (potentially related to memory leaks?).

Below is a sample code that triggers the problem. Notice that the environment does not have to be 'run'; the activation of the rule in the agenda is sufficient to cause the error later.

import clips

DEFTEMPLATE = """
(deftemplate template-fact
    (slot function))
"""

DEFRULE = """
(defrule fact-rule
    (template-fact (function ?func))
    (test (neq (funcall ?func) nil))
  =>
    ; do something
)
"""

DEFFUNCTION = """(deffunction function-X ())"""

# Run CLIPS
env = clips.Environment()

env.clear()

for construct in [DEFTEMPLATE, DEFRULE, DEFFUNCTION]:
    env.build(construct)

env.reset()

env.assert_string('(template-fact (function function-X))')

print("Facts found:")
for fact in env.facts():
    print(f"\t{fact}")

print("Clearing environment...")
env.clear()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions