Pyclips:将Clips类实例多插槽设置为[]时出错

时间:2018-07-09 12:36:20

标签: python clips pyclips clipspy

我希望类实例的多插槽成为空列表。我不确定剪辑或pyclips中是否有错误,或者我做错了。

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"]

我收到此错误: _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

2 个答案:

答案 0 :(得分:1)

上面的示例在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'])

输出。

[test1] of C (s)
[]

答案 1 :(得分:0)

问题似乎出在文件clipsmodule.c第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 */

我不知道为什么要进行此检查,如果我取消注释会产生什么影响。