如何在 CLIPS 中定义另一个 class 中的 class?
How to define a class within another class in CLIPS?
假设,我在 CLIPS 中定义了一个 class Coin 并且我还有一个 class Board
(defclass Coin
(is-a USER)
(role concrete)
(slot Side (type SYMBOL) (allowed-symbols Head Tail))
)
如何正确定义一个 class Board 上面有三个硬币?像这样:
(defclass Board
(is-a USER)
(role concrete)
(slot CoinOne (type Coin))
(slot CoinTwo (type Coin))
(slot CoinThree (type Coin))
)
这是一种可以自动将一个 class 的实例填充到另一个 class 的实例的方法:
CLIPS (6.31 6/12/19)
CLIPS>
(defclass Coin
(is-a USER)
(role concrete)
(slot Side (type SYMBOL) (allowed-symbols Head Tail)))
CLIPS>
(defclass Board
(is-a USER)
(role concrete)
(slot CoinOne
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin)))
(slot CoinTwo
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin)))
(slot CoinThree
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin))))
CLIPS> (make-instance [b1] of Board)
[b1]
CLIPS> (instances)
[initial-object] of INITIAL-OBJECT
[b1] of Board
[gen1] of Coin
[gen2] of Coin
[gen3] of Coin
For a total of 5 instances.
CLIPS> (send [b1] print)
[b1] of Board
(CoinOne [gen1])
(CoinTwo [gen2])
(CoinThree [gen3])
CLIPS> (send [gen1] print)
[gen1] of Coin
(Side Head)
CLIPS>
假设,我在 CLIPS 中定义了一个 class Coin 并且我还有一个 class Board
(defclass Coin
(is-a USER)
(role concrete)
(slot Side (type SYMBOL) (allowed-symbols Head Tail))
)
如何正确定义一个 class Board 上面有三个硬币?像这样:
(defclass Board
(is-a USER)
(role concrete)
(slot CoinOne (type Coin))
(slot CoinTwo (type Coin))
(slot CoinThree (type Coin))
)
这是一种可以自动将一个 class 的实例填充到另一个 class 的实例的方法:
CLIPS (6.31 6/12/19)
CLIPS>
(defclass Coin
(is-a USER)
(role concrete)
(slot Side (type SYMBOL) (allowed-symbols Head Tail)))
CLIPS>
(defclass Board
(is-a USER)
(role concrete)
(slot CoinOne
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin)))
(slot CoinTwo
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin)))
(slot CoinThree
(type INSTANCE)
(allowed-classes Coin)
(default-dynamic (make-instance of Coin))))
CLIPS> (make-instance [b1] of Board)
[b1]
CLIPS> (instances)
[initial-object] of INITIAL-OBJECT
[b1] of Board
[gen1] of Coin
[gen2] of Coin
[gen3] of Coin
For a total of 5 instances.
CLIPS> (send [b1] print)
[b1] of Board
(CoinOne [gen1])
(CoinTwo [gen2])
(CoinThree [gen3])
CLIPS> (send [gen1] print)
[gen1] of Coin
(Side Head)
CLIPS>