Calling a function disrupts the rules - clips

I'm trying to change the design of an expert system to work carried out by my rules.
Topic - processing of different parts on different machines. Naturally, each kind of items processed at different times on different machines.
The system consists of three rules. The first rule - load machines work. The second rule - unloads machines. The third rule - performs the movement of time.
I added in the first rule of a function call, which seeks item with maximum processing time. However, the expert system stopped working. Simply displays "1". That's all.
(defglobal ?*time* = 0)
(deftemplate details
(field det (type SYMBOL))
(field oper (type INTEGER))
(field count (type INTEGER))
)
(deftemplate route
(field det (type SYMBOL))
(field oper (type INTEGER))
(field machine (type INTEGER))
(field time (type INTEGER))
)
(deftemplate machine
(field num (type INTEGER))
(field count (type INTEGER)(default 0))
(field det (type SYMBOL)(default A))
(field oper (type INTEGER)(default 0))
(field time (type INTEGER)(default 0))
)
(deffacts details
(details (det A) (oper 0) (count 100))
(details (det B) (oper 0) (count 150))
(details (det C) (oper 0) (count 200))
(details (det D) (oper 0) (count 300))
(details (det E) (oper 0) (count 200))
(details (det A) (oper 1) (count 0))
(details (det B) (oper 1) (count 0))
(details (det C) (oper 1) (count 0))
(details (det D) (oper 1) (count 0))
(details (det E) (oper 1) (count 0))
....
)
(deffacts route
(route (det A) (oper 1) (machine 1) (time 10))
(route (det A) (oper 2) (machine 2) (time 5))
(route (det A) (oper 2) (machine 2) (time 2))
(route (det A) (oper 3) (machine 3) (time 4))
(route (det A) (oper 3) (machine 4) (time 3))
(route (det A) (oper 4) (machine 4) (time 8))
(route (det A) (oper 4) (machine 1) (time 8))
(route (det B) (oper 1) (machine 1) (time 8))
(route (det B) (oper 2) (machine 5) (time 4))
(route (det B) (oper 2) (machine 2) (time 6))
(route (det B) (oper 3) (machine 6) (time 3))
(route (det B) (oper 3) (machine 5) (time 2))
(route (det B) (oper 4) (machine 7) (time 2))
(route (det B) (oper 4) (machine 2) (time 3))
...
)
(deffacts machines
(machine (num 1))
(machine (num 2))
(machine (num 3))
(machine (num 4))
(machine (num 5))
(machine (num 6))
(machine (num 7))
(machine (num 8))
)
(deffunction my-predicate (?fact1 ?fact2)
(< (fact-slot-value ?fact1 time) (fact-slot-value ?fact2 time)))
(deffunction find-max2 (?template1 ?predicate1 ?operation ?template2 ?max)
(bind ?max FALSE)
(do-for-all-facts ((?f2 ?template2)) (eq (fact-slot-value ?f2 count) 0)
(do-for-all-facts ((?f1 ?template1)) (eq (fact-slot-value ?f1 oper) ?operation) (eq (fact-slot-value ?f1 oper)(fact-slot-value ?f2 oper))
(if (or (not ?max) (funcall ?predicate1 ?f1 ?max))
then
(bind ?max ?f1)))
)
)
;--------------------------------------------------------------------------------------------------
(defrule work_on_1
(declare (salience 10000))
(machine (num ?num1)(count ?count1) (time ?time1))
(test (eq ?count1 0))
(test (eq ?time1 0))
?node1 <- (machine (num ?num1)(count ?count1) (time ?time1))
(details (det ?detail) (oper ?operation1) (count ?count2))
(test (not (eq ?count2 0)))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2))
; add this code
(funcall find-max2 route my-predicate ?operation1 details ?max)
(test (eq ?operation1(fact-slot-value ?max oper )))
(route (machine ?num1) (det ?detail) (oper ?operation2) (time ?time2))
(test (eq ?operation2 (+ ?operation1 1)))
=>
(if (> ?count2 30)
then
(modify ?node1 (count 30) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 30)))
(printout t ?*time*" ," ?num1 " 30 деталей типа "?detail " , " ?operation2 " , " ?time2 crlf)
else
(modify ?node1 (count ?count2) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 ?count2)))
(printout t ?*time*" , " ?num1 " " ?count2 " , "?detail " , " ?operation2 " , " ?time2 crlf)
)
)

There are numerous issues with the code. First it's unclear why there’s redundant pattern matching for the machine and details facts:
(machine (num ?num1)(count ?count1) (time ?time1))
(test (eq ?count1 0))
(test (eq ?time1 0))
?node1 <- (machine (num ?num1)(count ?count1) (time ?time1))
(details (det ?detail) (oper ?operation1) (count ?count2))
(test (not (eq ?count2 0)))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2))
The following code is sufficient to achieve the same task:
?node1 <- (machine (num ?num1) (count ?count1&0) (time ?time1&0))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2&~0))
Second, it looks like you're expecting the funcall pattern to invoke a function call and place the result of that function call in the variable ?max:
(funcall find-max2 route my-predicate ?operation1 details ?max)
There is no funcall conditional element that has this type of behavior. In this case, you've just created a pattern conditional element that's looking for an ordered fact with the relation name funcall. If you wanted to invoke funcall from the conditions of a rule you'd use the test conditional element:
(test (funcall find-max2 route my-predicate ?operation1 details))
Since the function being invoked is a literal, find-max2, there's really no point in using funcall since you can just call the function directly:
(test (find-max2 route my-predicate ?operation1 details))
Third, there's not much point to using the query functions within the conditions of a rule since you can directly pattern match on the facts instead. In addition, the placement of the query function you've used within the conditions will cause it to be executed once there are matching machine/details facts, but possibly before there are any route facts, so it will likely not even return the correct results.
The following rule shows how to find the maximum values without using query functions:
(defrule find-max
(route (oper ?oper1) (time ?time1))
(exists (details (count 0) (oper ?oper1)))
(not (and (route (oper ?oper2) (time ?time2&:(> ?time2 ?time1)))
(exists (details (count 0) (oper ?oper2)))))
=>
(printout t "Maximum time is " ?time1 crlf))

(defrule work_on_1
(declare (salience 10000))
?node1 <- (machinegun (num ?num1) (count ?count1&0) (time ?time1&0))
?node2 <- (store (det ?detail) (oper ?operation1) (count ?count2&~0))
(tex_route (oper ?oper1) (time ?time2))
(exists (store (count 0) (oper ?oper1)))
(not (and (tex_route (oper ?oper2) (time ?time3&:(> ?time3 ?time2)))
(exists (store (count 0) (oper ?oper2)))))
(test (eq ?time1 ?time2))
(route (machine ?num1) (det ?detail) (oper ?operation2) (time ?time2))
(test (eq ?operation2 (+ ?operation1 1)))
=>
(if (> ?count2 30)
then
(modify ?node1 (count 30) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 30)))
(printout t ?*time*" ," ?num1 " 30 деталей типа "?detail " , " ?operation2 " , " ?time2 crlf)
else
(modify ?node1 (count ?count2) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 ?count2)))
(printout t ?*time*" , " ?num1 " " ?count2 " , "?detail " , " ?operation2 " , " ?time2 crlf)
)
)
It is new rule, but when the expert system stopped working - simply displays "1".

Related

Clips not providing answer

So I get the program to say enter name. However, once I enter the name it doesn't output any other information. I'm trying to get it to print out the name, class, magnitude, and distance. Where am I going wrong?
(deftemplate stars
(slot name)
(slot class)
(slot magnitude)
(slot dist)
)
(deffacts star
(stars (name Sirius) (class A) (magnitude 1) (dist 8.8))
(stars (name Canopus) (class F) (magnitude -3) (dist 98))
(stars (name Arcturus) (class K) (magnitude 0) (dist 36))
(stars (name Vega) (class A) (magnitude 1) (dist 26))
(stars (name Capella) (class G) (magnitude -1) (dist 46))
(stars (name Rigel) (class B) (magnitude -7) (dist 880))
(stars (name Procyon) (class F) (magnitude 3) (dist 11))
(stars (name Betelgeuse) (class M) (magnitude -5) (dist 490))
(stars (name Altair) (class A) (magnitude 2) (dist 16))
(stars (name Aldebaran) (class K) (magnitude -1) (dist 68))
(stars (name Spica) (class B) (magnitude -3) (dist 300))
(stars (name Antares) (class M) (magnitude -4) (dist 250))
(stars (name Pollux) (class K) (magnitude 1) (dist 35))
(stars (name Deneb) (class A) (magnitude -7) (dist 1630))
)
(defrule start-up
?i <- (initial-fact)
=>
(printout t "Enter name: ")
(bind ?y (read))
(assert (name ?y))
(retract ?i)
)
(defrule S1
?char <- (stars (name ?n) (class ?c) (magnitude ?m) (dist ?d))
(name ?y)
(test ( eq ?n ?y))
=>
(printout t ?n " " ?c" " ?m " " ?d crlf)
(retract ?char)
(assert (found))
)
I got the initial output of enter name but didn't get the second output of name, class, magnitude, and distance.

max element in Z3 Seq Int

I'm trying to write a max function that operates on Seq Int.
It should return the index with maximal value. Here is what I have:
(declare-fun max ((Seq Int)) Int)
(assert (forall ((A (Seq Int)))
(=>
(> (seq.len A) 0)
(and
(<= 0 (max A))
(< (max A) (seq.len A))
(forall ((i Int))
(=>
(and
(<= 0 i)
(< i (seq.len A)))
(<= (seq.nth A i) (seq.nth A (max A))))))))
)
(assert (= (max (seq.++ (seq.unit 8) (seq.unit 3))) 0))
;(assert (= (max (seq.++ (seq.unit 8) (seq.unit 3))) 1))
(check-sat)
When I run it like this, Z3 gets stuck. If I use the commented line instead, Z3 immediately answers unsat (like it should). Am I missing something here? Is there a way to define max properly?
This sort of quantified problems are just not a good match for z3. (Or any other SMT solver.) To prove properties of such recursive predicates, you need induction. Traditional SMT solvers have no induction capabilities.
Having said that, you can help z3 by making your quantified assertions separated out, like this:
(declare-fun max ((Seq Int)) Int)
(assert (forall ((A (Seq Int))) (=> (> (seq.len A) 0) (<= 0 (max A)))))
(assert (forall ((A (Seq Int))) (=> (> (seq.len A) 0) (< (max A) (seq.len A)))))
(assert (forall ((A (Seq Int)) (i Int)) (=> (and (> (seq.len A) 0) (<= 0 i) (< i (seq.len A)))
(<= (seq.nth A i) (seq.nth A (max A))))))
(assert (= (max (seq.++ (seq.unit 8) (seq.unit 3))) 0))
;(assert (= (max (seq.++ (seq.unit 8) (seq.unit 3))) 1))
(check-sat)
If you run this, it succesfully says:
sat
While this is correct, don't be fooled into thinking you've completely specified how max should work or z3 can handle all such problems. To wit, let's add (get-model) and see what it says:
sat
(model
(define-fun max ((x!0 (Seq Int))) Int
(ite (= x!0 (seq.++ (seq.unit 7718) (seq.++ (seq.unit 15) (seq.unit 7719))))
2
0))
)
Oh look, it simply found an interpretation of max that doesn't even satisfy the quantified axioms you've given. Looks like this is a z3 bug and should probably be reported. But the moral of the story is the same: Sequence logic and quantifiers are a soft spot, and I wouldn't count on the solver response even if you got a sat answer.
Long story short Recursion requires induction, and if that's what your specification requires, use a tool that understands induction. Isabelle, HOL, Coq, Agda, Lean; to name a few. There are many choices. And most of those tools automatically call z3 (or other SMT solvers) under the hood to establish properties as necessary (or as guided by the user) anyhow; so you have the best of both worlds.

How to fill a multifield slot from single slots?

The problem is to fill a multifield slot from single slots. To specify the idea, there a set of facts of the same template where some single slots are allready filled, and another template where a multifield slots are not yet filled. It is need to fill the latter with values of single slots values from single slots facts belonging to another template.
For Instance, here the templates declared:
(deftemplate Connexion
(slot ID-BUS)
(multislot CB-CLOSED (default nil))
(multislot CB-OPEN (default nil)))
(deftemplate CB
(slot ID-BUS)
(slot NUM-CB)
(slot STATE-CB (allowed-integers -1 0 1)(default -1)))
(deftemplate State-Vector
(multislot CB-CLOSED (default nil))
(multislot CB-OPEN (default nil)))
Suppose a following facts:
(deffacts Some-Facts
(State-Vector (CB-CLOSED 1 4 5 6 7)(CB-OPEN 2 3 8 9))
(CB (ID-BUS B1)(NUM-CB 1)(STATE-CB 1))
(CB (ID-BUS B1)(NUM-CB 4)(STATE-CB 1))
(CB (ID-BUS B1)(NUM-CB 6)(STATE-CB 1))
(CB (ID-BUS B2)(NUM-CB 2)(STATE-CB 0))
(CB (ID-BUS B2)(NUM-CB 5)(STATE-CB 1))
(CB (ID-BUS B2)(NUM-CB 8)(STATE-CB 0))
(CB (ID-BUS B3)(NUM-CB 3)(STATE-CB 0))
(CB (ID-BUS B3)(NUM-CB 7)(STATE-CB 1))
(CB (ID-BUS B3)(NUM-CB 9)(STATE-CB 0))
(Connexion (ID-BUS B1)(CB-CLOSED nil)(CB-OPEN nil))
(Connexion (ID-BUS B2)(CB-CLOSED nil)(CB-OPEN nil))
(Connexion (ID-BUS B3)(CB-CLOSED nil)(CB-OPEN nil)))
What was required is to fill multifield slots CB-CLOSED and CB-OPEN belonging to template Connexion from facts belonging to template CB. The expected results will be something like this:
(Connexion (ID-BUS B1)(CB-CLOSED 1 4 6)(CB-OPEN nil))
(Connexion (ID-BUS B2)(CB-CLOSED 5)(CB-OPEN 2 8)))
(Connexion (ID-BUS B3)(CB-CLOSED 7)(CB-OPEN 3 9)))
Question: How did I proceed to obtain this results ?
CLIPS>
(deftemplate Connexion
(slot ID-BUS)
(multislot CB-CLOSED (default nil))
(multislot CB-OPEN (default nil)))
CLIPS>
(deftemplate CB
(slot ID-BUS)
(slot NUM-CB)
(slot STATE-CB (allowed-integers -1 0 1)(default -1)))
CLIPS>
(deftemplate State-Vector
(multislot CB-CLOSED (default nil))
(multislot CB-OPEN (default nil)))
CLIPS>
(deffacts Some-Facts
(State-Vector (CB-CLOSED 1 4 5 6 7)(CB-OPEN 2 3 8 9))
(CB (ID-BUS B1)(NUM-CB 1)(STATE-CB 1))
(CB (ID-BUS B1)(NUM-CB 4)(STATE-CB 1))
(CB (ID-BUS B1)(NUM-CB 6)(STATE-CB 1))
(CB (ID-BUS B2)(NUM-CB 2)(STATE-CB 0))
(CB (ID-BUS B2)(NUM-CB 5)(STATE-CB 1))
(CB (ID-BUS B2)(NUM-CB 8)(STATE-CB 0))
(CB (ID-BUS B3)(NUM-CB 3)(STATE-CB 0))
(CB (ID-BUS B3)(NUM-CB 7)(STATE-CB 1))
(CB (ID-BUS B3)(NUM-CB 9)(STATE-CB 0))
(Connexion (ID-BUS B1)(CB-CLOSED nil)(CB-OPEN nil))
(Connexion (ID-BUS B2)(CB-CLOSED nil)(CB-OPEN nil))
(Connexion (ID-BUS B3)(CB-CLOSED nil)(CB-OPEN nil)))
CLIPS>
(defrule populate-connexion
?c <- (Connexion (ID-BUS ?name) (CB-CLOSED nil) (CB-OPEN nil))
=>
(bind ?closed (create$))
(bind ?open (create$))
(do-for-all-facts ((?cb CB)) (eq ?cb:ID-BUS ?name)
(if (eq ?cb:STATE-CB 1)
then
(bind ?closed (create$ ?closed ?cb:NUM-CB))
else
(bind ?open (create$ ?open ?cb:NUM-CB))))
(modify ?c (CB-CLOSED ?closed) (CB-OPEN ?open)))
CLIPS> (reset)
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (State-Vector (CB-CLOSED 1 4 5 6 7) (CB-OPEN 2 3 8 9))
f-2 (CB (ID-BUS B1) (NUM-CB 1) (STATE-CB 1))
f-3 (CB (ID-BUS B1) (NUM-CB 4) (STATE-CB 1))
f-4 (CB (ID-BUS B1) (NUM-CB 6) (STATE-CB 1))
f-5 (CB (ID-BUS B2) (NUM-CB 2) (STATE-CB 0))
f-6 (CB (ID-BUS B2) (NUM-CB 5) (STATE-CB 1))
f-7 (CB (ID-BUS B2) (NUM-CB 8) (STATE-CB 0))
f-8 (CB (ID-BUS B3) (NUM-CB 3) (STATE-CB 0))
f-9 (CB (ID-BUS B3) (NUM-CB 7) (STATE-CB 1))
f-10 (CB (ID-BUS B3) (NUM-CB 9) (STATE-CB 0))
f-14 (Connexion (ID-BUS B3) (CB-CLOSED 7) (CB-OPEN 3 9))
f-15 (Connexion (ID-BUS B2) (CB-CLOSED 5) (CB-OPEN 2 8))
f-16 (Connexion (ID-BUS B1) (CB-CLOSED 1 4 6) (CB-OPEN))
For a total of 14 facts.
CLIPS>
Alternately, you can populate the Connexion facts in a single rule firing:
(defrule populate-connexion
=>
(do-for-all-facts ((?cn Connexion))
(and (eq ?cn:CB-CLOSED (create$ nil)) (eq ?cn:CB-OPEN (create$ nil)))
(bind ?closed (create$))
(bind ?open (create$))
(do-for-all-facts ((?cb CB)) (eq ?cb:ID-BUS ?cn:ID-BUS)
(if (eq ?cb:STATE-CB 1)
then
(bind ?closed (create$ ?closed ?cb:NUM-CB))
else
(bind ?open (create$ ?open ?cb:NUM-CB))))
(modify ?cn (CB-CLOSED ?closed) (CB-OPEN ?open)))))

how to print function output

I am new to racket. Please help me.
In my code, I defined show1. When I call show1 from within another function, the bit image is not being drawn. But, when I call the function separately, as (show1 a), it works.
is there any solution to print out of show1 function
(require racket/draw)
(require racket/gui)
(define target (make-bitmap 60 60)) ; A 30x30 bitmap
(define dc (new bitmap-dc% [bitmap target]))
(define board
(lambda(ls call x y)
;(send dc draw-rectangle
; 0 0 ; Top-left at (0, 10), 10 pixels down from top-left
; 60 60)
(if (even? call)
(send dc set-brush "lightblue" 'solid)
(send dc set-brush "white" 'solid))
(send dc set-pen "black" 0 'transparent)
(send dc draw-rectangle x y 20 20)
(cond
[(equal? (list-ref ls call) 'x)(printx x y) ]
[(equal? (list-ref ls call) 'o)(printy x y) ]
[(number? (list-ref ls call)) ])
(cond
[(< call 2) (board ls (+ call 1) (+ x 20) 0)]
[(= call 2) (board ls (+ call 1) 0 20)]
[(and (> call 2) (< call 5)) (board ls (+ call 1) (+ x 20) 20)]
[(= call 5) (board ls (+ call 1) 0 40)]
[(and (> call 5) (< call 8)) (board ls (+ call 1) (+ x 20) 40)])
target))
(define printx
(lambda (x y)
(send dc set-pen "red" 2 'solid)
(send dc draw-line x y (+ x 18) (+ y 18))
(send dc draw-line (+ x 18) y x (+ y 18))))
(define printy
(lambda (x y)
(send dc set-pen "red" 2 'solid)
(send dc set-brush "green" 'transparent)
(send dc draw-rounded-rectangle x y 20 20 10)))
(require unstable/list)
(require racket/mpair)
(define sot 3)
(define a (build-list (* sot sot) values))
(define dummy 1)
(define play1
(lambda (dummy)
(set! dummy (+ 1 dummy))
(play (- dummy 1))
(play1 dummy)
))
(define show1
(lambda (ls)
(board a 0 0 0)))
" 0 1 2"
" 3 4 5"
" 6 7 8"
(newline)
(printf "Above shown is the address of the tic-tac-toe box \n")
;(newline)
(define firs
(lambda (value addr pla)
(cond
[(> addr (- (* sot sot) 1)) (error "input error run it again")]
[(number? (list-ref a addr)) (set! a (list-set a addr pla)) (show1 a) (win a)]
[else (printf "error the box is already filled run it again\n") (firs value (read) pla)] )show1))
;(set! dummy (- dummy 1))
;[(error "error the box is already filled run it again")]
(define play
(lambda (dummy)
(cond
[(> dummy (* sot sot)) (printf "MATCH DRAW \n")(exit)]
[(even? dummy) (print "second player") (newline) (set! dummy (+ 1 dummy))(firs dummy (read) 'o)]
[(not (even? dummy)) (print "first player")(newline) (firs dummy (read) 'x)])))
(define win
(lambda (a)
(cond [(and (equal? (list-ref a 0) (list-ref a 3)) (equal? (list-ref a 0) (list-ref a 6))) (cond [(equal? (list-ref a 0) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 0) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 1) (list-ref a 4)) (equal? (list-ref a 1) (list-ref a 7))) (cond [(equal? (list-ref a 1) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 1) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 2) (list-ref a 5)) (equal? (list-ref a 2) (list-ref a 8))) (cond [(equal? (list-ref a 2) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 2) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 0) (list-ref a 1)) (equal? (list-ref a 0) (list-ref a 2))) (cond [(equal? (list-ref a 0) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 0) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 3) (list-ref a 4)) (equal? (list-ref a 3) (list-ref a 5))) (cond [(equal? (list-ref a 3) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 3) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 6) (list-ref a 7)) (equal? (list-ref a 6) (list-ref a 8))) (cond [(equal? (list-ref a 6) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 6) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 0) (list-ref a 4)) (equal? (list-ref a 0) (list-ref a 8))) (cond [(equal? (list-ref a 0) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 0) 'o) (print "player 2 wins")(newline) (exit)])]
[(and (equal? (list-ref a 2) (list-ref a 4)) (equal? (list-ref a 2)(list-ref a 6))) (cond [(equal? (list-ref a 2) 'x) (print "player 1 wins")(newline) (exit)]
[(equal? (list-ref a 2) 'o) (print "player 2 wins")(newline) (exit)])]
[else (board a 0 0 0)]
)));[(equal? value 8) (newline)"match draw"])))
(show1 a)
(play1 dummy)
Wow! A lot of code. I have a meta-suggestion, and a suggestion.
1) Meta-suggestion: programming is all about learning how to figure out problems by yourself. In this case, you want to see if you can strip out the parts of this giant program that don't affect the answer, to find a small program that shows the problem.
2) In this case, I think your problem is simply that values are printed when they're the result of top-level expressions, and not otherwise. To take a simple example, compare
#lang racket
(+ 3 4)
with
#lang racket
(+ (+ 1 2) 4)
Why doesn't the second one print "3", which is the result of (+ 1 2) ? It appears to me that this is the same reason that the result of show1 is not being displayed.
Caveat: per point #1, it's hard to read the code because there's so much of it...

CLIPS multiple and

Let's say that I have a rule like this:
(defrule get_next_N_poz
?id <- (get_next_poz $?)
(world (limit $?) (ball ?b1 ?b2) (men $? ?x ?y - $?) (id ?))
(and
(test (= ?x ?b1))
(test (= ?y (- ?b2 1))))
=>
(printout t "north ready position:" ?x ?y)
(modify ?id (get_next_poz 1)))
How do I add a new "and"?
Thank you.
It depends on what logic you're trying to implement. The existing and you have is redundant anyway, but if you wanted a second one, you'd just add it after the end of the last:
(and
(test (= ?x ?b1))
(test (= ?y (- ?b2 1))))
(and
(test (= ?x ?b2))
(test (= ?y (+ ?b1 1))))
If you wanted one or the other of these conditions you'd do this:
(or (and
(test (= ?x ?b1))
(test (= ?y (- ?b2 1))))
(and
(test (= ?x ?b2))
(test (= ?y (+ ?b1 1)))))
Rather than using and/or conditional elements, you could use the and/or boolean functions within a single test conditional element:
(test (or (and (= ?x ?b1)
(= ?y (- ?b2 1)))
(and (= ?x ?b2)
(= ?y (+ ?b1 1)))))

Resources