Looping with Rules
- Make one rule that loops from 1 to 5
- When I did this, I used an LHS like:
(value ?a) (test (< ?a 5))
- Here test says call the fucntion (in this case <); note
that the variable ?a is bound across LHS and RHS.
- What my system does is if there is assert (value 1), it
will add in 4 assertion (value 2)...(value 5)
- Here the same rule is being applied multiple times because
there are new (value ?a) assertions being added.
- Finally, if you haven't managed it yet, you can use a
functions like + in the RHS, or even from the shell.
From the clips prompt try (+ 3 5), or (* 3 5 7).
- Now try a loop from 10 to 20.
- You can also get ahold of facts and manipulate them.
- For example:
?f1 <- (value 4)
(printout t (fact-index ?f1) crlf))
- <- binds the fact itself to a variable. It is the address of
operator for those of you in the know.
- If you retract ?f1 the fact goes away.
- Make a new loop that loops from 1 to 10, but only
leaves one fact (use retract).
- You can also make functions with rules.
- Make a function that loops from 1 to a variable that the
- I've done this by having a special variable infunction, and
three rules, one for init, one for the body and one for
- They all check that the variable has the value working, and
the last changes the value to done.
- If you've got this far and did it on your own well done. If
you didn't do it on your own, make sure you can do it on your
own. It's also wise to save your work.