是否可以在带有变量的插槽中设置允许的整数?

Is it possible to set allowed-integers in a slot with a variable?

我想用多字段变量将我允许的整数限制在一个槽中。

所以代替:

CLIPS> (deftemplate foo (slot constr-integers (allowed-integers 1 3 4 7)))

我想做这样的事情:

CLIPS> (bind ?multifieldvariable (create$ 1 3 4 7))
(1 3 4 7)
CLIPS> (deftemplate bar (slot constr-integers (allowed-integers ?multifieldvariable)))

[PRNTUTIL2] Syntax Error:  Check appropriate syntax for allowed-integers attribute.

ERROR:
(deftemplate MAIN::bar
   (slot constr-integers (allowed-integers ?multifieldvariable 

我知道如何解决这个问题,但也许有一种更优雅的方法。

此致, 塞巴斯蒂安

您只能通过调用构建函数动态创建 deftemplate 来实现:

CLIPS> (bind ?multifieldvariable (create$ 1 3 4 7))
(1 3 4 7)
CLIPS> 
(build (str-cat "(deftemplate bar (slot constr-integers (allowed-integers " 
                 (implode$ ?multifieldvariable)
                ")))"))
TRUE
CLIPS> (ppdeftemplate bar)
(deftemplate MAIN::bar
   (slot constr-integers (allowed-integers 1 3 4 7)))
CLIPS>