-2

I need help to write two rules, that add and remove values from queue. Rule that removes value from queue must use forall structure.

As far as I know, CLIPS does not have arrays, stack, lists or any other type of collections. So I have started with defining template queue with a slot item, that should represent value of a queue, but have not succeeded with the rules. Does anyone have any idea how this can be done?

  • Please provide some code to increase changes to understand you question better and provide an answer. – Heikki Dec 03 '17 at 20:23

1 Answers1

0

CLIPS has multifield objects which act as lists.

You can define your queue as a global variable and modify it in your rules as for this example (LIFO queue).

CLIPS> (defglobal ?*queue* = (create$))
; add "foo" to the queue
CLIPS> (bind ?*queue* (insert$ ?*queue* 1 "foo"))
("foo")
; add "bar" to the queue
CLIPS> (bind ?*queue* (insert$ ?*queue* 1 "bar"))
("bar" "foo")
; remove first element from the queue
(bind ?*queue* (delete$ ?*queue* 1 1))
("foo")
noxdafox
  • 14,439
  • 4
  • 33
  • 45