剪辑。计算学生数和输出总和
CLIPS. To count students and prinout sum
deftemplate:
(deftemplate student
(multislot fio (type SYMBOL)(cardinality 1 3))
(slot den_rozhdeniya (type INTEGER))
(slot mecyaz_rozhdeniya (type SYMBOL))
(slot god_rozhdeniya (type INTEGER))
(slot den_postupleniya (type INTEGER))
(slot mecyaz_postupleniya (type SYMBOL))
(slot god_postupleniya (type INTEGER))
(multislot data_postupleniya (type SYMBOL NUMBER))
(slot facultet (default fit)(type SYMBOL))
(slot gruppa (type SYMBOL INTEGER))
(multislot adress (type SYMBOL INTEGER))
(multislot telefon (type NUMBER))
(slot sredniy_ball(range 0 10) (type INTEGER FLOAT)))
和 5 个学生:
(assert (student(fio Semenova Yuliya Igorevna) (den_rozhdeniya 10)(mecyaz_rozhdeniya oktyabr) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2014)(gruppa 14-itd) (adress Molodeznaya 108, kv. 10) (telefon 23 56 89) (sredniy_ball 9.5))
(student(fio Korneeva Alina Sergeevna) (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Kalinina 8, kv. 4) (telefon 43 45 02) (sredniy_ball 8.5))
(student(fio Lenskaya Ekaterina Antonovna) (den_rozhdeniya 10)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2016)(gruppa 16-itd) (adress Molodeznaya 1, kv. 78) (telefon 23 56 89) (sredniy_ball 7))
(student(fio Petrov Slava Andreevich) (den_rozhdeniya 8)(mecyaz_rozhdeniya may) (god_rozhdeniya 2002)(den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2017)(gruppa 17-itd) (adress Pyshkina 5, kv. 13) (telefon 23 85 12) (sredniy_ball 5.5))
(student(fio Ivanova Svetlana Kirilovna)(den_rozhdeniya 25)(mecyaz_rozhdeniya avgust) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Molodeznaya 5, kv. 45) (telefon 78 32 51) (sredniy_ball 9)))
我需要一个规则来计算组中有多少学生。
我知道可以这样做:
(length$ (find-all-facts ((?f student)) (eq ?f: gruppa 15-itd)))
但是我想在 defrule 中进行,也可以在 defglobal
中进行
这是我的努力:
(defglobal ?*gr* = 14-itd)
(bind ?*gr* (read))
(defrule rule1
(student (gruppa ?gruppa))
=>
(printout t (length$ (find-all-facts ((?f student)) (= ?f: gruppa ?*gr*))) crlf))
CLIPS>
(defrule rule1
=>
(printout t "Group? ")
(bind ?gr (read))
(printout t "Matching students: ")
(printout t (length$ (find-all-facts ((?f student)) (eq ?f:gruppa ?gr))) crlf))
CLIPS> (run)
Group? 15-itd
Matching students: 2
CLIPS>
deftemplate:
(deftemplate student
(multislot fio (type SYMBOL)(cardinality 1 3))
(slot den_rozhdeniya (type INTEGER))
(slot mecyaz_rozhdeniya (type SYMBOL))
(slot god_rozhdeniya (type INTEGER))
(slot den_postupleniya (type INTEGER))
(slot mecyaz_postupleniya (type SYMBOL))
(slot god_postupleniya (type INTEGER))
(multislot data_postupleniya (type SYMBOL NUMBER))
(slot facultet (default fit)(type SYMBOL))
(slot gruppa (type SYMBOL INTEGER))
(multislot adress (type SYMBOL INTEGER))
(multislot telefon (type NUMBER))
(slot sredniy_ball(range 0 10) (type INTEGER FLOAT)))
和 5 个学生:
(assert (student(fio Semenova Yuliya Igorevna) (den_rozhdeniya 10)(mecyaz_rozhdeniya oktyabr) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2014)(gruppa 14-itd) (adress Molodeznaya 108, kv. 10) (telefon 23 56 89) (sredniy_ball 9.5))
(student(fio Korneeva Alina Sergeevna) (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Kalinina 8, kv. 4) (telefon 43 45 02) (sredniy_ball 8.5))
(student(fio Lenskaya Ekaterina Antonovna) (den_rozhdeniya 10)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2016)(gruppa 16-itd) (adress Molodeznaya 1, kv. 78) (telefon 23 56 89) (sredniy_ball 7))
(student(fio Petrov Slava Andreevich) (den_rozhdeniya 8)(mecyaz_rozhdeniya may) (god_rozhdeniya 2002)(den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2017)(gruppa 17-itd) (adress Pyshkina 5, kv. 13) (telefon 23 85 12) (sredniy_ball 5.5))
(student(fio Ivanova Svetlana Kirilovna)(den_rozhdeniya 25)(mecyaz_rozhdeniya avgust) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Molodeznaya 5, kv. 45) (telefon 78 32 51) (sredniy_ball 9)))
我需要一个规则来计算组中有多少学生。
我知道可以这样做:
(length$ (find-all-facts ((?f student)) (eq ?f: gruppa 15-itd)))
但是我想在 defrule 中进行,也可以在 defglobal
中进行这是我的努力:
(defglobal ?*gr* = 14-itd)
(bind ?*gr* (read))
(defrule rule1
(student (gruppa ?gruppa))
=>
(printout t (length$ (find-all-facts ((?f student)) (= ?f: gruppa ?*gr*))) crlf))
CLIPS>
(defrule rule1
=>
(printout t "Group? ")
(bind ?gr (read))
(printout t "Matching students: ")
(printout t (length$ (find-all-facts ((?f student)) (eq ?f:gruppa ?gr))) crlf))
CLIPS> (run)
Group? 15-itd
Matching students: 2
CLIPS>