title: CLIPS (clear) command fails / throws exception in pyclips
body: <p>I have a pyclips / clips program for which I wrote some unit tests using pytest.
  Each test case involes an initial <code>clips.Clear()</code> followed by the execution of real clips COOL code via <code>clips.Load(rule_file.clp)</code>. Running each test individually works fine.</p>
  
  <p>Yet, when telling pytest to run all tests, some fail with <code>ClipsError: S03: environment could not be cleared</code>. In fact, it depends on the order of the tests in the .py file. There seem to be test cases, that cause the subsequent test case to throw the exception. </p>
  
  <p>Maybe some clips code is still "in use" so that the clearing fails?
  I read <a href="https://www.csie.ntu.edu.tw/~sylee/courses/clips/bpg/node13.1.5.html" rel="nofollow noreferrer">here</a> that <code>(clear)</code></p>
  
  <blockquote>
    <p>Clears CLIPS. Removes all constructs and all associated data structures (such as facts and instances) from the CLIPS environment. A clear may be performed safely at any time, however, certain constructs will not allow themselves to be deleted while they are in use.</p>
  </blockquote>
  
  <p>Could this be the case here? What is causing the <code>(clear)</code> command to fail?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I was able to narrow down the problem. It occurs under the following circumstances:</p>
  
  <p>test_case_A comes right before test_case_B.
  In test_case_A there is a <code>test</code> such as</p>
  
  <pre><code>(test (eq (type ?f_bio_puts) clips_FUNCTION))
  </code></pre>
  
  <p>but <code>f_bio_puts</code> has been set to</p>
  
  <p><code>(slot f_bio_puts (default [nil]))</code></p>
  
  <p>So testing the type of a slot variable, which has been set to <code>[nil]</code> initially, seems to cause the <code>(clear)</code> command to fail. Any ideas?</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I think I know what is causing the problem. It is the <code>test</code> line. I adapted my code to make it run in the clips Dialog Windows. And I got this error when loading via <code>(batch ...)</code> </p>
  
  <pre><code>[INSFUN2] No such instance nil in function type.
  [DRIVE1] This error occurred in the join network
     Problem resided in associated join
         Of pattern #1 in rule part_1
  </code></pre>
  
  <p>I guess it is a bug of pyclips that this is masked.</p>