Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sjvega0 opened this issue May 17, 2025 · 0 comments
Open

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

sjvega0 opened this issue May 17, 2025 · 0 comments

Comments

@sjvega0
Copy link

sjvega0 commented May 17, 2025

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant