how to clips.Assert(variable) ?

Help
Pyc Liph
2008-07-31
2013-04-25
  • Pyc Liph
    Pyc Liph
    2008-07-31

    The pattern using a String constant such as in clips.Assert("(animal)") works.
    However to use a variable like here:

    1        assertarg = '"('+ results.argument +')"'
    2        assertarg = '"(mouse)"'
    3        clips.Assert(str(assertarg))
    4        clips.Assert(assertarg)

    does not work. Different combinations 1+3, 1+4, 2+3, 2+4 produce this error:

    File "build/bdist.linux-i686/egg/clips/_clips_wrap.py", line 3152, in Assert
        return Fact(_c.assertString(str(o)))
    ClipsError: C12: could not assert

    Does anyone know how to assign a value to a variable var such that clips.Assert(var) worked?
    Thanks,
    Pyc.

     
    • Hi Pyc,

      the problem here is in what you try to assert: there are too many quotes. Look at this:

      >>> assertarg = '"(mouse)"' # the actual string contains double quotes!
      >>> print assertarg
      "(mouse)"
      >>> clips.Assert(assertarg)

      Traceback (most recent call last):
        File "<pyshell#7>", line 1, in <module>
          clips.Assert(assertarg)
        File "build\bdist.win32\egg\clips\_clips_wrap.py", line 3152, in Assert
          return Fact(_c.assertString(str(o)))
      ClipsError: C12: could not assert
      >>> print clips.ErrorStream.Read()

      [PRNTUTIL2] Syntax Error:  Check appropriate syntax for RHS patterns.

      >>> assertarg = '(mouse)'
      >>> import clips
      >>> clips.Assert(assertarg)
      <Fact 'f-0': fact object at 0x026372C0>
      >>> clips.PrintFacts()
      f-0     (mouse)
      For a total of 1 fact.
      >>>

      Same for the other one: let's say result.argument is "testing42", then we have

      >>> assertarg = '"('+ result.argument +')"'
      >>> print assertarg
      "(testing42)"
      >>>

      There are still quotes at the start and at the end of the string you try to assert, and CLIPS doesn't accept it. Instead, removing the excess quotes,

      >>> result.argument = "testing42"
      >>> assertarg = '('+ result.argument +')'
      >>> clips.Assert(assertarg)
      <Fact 'f-0': fact object at 0x02641BA0>
      >>> clips.PrintFacts()
      f-0     (testing42)
      For a total of 1 fact.
      >>>

      it works as expected!

      Cheers,

      F.