langlauf.io
langlauf.io

Reputation: 3221

Pyclips: Error when setting a clips class instance multislot to [ ]

I want a multislot of a class instance to become an empty list. I am not sure if there is a bug in clips or pyclips, or if I am doing it wrong.

import clips

C = clips.BuildClass("C", "(is-a USER)(multislot s)")
i = clips.BuildInstance("test1", C)
#i.Slots['s'] = clips.Multifield([])          # error
i.Slots['s'] = []                             # error
#i.Slots['s'] = clips.Multifield(["1", "4"])  # no error
#i.Slots['s'] = ["1", "4"]                    # no error
print i.Slots["s"]

I am getting this error: _clips.ClipsError: C09: unable to understand argument

Stacktrace:

File "\\VBOXSVR\vagrant\return_empty_list_bug.py", line 6, in <module>
  i.Slots['s'] = [] # error
File "c:\Python27\Lib\site-packages\clips\_clips_wrap.py", line 175, in _WRAPPER
  return f(self, *args)
File "c:\Python27\Lib\site-packages\clips\_clips_wrap.py", line 269, in _WRAPPER
  return f(self, *newargs)
File "c:\Python27\Lib\site-packages\clips\_clips_wrap.py", line 2506, in __setitem__
  _c.directPutSlot(self.__instance, name, _py2cl(v))

_clips.ClipsError: C09: unable to understand argument

Upvotes: 0

Views: 259

Answers (2)

langlauf.io
langlauf.io

Reputation: 3221

The problem seems to be in file clipsmodule.c line 1788:

case MULTIFIELD:
    if(!PyList_Check(value))
        goto fail;
    n = PyList_Size(value);
    if(n == 0) goto fail;          // <---- This seems to cause the error.
    if(!(do_value = EnvCreateMultifield(env, n)))
        goto fail;
    for(i2 = 0; i2 < n; i2++) {
        item = PyList_GetItem(value, i2);
        if(!item)
            goto fail;
        if(!i_py2do_mfhelp_e(env, item, do_value, (int)(i2 + 1)))
            goto fail;
    }
    break;  /* n is still good for below */

I don't know why this check is there and what will be the effects if I uncomment it.

Upvotes: 0

noxdafox
noxdafox

Reputation: 15060

The above example works in clipspy.

import clips

environment = clips.Environment()
environment.build('(defclass C (is-a USER) (multislot s))')

c_class = environment.find_class('C')
instance = c_class.new_instance('test1')

instance['s'] = []

print(instance)
print(instance['s'])

Output.

[test1] of C (s)
[]

Upvotes: 1

Related Questions