CLIPS: Asserting facts of arbitrary length
An example fact in my system could be (trip 4 1330 650 boston chicago ... los_angeles)
with any number of cities tacked on at the end. I know I can match arbitrary lengths using the multifield wildcard ($?
), but how can I assert a fact with an arbitrary length? What I want to do is match to one of the facts in the form above, and then append another city to the end of it. 开发者_如何学CIs it possible to do this?
Yes it is possible. You can match 0 or more parts of a fact using $?
. To use it in the RHS you can assign it to a variable using $?variable_name
.
To append another city onto the end, you can match your trip fact with (trip ?arg1 ?arg2 ?arg3 $?cities)
and assert a new trip fact with the city on the end: (trip ?arg1 ?arg2 ?arg3 $?cities new_city)
.
精彩评论