CLIPSC Language Integrated Production System
Intr
oduzi
one
Intr
oduzi
one
CL
IPS:
CL
angu
age
Inte
grat
edP
rod
uct
ion
Sys
tem
CL
IPS
è u
n
tool
per
lo
sv
ilu
pp
o d
i Si
stem
iB
asat
isu
C
onos
cen
zale
cu
i or
igin
i ri
salg
ono
al
198
4 (N
ASA
�s
Joh
nso
n S
pac
eC
ente
r).
Imp
lem
enta
to i
n l
ingu
aggi
o C
per
eli
min
are
i p
robl
emi
lega
ti a
ll�u
so d
elli
ngu
aggi
o L
ISP
.
Lin
guag
gio
a re
gole
ba
sato
sull
�alg
orit
mo
Re
teco
n
il
mec
can
ism
o d
i at
tiva
zion
ed
elle
reg
ole
di
tip
o F
orw
ard
C
hain
ing
La
vers
ion
e5.
0(1
991
) in
trod
uce
du
e n
uov
ip
arad
igm
i d
ip
rogr
amm
azio
ne:
pro
gram
maz
ion
e p
roce
du
rale
e
pro
gram
maz
ion
e or
ien
tata
ag
liog
gett
i(C
LIP
S O
bjec
t-O
rien
ted
Lan
guag
e(C
OO
L))
-C
LIPS
Refe
rence
Manual:
Volu
me I -
The B
asi
c Pro
gra
mm
ing G
uid
eV
olu
me II -
The A
dvance
d P
rogra
mm
ing G
uid
eV
olu
me III �
The Inte
rface
s G
uid
e-
CLI
PS
Use
r�s
Guid
e
http://w
ww.ghg.net/clips/CLIPS.htm
lhttp://w
ww.ghg.net/clips/download/documentation/
CLIPS
is
released
as
public
domain
software
and
as
such
you
are
under
no
obligation
to
pay
for
its
use.
However,
if
you
derive
commercial
or
monetary
benefit
from
use
of
the
software
or
just
want
to
show
support,
please
consider
making a
voluntary
payment based
on
the
worth
of
the
software
to
you
as
compensation
for
the
time
and
effort
required
to
develop
and
maintain
CLIPS.
Payments
canbemadeonlineat http://order.kagi.com/?JKT.
Rif
erim
enti
Rif
erim
enti
1. u
tili
zzan
do
un
a in
terf
acci
ate
stu
ale
a li
nea
di c
oman
do;
Esec
uzi
one
Esec
uzi
one
2. u
tili
zzan
do
un
a in
terf
acci
a a
fin
estr
e;
3. c
ome
sist
ema
esp
erto
embe
dd
ed.
Esec
uzi
one
Esec
uzi
one
I co
man
di C
LIP
S so
no
sem
pre
racc
hiu
si fr
a p
aren
tesi
Alc
un
icom
and
iim
por
tan
ti�
(exi
t)
abba
nd
ona
CL
IPS
�(c
lear
)ri
mu
ove
tutt
e le
reg
ole
e i f
atti
dal
la m
emor
ia
�(r
eset
) ri
mu
ove
i fat
ti m
a n
onle
reg
ole
dal
lam
emor
ia�
(ru
n)
avvi
al'e
secu
zion
e d
i un
pro
gram
ma
CL
IPS
I pri
mi co
man
diI p
rim
i co
man
di
All
a ba
se C
LIP
S op
era
man
ten
end
o u
na
list
a d
ifa
ttie
du
nin
siem
ed
i reg
ole
che
oper
ano
sui f
atti
.
Un
fatt
o ra
pp
rese
nta
info
rmaz
ion
e(c
olor
e ve
rde)
o (
gen
itor
e G
iova
nn
i Mar
ia)
I fa
tti v
engo
no
crea
ti a
sser
end
oli n
el d
ata
base
dei
fatt
iu
tili
zzan
do
ilco
man
do
asse
rt:
CL
IPS>
(ass
ert
(col
ore
verd
e))
<F
act-
0>
<F
act-
0>
: ris
pos
ta d
el C
LIP
S p
erd
ire
che
è st
ato
inse
rito
u
n n
uov
o fa
tto
(nu
mer
o 0
) n
eld
atab
ase
dei
fat
ti.
CL
IPS>
(fac
ts)
f-0
(co
lore
ver
de)
For
a t
otal
of
1 fa
ctIntr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
I fa
tti p
osso
no
anch
e es
sere
rim
ossi
dal
dat
abas
e d
ei fa
tti
uti
lizz
and
o il
com
and
o re
trac
t:
CL
IPS>
(ass
ert
(col
ore
verd
e))
<F
act-
0>
CL
IPS>
(ass
ert
(col
ore
ross
o))
<F
act-
1>
Rit
ratt
iam
o il
pri
mo
fatt
o e
visu
aliz
ziam
o la
list
a d
ei fa
tti:
CL
IPS>
(ret
ract
0)
CL
IPS>
(fac
ts)
f-1
(col
our
red
)F
ora
tota
l of
1fa
ct.
Per
rit
ratt
are
un
fat
to b
isog
na
spec
ific
are
un
nu
mer
o (f
act-
ind
ex).
I fa
ct-i
nd
ice
non
ven
gon
o ri
usa
ti. U
na
volt
a ri
trat
tato
ilfa
tto
0,i
l pro
ssim
ofa
tto
asse
rito
avrà
ind
ice
2 e
non
0
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
I so
li fa
tto
han
no
un
uso
lim
itat
o. E
' nec
essa
ria
l'ap
pli
cazi
one
di r
egol
e p
erlo
svil
up
po
di u
n p
rogr
amm
a in
gr
ado
di e
ffet
tuar
efu
nzi
oni u
tili
. In
gen
eral
e, u
na
rego
la è
es
pre
ssa
nel
lafo
rma
�SE
qu
alco
saè
vera
AL
LO
RA
ese
gui
qual
che
azio
ne�
.Qu
esto
tip
o d
i reg
ola
è d
etta
pro
du
zion
e.
Tip
ica
rego
la C
LIP
S:
(def
rule
mor
de
(an
imal
e ca
ne)
=>
(ass
ert
(an
imal
em
ord
e)))
�se
c'è
un
fa
tto
(an
ima
leca
ne)
nel
db
dei
fa
tti,
all
ora
ass
eris
ciu
n a
ltro
fa
tto
(an
ima
lem
ord
e),n
el d
b d
ei f
att
i�
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
Un
a re
gola
con
sist
e d
i tre
par
ti
�(d
efru
le m
ord
e� d
à al
la r
egol
a u
n n
ome
un
ico
�(an
imal
e ca
ne)
� è
il p
atte
rn(l
a p
arte
IF
) d
ella
rego
la
�(as
sert
(an
imal
e m
ord
e))�
èl'a
zion
e(l
a p
arte
TH
EN
)
ESE
MP
IO
CL
IPS>
(cle
ar)
CL
IPS>
(d
efru
le m
ord
e(a
nim
ale
can
e)=
> (
asse
rt (
anim
ale
mor
de)
))C
LIP
S>(r
ule
s)C
LIP
S> (
asse
rt (
anim
ale
can
e))
CL
IPS>
(fac
ts)
CL
IPS>
(ru
n)
CL
IPS>
(fac
ts)
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
Inse
riam
o qu
esta
nu
ova
rego
la
(def
rule
can
e(a
nim
ale-
ha
cod
a)(a
nim
ale-
ha
quat
tro-
zam
pe)
=>
(ass
ert
(an
imal
eca
ne)
))
CL
IPS>
(re
set)
Ora
asse
riam
o i s
egu
enti
fatt
i
(an
imal
e-h
a co
da)
e(a
nim
ale-
ha
quat
tro-
zam
pe)
CL
IPS>
(fa
cts)
2 fa
tti
CL
IPS>
(ru
n)
CL
IPS>
(fa
cts)
4 fa
tti!
!!
Reg
ole
e fa
tti p
osso
no
esse
re s
crit
ti in
un
fil
e d
i tes
to c
on
este
nsi
one
�clp
�e
poi
car
icat
i in
CL
IPS.
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
Il c
ostr
utt
o d
eff
act
sci
per
met
ted
i ass
erir
ep
iùfa
ttin
el d
b og
ni v
olta
ch
esi
res
etta
il s
iste
ma.
(def
fact
sst
artu
p(m
asch
io g
ian
ni)
(fe
mm
ina
luci
a)(m
asch
iolu
ca)
(fem
min
am
aria
)(g
enit
ore
gian
ni l
uci
a)(g
enit
ore
mar
ialu
cia)
)
I w
ild
card
(def
rule
fig
lio-
gian
ni
(gen
itor
e gi
ann
i?)
=>
(pri
nto
ut
t "t
rova
to u
n f
igli
o d
i Gia
nn
i" c
rlf)
)
CL
IPS>
(ru
n)
trov
ato
un
figl
io d
i Gia
nn
iC
LIP
S>
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
Le
va
ria
bil
in
ei
pa
tte
rn
(def
rule
mas
chi
(mas
chio
?m)
=>
(pri
nto
ut
t "t
rova
to u
n m
asch
io"
?mcr
lf))
CL
IPS>
(ru
n)
trov
ato
un
mas
chio
gia
nn
itr
ovat
ou
n m
asch
io lu
caC
LIP
S>
(def
rule
mad
re(f
emm
ina
?f)
(gen
itor
e ?f
?x)
=>
(pri
nto
ut
t"t
rova
tam
adre
"?m
�di�
?xcr
lf))
Intr
o C
LIPS:
Fat
tie
rego
leIn
tro
CLI
PS:
Fat
tie
rego
le
La
rap
pre
sen
tazi
one
del
l�in
form
azio
ne
in C
LIP
Sav
vien
e p
erm
ezzo
dif
att
i,og
get
tie
vari
abi
lig
loba
li
Fa
tti
I fa
tti s
ono
un
o st
rum
ento
di b
ase,
di a
lto
live
llo,
per
la
rap
pre
sen
tazi
one
del
l�in
form
azio
ne
in C
LIP
S.
Ogn
ifa
tto
rap
pre
sen
tau
na
por
zion
e d
i in
form
azio
ne
mem
oriz
zata
nel
db
dei
fatt
i (li
sta
dei
fatt
i fa
ct-l
ist)
. Ifa
tti
rap
pre
sen
tan
o l�u
nit
àfo
nd
amen
tale
did
ati u
tili
zzat
a d
alle
reg
ole.
I fa
tti p
osso
no
esse
rea
gg
iun
tial
lafa
ct-l
ist
(uti
lizz
and
o il
co
man
do
ass
ert
),ri
mos
sid
alla
fact
-lis
t(u
tili
zzan
do
il c
oman
do
retr
act
), m
odif
icat
i(u
tili
zzan
do
il c
oman
do
mo
dif
y),o
du
pli
cati
(u
tili
zzan
do
il c
oman
do
du
pli
cate
).
L'as
traz
ione
dati
L'as
traz
ione
dati
Il C
LIP
S fo
rnis
ce t
reel
emen
tid
ibas
e p
er s
criv
ere
pro
gram
mi:
-ti
pi d
i dat
i pri
mit
ivi,
-fu
nzi
oni p
er la
man
ipol
azio
ne
dei
dat
i, e
-co
stru
tti p
er l�
aggi
un
ta d
i con
osce
nza
.
Tip
idi d
atip
er la
rap
pre
sen
tazi
one
di v
alor
i nu
mer
ici
�in
tege
r: 2
37, 1
5,+
12, -
32
�fl
oat:
237
e3, 1
5.0
9,+
12.0
,-32
.3e-
7
<in
tege
r> ::
= [
+ |
-]
<d
igit
>+
<d
igit
>::
= 0
| 1
|2
|3
|4
|5
|6
| 7
|8
|9
<fl
oat>
::=
<in
tege
r> <
exp
onen
t> |
<in
tege
r>.[
exp
onen
t].<
un
sign
ed in
tege
r> [
exp
onen
t]<
inte
ger>
. <
un
sign
edin
tege
r>[e
xpon
ent]
<u
nsi
gned
-in
tege
r>::
=<
dig
it>
+<
exp
onen
t> ::
= e
| E
<in
tege
r>
Elem
enti
di ba
seEl
emen
ti d
i ba
se
Tip
i di d
ati p
er la
rap
pre
sen
tazi
one
di v
alor
i sim
boli
ci
Sym
bo
l: s
equ
enza
di c
arat
teri
ch
ep
arto
no
con
un
car
atte
reA
SCII
sta
mp
abil
e, s
egu
ito
da
zero
op
iùca
ratt
eri A
SCII
st
amp
abil
i. N
on p
uò
iniz
iare
con
i ca
ratt
eri?
e$
? p
oich
éso
no
rise
rvat
i all
e va
riab
ili
�sy
mbo
l: fo
o,H
ello
,B76
-HI,
bad
_va
lue,
127A
,456
-93-
039
,@+
=-%
,2ea
ch
Str
ing
: in
siem
e d
i car
atte
ri c
he
iniz
ian
o co
n il
sim
bolo
"se
guit
i d
a ca
ratt
eri A
SCII
sta
mp
abil
ie c
he
term
inan
o co
n il
sim
bolo
"
�st
rin
g:"
foo"
, "a
and
b",
"1
nu
mbe
r", "
a\"q
uot
e�
Elem
enti
di ba
seEl
emen
ti d
i ba
se
�ex
tern
al-a
dd
ress
: gl
i in
dir
izzi
del
lest
rutt
ure
dat
i es
tern
ere
stit
uit
ida
un
a fu
nzi
one
inte
grat
aco
n il
CL
IPS
�fa
ct-a
dre
sses
: u
n f
atto
èu
na
list
a d
i val
ori a
tom
ici a
iqu
ali
si p
uò
fare
rif
erim
ento
per
pos
izio
ne
(ord
ered
fact
s)o
per
nom
e (n
on-o
rder
ed o
tem
pla
tefa
cts)
. A
du
n f
atto
si
fari
feri
men
toco
nu
nin
dic
eo
con
un
ind
iriz
zo
�in
stan
ce-n
ame,
inst
ance
-ad
dre
ss:
un
ais
tan
zaè
un
ogge
tto,
ista
nzi
azi
one
di
un
a sp
ecif
ica
clas
se a
lla
qual
esi
p
uò
far
rife
rim
ento
con
il s
uo
nom
e
Ogg
etti
CL
IPS:
flo
at,
inte
gers
,sy
mbo
l,st
rin
g,m
ult
ifie
ld,
exte
rnal
-ad
ress
es,
fact
-ad
ress
eso
inst
ance
s d
iu
na
clas
seu
ser-
def
ined
.
Elem
enti
di ba
seEl
emen
ti d
i ba
se
Un
inst
an
ce-n
am
eè
un
sim
bolo
racc
hiu
sotr
ap
aren
tesi
qu
adre
[pu
mp
-1]
[foo
] [+
++
] [1
23-8
90
]
InC
LIP
Su
nse
gnap
osto
con
un
valo
reè
det
tofi
eld
.
Un
mu
ltif
ield
va
lue
èu
na
sequ
enza
di
zero
op
iù�s
ingl
efi
eld
valu
es�
rac
chiu
si t
ra p
aren
tesi
ton
de
(a)
(1ba
rfo
o)()
(x
3.0
"re
d"
567)
Cos
tan
te: s
ingo
lofi
eld
con
valo
refi
sso
Var
iabi
le: l
ocaz
ion
e si
mbo
lica
uti
lizz
ata
per
imm
agaz
zin
are
valo
ri
Com
men
ti: p
rece
du
ti d
alsi
mbo
lo ;
Elem
enti
di ba
seEl
emen
ti d
i ba
se
Un
afu
nzi
on
ein
CL
IPS
è u
na
por
zion
e d
i cod
ice
eseg
uib
ile
iden
tifi
cata
da
un
o sp
ecif
ico
nom
ech
ere
stit
uis
ceu
n v
alor
eo
ha
un
eff
etto
col
late
rale
.
Ilco
stru
tto
de
ffu
nct
ion
per
met
teal
l�ute
nte
di d
efin
ire
nu
ove
fun
zion
i, d
iret
tam
ente
nel
l�am
bien
teC
LIP
S. Q
ues
to t
ipo
di
fun
zion
i agi
scon
o co
me
leal
tre
(use
r d
efin
edfu
nct
ion
se
syst
emd
efin
e fu
nct
ion
s), p
erò,
inve
ced
i ess
ere
eseg
uit
ed
iret
tam
ente
(com
e ac
cad
e p
eril
cod
ice
scri
tto
in u
n li
ngu
aggi
o es
tern
o)
ven
gon
o in
terp
reta
ted
all�a
mbi
ente
CL
IPS.
Le
fun
zion
igen
eric
he
pos
son
oes
sere
def
init
eu
tili
zzan
do
i co
stru
tti d
efg
en
eri
ce
de
fme
tho
d. Q
ues
toti
po
di f
un
zion
i p
erm
etto
no
l�ese
cuzi
one
di d
iver
sep
orzi
oni d
i cod
ice
in b
ase
agli
ar
gom
enti
pas
sati
all
afu
nzi
one.
Qu
ind
i, u
n s
ingo
lo n
ome
di
fun
zion
ep
uò
esse
reso
vra
cca
rica
toco
n p
iù p
orzi
oni d
i cod
ice.
Cli
ps
uti
lizz
ala
not
azi
one
pre
fiss
ap
er le
fun
zion
i(*
8 (
+ 3
(*2
34)
9)
(*3
4))
Elem
enti
di ba
seEl
emen
ti d
i ba
se
Il C
LIP
S fo
rnis
ce m
olti
cost
rutt
i:
de
fmo
du
le,
de
fru
le,
de
ffa
cts,
de
fte
mp
late
,d
efg
lob
al,
d
eff
un
ctio
n,
de
fcla
ss,
de
fin
sta
nce
s,d
efm
ess
ag
e-h
an
dle
r,d
efg
en
eri
c, e
d
efm
eth
od
.
Elem
enti
di ba
seEl
emen
ti d
i ba
se
Per
pot
er u
tili
zzar
e i c
oman
dir
etr
act
,mo
dif
y,e
du
pli
cate
èn
eces
sari
o sp
ecif
icar
eu
n fa
tto
per
mez
zo d
elsu
ofa
ct-i
nd
ex
o
fact
-ad
dre
ss. A
dog
ni f
atto
agg
iun
to (
o m
odif
icat
o) v
ien
eas
soci
ato
un
ind
ice
inte
ro (
un
ico)
det
to f
act
-in
dex
i fac
t-in
dex
par
ton
o d
a ze
ro e
son
o in
crem
enta
ti d
i un
op
erog
ni n
uov
o fatt
oca
mbi
ato
L�e
ffet
to d
eico
man
di r
ese
t o
cle
ar
è d
i por
re a
zer
o i f
act-
ind
ex
Un
fatt
op
uò
anch
ees
sere
spec
ific
ato
per
mez
zod
el s
uo
fact
-ad
dre
ss, o
tten
uto
catt
ura
nd
oil
valo
rere
stit
uit
o d
aico
man
di
che
rest
itu
isco
no
un
fac
t-ad
dre
ss (
ass
ert
,m
od
ify,
ed
up
lica
te)
o m
app
and
o u
na
vari
abil
eal
fac
t-ad
dre
ss d
i un
fat
to in
un
pat
tern
n
ella
LH
Sd
iun
are
gola
La
mem
oriz
zazi
one
dei
fatt
ipu
òa
vven
ire
in m
odo
ord
ina
to e
in
mod
o n
on-o
rdin
ato
Ifat
tiIf
atti
I fa
tti
ord
ina
tiso
no
cost
itu
iti
da
un
sim
bolo
segu
ito
da
un
a se
quen
za d
i zer
o o
più
cam
pis
epar
ati d
asp
azi e
del
imit
ati d
au
na
par
ente
si a
per
ta a
sin
istr
a e
da
un
a p
aren
tesi
ch
iusa
a d
estr
a.
Il p
rim
o ca
mp
o d
iun
fatt
o or
din
ato
spec
ific
a u
na
rela
zion
ech
eè
app
lica
ta a
i res
tan
ti c
amp
i del
fatt
o.
Per
esem
pio
, (p
adre
gio
van
nim
ario
)d
ice
che
giov
ann
iè
il p
adre
mar
io.
(for
no
acce
so)
(alt
ezza
100
m)
(ele
nco
-sp
esa
zucc
her
o m
iele
zu
cch
ine
pom
odor
i)
Fat
ti o
rdin
ati
Fat
ti o
rdin
ati
I fa
tti o
rdin
ati r
app
rese
nta
no
info
rma
zion
e or
din
ata
. Per
pot
erac
ced
ere
aqu
esto
tip
o d
i in
form
azio
ne
biso
gna
con
osce
re i
cam
pi
che
laco
nte
ngo
no.
I fa
tti
no
n o
rdin
ati
(o t
em
pla
te)
forn
isco
no
la p
ossi
bili
tà d
i as
trar
red
alla
str
utt
ura
del
fatt
oas
segn
and
o d
ei n
omi a
d o
gni
cam
po
nel
fatt
o. I
l cos
tru
tto
de
fte
mp
late
(an
alog
o al
la
def
iniz
ion
e d
i rec
ord
od
i str
utt
ura
in C
)vi
ene
uti
lizz
ato
per
cr
eare
un
tem
pla
tech
ep
oip
uò
esse
re u
tili
zzat
o p
er a
cced
ere
aica
mp
i per
nom
e.
Un
tem
pla
te è
def
init
od
a ze
ro o
più
def
iniz
ion
i di s
lots
.(c
lien
te (
nom
e "P
aolo
Ros
si")
(id
X93
45A
))(p
un
to-d
i-m
assa
(x-v
eloc
ita
100
) (y
-vel
ocit
a-2
00
))
(cor
so(d
ocen
te "
Bia
nch
i")
(#-s
tud
enti
30)
(au
la"3
7A")
)(c
orso
(#-s
tud
enti
30)
(doc
ente
"B
ian
chi"
)(a
ula
"37
A")
)
Fat
tinon
ordi
nat
iFat
tinon
ordi
nat
i
Un
og
ge
tto
inC
LIP
Sè
un
sim
bolo
, u
na
stri
nga
,u
n n
um
ero
floa
tin
g-p
oin
to
inte
ro, u
n m
ult
ifie
ldva
lue,
un
exte
rnal
-ad
dre
sso
un
a is
tan
za d
i u
na
clas
seu
ser-
def
ined
. G
li o
gget
ti s
ono
des
crit
ti
da
un
a p
rop
riet
à e
da
un
com
por
tam
ento
. U
na
cla
sse
èu
nte
mp
late
di
pro
pri
età
eco
mp
orta
men
tico
mu
ni
ad o
gget
tich
e so
no
ista
nze
del
lacl
asse
.
Rol
ls-R
oyce
del
la c
lass
e SY
MB
OL
"Rol
ls-R
oyce
" d
ella
cla
sse
STR
ING
8.0
del
lacl
asse
FL
OA
T8
del
la c
lass
e IN
TE
GE
R(8
.0R
olls
-Roy
ce 8
[R
olls
-Roy
ce])
del
la c
lass
e M
UL
TIF
IEL
D<
Poi
nte
r-0
0C
F61
AB
> d
ella
cla
sse
EX
TE
RN
AL
-AD
DR
ESS
[Rol
ls-R
oyce
] d
ella
clas
seC
AR
(a u
ser-
def
ined
cla
ss)
Gli o
gget
tiG
li o
gget
ti
Ilco
stru
tto
de
fglo
ba
l p
erm
ette
la d
efin
izio
ne
di v
aria
bili
gl
obal
i. È
pos
sibi
le a
cced
ere
da
qual
sias
i par
te a
qu
este
var
iabi
li.
Alc
un
i cos
tru
tti(
com
e d
efru
lee
def
fun
ctio
n)
per
met
ton
ol�a
lloc
azio
ne
di v
aria
bili
loca
li a
lle
qual
isip
uò
acce
der
ed
all�i
nte
rno
del
cost
rutt
o, m
ach
en
onh
ann
o si
gnif
icat
o al
cun
o al
d
i fu
ori d
el c
ostr
utt
o.
Un
a va
riab
ile
glob
ale
in C
LIP
S è
sim
ile
alle
var
iabi
li g
loba
li d
ei
lin
guag
gi p
roce
du
rali
,ma
ha
tip
izza
zion
ed
ebol
e(n
on
nec
essa
riam
ente
dev
eco
nte
ner
eu
nva
lore
di u
nso
loti
po)
Var
iabiligl
obal
iV
aria
biligl
obal
i
Per
rap
pre
sen
tare
la c
onos
cen
za C
LIP
S fo
rnis
ceu
n p
ara
dig
ma
eu
rist
ico
edu
np
ara
dig
ma
pro
ced
ura
le.
Co
no
sce
nza
Eu
rist
ica
: le
re
go
le
Un
met
odo
per
rap
pre
sen
tare
la c
onos
cen
za in
CL
IPS
èat
trav
erso
la r
egol
a.
Le
rego
leso
no
uti
lizz
ate
per
rap
pre
sen
tare
euri
stic
he
che
spec
ific
ano
un
insi
eme
di a
zion
ida
effe
ttu
are
inu
na
dat
asi
tuaz
ion
e.
Un
a re
gola
è c
osti
tuit
a d
a u
nan
tece
den
te(l
eft-
han
d-s
ide,
LH
S)e
da
un
con
segu
ente
(rig
ht-h
an
d-s
ide,
RH
S)
Rap
pre
senta
zion
e de
lla
conos
cenza
Rap
pre
senta
zion
e de
lla
conos
cenza
L�a
nte
ced
ente
di u
na
rego
la è
un
insi
eme
dic
on
diz
ion
i(c
on
dit
ion
al
ele
me
nts
)ch
ed
evon
oes
sere
vere
affi
nch
éla
rego
la s
ia a
pp
lica
bile
. In
CL
IPS,
la s
odd
isfa
cibi
lità
del
le c
ond
izio
ni d
i un
a re
gola
èba
sata
su
ll�e
sist
enza
o m
eno
di s
pec
ific
i fat
ti n
ella
fac
t-li
st o
di
spec
ific
he
ista
nze
di c
lass
i nel
la in
stan
ce-l
ist.
Un
tip
o d
i con
diz
ion
ech
ep
uò
esse
resp
ecif
icat
a è
ilp
att
ern
.Ip
atte
rn s
ono
cost
itu
iti d
a u
n in
siem
ed
i res
triz
ion
i uti
lizz
ate
per
d
eter
min
are
qual
i fat
ti o
ogg
etti
sod
dis
fan
o le
con
diz
ion
i nel
p
atte
rn.
Il p
roce
sso
di m
atc
hin
gfr
a fa
tti/
ogge
tti e
il p
atte
rn è
det
to
pa
tte
rn-m
atc
hin
g.
IlC
LIP
Sfo
rnis
ceu
nm
oto
re i
nfe
ren
zia
lech
eau
tom
atic
amen
tem
app
ai p
atte
rn s
ull
afa
ct-l
ist
e/o
sull
a in
stan
ce-l
ist
corr
ente
, det
erm
inan
do
qual
i reg
ole
son
o ap
pli
cabi
li
Le r
egol
eLe
reg
ole
Il c
onse
guen
te d
i un
a re
gola
è c
osti
tuit
od
a u
n in
siem
ed
i azi
oni
da
eseg
uir
e qu
and
o il
mot
ore
infe
ren
zial
ed
elC
LIP
Sd
ecid
ed
i ap
pli
care
lare
gola
. Se
son
o ap
pli
cabi
lip
iù r
egol
e, il
mot
ore
infe
ren
zial
e u
tili
zza
un
ast
rate
gia
di
riso
luzi
on
e d
i co
nfl
itti
per
sele
zion
are
qual
ere
gola
dev
e es
sere
ese
guit
aD
opo
aver
ese
guit
o le
azio
ni d
ella
rego
la s
elez
ion
ata
(ch
ep
osso
no
infl
uen
zare
lali
sta
del
le r
egol
e ap
pli
cabi
li)
il m
otor
ein
fere
nzi
ale
sele
zion
a u
n�a
ltra
reg
ola
da
eseg
uir
eQ
ues
to p
roce
sso
con
tin
ua
fin
quan
do
non
res
tan
o re
gole
app
lica
bili
Le r
egol
eLe
reg
ole
IlC
LIP
S su
pp
orta
an
che
un
par
adig
ma
pro
ced
ura
le p
er la
ra
pp
rese
nta
zion
e d
ella
con
osce
nza
com
equ
ello
dei
lin
guag
giP
asca
l e C
. L
efu
nzi
on
i (d
eff
un
ctio
ns)
ele
fun
zio
ni
ge
ne
rich
e(g
ener
ic
fun
ctio
ns)
per
met
ton
o al
l�ute
nte
di d
efin
ire
nu
ovi e
lem
enti
eseg
uib
ili c
he
pro
voca
no
un
eff
etto
coll
ater
ale
opp
ure
che
rest
itu
isco
no
un
val
ore.
I m
essa
ge-h
and
lers
per
met
ton
o al
l�ute
nte
di d
efin
ire
ilco
mp
orta
men
to d
egli
ogg
etti
sp
ecif
ican
do
la lo
ro r
isp
osta
ai
mes
sagg
i. D
effu
nct
ion
s, g
ener
ic f
un
ctio
ns
e m
essa
ge-
han
dle
rs s
ono
por
zion
i di c
odic
e p
roce
du
rale
sp
ecif
ica
ti d
all
�ute
nte
che
ilC
LIP
S es
egu
e qu
an
do
opp
ortu
no.
D
efm
od
ule
sp
erm
ette
di p
arti
zion
are
la b
ase
di c
onos
cen
za
Con
osce
nza
pro
cedu
rale
Con
osce
nza
pro
cedu
rale
In u
nli
ngu
aggi
o or
ien
tato
agl
i ogg
etti
, tu
tti g
li e
lem
enti
di
pro
gram
maz
ion
eso
no
ogge
tti m
anip
olat
i per
mez
zo d
i mes
sagg
i. In
CL
IPS,
lad
efin
izio
ne
diu
n o
gget
to è
più
fort
e:
nu
mer
i flo
atin
g-p
oin
te
inte
ri, s
imbo
li, s
trin
ghe,
mu
ltif
ield
valu
es, e
xter
nal
-ad
dre
sses
, fac
t-ad
dre
sses
e is
tan
ze d
i cla
ssiu
ser-
def
ined
.T
utt
igli
ogg
etti
pos
son
o es
sere
man
ipol
atic
on i
mes
sagg
i.L
eis
tan
zed
elle
clas
siu
ser-
def
ined
dev
ono
esse
re m
anip
olat
e co
ni
mes
sagg
i.C
arat
teri
stic
he
di u
n s
iste
ma
OO
P: a
stra
zio
ne
, in
cap
sula
zio
ne
,e
red
ita
rie
tà,
po
lim
orf
ism
o e
bin
din
g
din
am
ico
.
CLI
PS
Obje
ct O
rien
ted
CLI
PS
Obje
ct O
rien
ted
I fa
tti o
rdin
ati r
app
rese
nta
no
info
rmaz
ion
e p
osiz
ion
ale.
Per
ac
ced
ere
a qu
esto
tip
o d
i in
form
azio
ne,
l�u
ten
ted
eve
con
osce
ren
on s
olo
il t
ipo
did
ato
mem
oriz
zato
ma
anch
equ
alic
amp
ilo
con
ten
gon
o.
I fa
tti n
on o
rdin
ati
(o t
emp
late
) fo
rnis
con
o la
pos
sibi
lità
di
astr
arre
dal
la s
tru
ttu
ra d
ei fa
tti a
sseg
nan
do
dei
nom
i ad
ogn
i ca
mp
o d
elfa
tto.
Ilco
stru
tto
de
fte
mp
late
vien
eu
tili
zzat
o p
er c
rear
eu
n t
emp
late
che
pu
ò es
sere
usa
to p
er d
efin
ire
fatt
i non
ord
inat
i.I tem
pla
teI t
empla
te
(deftemplate
<deftemplate-name>
[<comment>]
<slot-definition>*)
<slot-definition>
::=
<single-slot-definition>
|<multislot-definition>
<single-slot-definition>
::=
(slot
<slot-name><template-attribute>*)
<multislot-definition>
::=
(multislot
<slot-name><template-attribute>*)
<template-attribute>
::=
<default-attribute>
<constraint-attribute>
<default-attribute>
::=
(default
?DERIVE
|?NONE
|<expression>*)
|(default-dynamic
<expression>*)
(deftemplate
corso
(slot
nome)
(slot
studenti)
(slotdocente)
(slot
aula))
I tem
pla
teI t
empla
te
<de
faul
t-at
trib
ute>
spec
ifica
il
valo
re d
a ut
ilizz
are
com
e de
faul
t qu
ando
vie
ne a
sser
ito u
n te
mpl
ate
L�at
trib
uto
def
ault
sp
ecifi
ca
un
valo
re
di
defa
ult
stat
ico.
La
va
luta
zion
e av
vien
e un
aso
lavo
ltaal
lade
finiz
ione
del
defte
mpl
ate.
L�at
trib
uto
def
ault
-dyn
amic
è
un
dyna
mic
de
faul
t. La
va
luta
zion
e av
vien
e og
ni v
olta
che
vie
ne a
sser
ito u
n te
mpl
ate.
I val
oridi
def
ault
I val
oridi
def
ault
CLIPS>
(clear)
CLIPS>
(deftemplate
foo
(slot
w(default
?NONE))
(slot
x(default
?DERIVE))
(slot
y(default
(gensym*)))
(slot
z(default-dynamic
(gensym*))))
CLIPS>
(assert
(foo))
[TMPLTRHS1]
Slot
wrequiresa
value
because
of
its
(default
?NONE)
attribute.
CLIPS>
(assert
(foo
(w
3)))
<Fact-0>
CLIPS>
(assert
(foo
(w
4)))
<Fact-1>
CLIPS>
(facts)
f-0
(foo
(w
3)
(x
nil)
(y
gen1)
(z
gen2))
f-1
(foo
(w
4)
(x
nil)
(y
gen1)
(z
gen3))
For
atotal
of
2facts.
CLIPS>
I val
oridi
def
ault
I val
oridi
def
ault
(deftemplate
object
(slot
name
(type
SYMBOL)
(default
?DERIVE))
(slot
location
(type
SYMBOL)
(default
?DERIVE))
(slot
on-top-of
(type
SYMBOL)
(default
floor))
(slot
weight
(allowed-values
light
heavy)
(default
light))
(multislot
contents
(type
SYMBOL)
(default
?DERIVE)))
I vin
coli
I vin
coli
Qu
and
o si
ass
eris
ce o
si f
ari
feri
men
toad
un
fat
toor
din
ato
(com
e in
un
LH
S p
atte
rn)
vien
ecr
eato
un
�im
pli
ed�
tem
pla
te c
onu
nso
losl
ot.
CLIPS>
(clear)
CLIPS>
(assert
(foo
12
3))
<Fact-0>
CLIPS>
(defrule
yak
(bar
45
6)
=>)
CLIPS>
(list-deftemplates)
initial-fact
foo
bar
For
atotal
of
3deftemplates.
CLIPS>
(facts)
f-0
(foo
12
3)
For
atotal
of
1fact.
CLIPS>
init
ial
init
ial --
fact
fact
Ilco
stru
tto
de
ffa
cts
per
met
ted
i def
inir
eu
na
list
ad
i fat
ti c
he
ven
gon
o as
seri
ti a
uto
mat
icam
ente
qu
and
o si
invo
ca il
com
and
ore
set.
I fa
tti a
sser
iti c
on d
effa
cts
pos
son
o es
sere
ritr
atta
ti o
map
pat
i co
me
glia
tri f
atti
.
La
init
ial f
act-
list
, ch
e in
clu
de
ogn
idef
fact
sd
efin
ito,
vie
ne
sem
pre
ric
ostr
uit
a d
opo
ogn
i com
and
o re
set
Sin
tass
i(d
effa
cts
<d
effa
cts-
nam
e> [
<co
mm
ent>
]<
RH
S-p
atte
rn>
*)
Il co
stru
tto
deff
acts
Il co
stru
tto
deff
acts
(deffacts
albero-genealogico
"Albero
G�
(maschio
mario)
(femmina
giulia)
(genitore
mario
giulia))
Dop
o og
ni a
vvio
ed
opo
il c
oman
do
cle
ar,
CL
IPS
cost
ruis
ceau
tom
atic
amen
te i
segu
enti
def
tem
pla
te e
def
fact
s.
(deftemplate
initial-fact)
(deffacts
initial-fact
(initial-fact))
Il co
stru
tto
deff
acts
Il co
stru
tto
deff
acts
Un
od
ei p
rin
cip
ali m
etod
i per
la r
app
rese
nta
zion
e d
ella
co
nos
cen
za in
CL
IPS
èat
trav
erso
lare
gola
.U
na
reg
ola
èu
na
coll
ezio
ne
di c
ond
izio
ni e
d a
zion
i da
com
pie
re
quan
do
le c
ond
izio
nis
ono
sod
dis
fatt
e. L
o sv
ilu
pp
ator
e d
i un
sist
ema
esp
erto
def
inis
ce le
reg
ole
che
des
criv
ono
com
e ri
solv
ere
un
pro
blem
a.L
�ese
cuzi
one
del
lere
gole
èba
sata
su
ll�e
sist
enza
om
eno
di f
atti
o is
tan
ze d
elle
clas
si d
efin
ite
dal
l�ute
nte
.
CL
IPS
forn
isce
il m
ecca
nis
mo
(in
fere
nce
en
gin
e)
che
cerc
ad
ies
egu
ire
un
mat
chin
g fr
a le
rego
le e
lo s
tato
att
ual
e d
el s
iste
ma
(com
era
pp
rese
nta
to d
alla
fac
t-li
st e
dal
la in
stan
ce-l
ist)
ed
app
lica
le a
zion
iU
tili
zzer
emo
il t
erm
ine
pa
tte
rne
nti
typ
er fa
rri
feri
men
to a
d u
nfa
tto
o ad
un
a is
tan
za d
i un
a cl
asse
def
init
a d
all�u
ten
te
Il co
stru
tto
def
rule
Il co
stru
tto
def
rule
Le
rego
leso
no
def
init
e u
tili
zzan
do
il c
ostr
utt
o d
efr
ule
.(d
efru
le <
rule
-nam
e> [
<co
mm
ent>
][<
dec
lara
tion
>]
;Ru
leP
rop
erti
es<
con
dit
ion
al-e
lem
ent>
*; L
eft-
Han
d S
ide
(LH
S)=
><
acti
on>
*); R
igh
t-H
and
Sid
e(R
HS)
Le
azio
ni
ven
gon
o es
egu
ite
inm
odal
ità
sequ
enzi
ale,
se
eso
lose
, so
no
sod
dis
fatt
etu
tte
leco
nd
izio
ni (
con
dit
ion
al-e
lem
ent)
in L
HS.
(def
rule
ese
mp
io"E
sem
pio
di r
egol
a"(f
rigo
luce
acc
esa)
(fri
go p
orta
ap
erta
)=
> (ass
ert
(fri
go c
ibo
guas
to))
)
Def
inir
e le
reg
ole
Def
inir
e le
reg
ole
Cos
tru
ita
la b
ase
di c
onos
cen
za (
info
rma
di r
egol
e) e
pre
par
ata
la f
act-
list
e/o
la in
stan
ce-l
ist,
ilC
LIP
S è
pro
nto
per
ese
guir
e le
rego
le.
Ne
i li
ng
ua
gg
i d
i p
rog
ram
ma
zio
ne
con
ve
nzi
on
ali
, il
p
rog
ram
ma
tore
de
fin
isce
esp
lici
tam
en
te l
a s
eq
ue
nza
d
ell
e o
pe
razi
on
i. C
iò n
on
acc
ad
e i
n C
LIP
S.
La
con
osce
nza
(re
gole
) e
idat
i(fa
tti e
ista
nze
) so
no
sep
arat
i,e
il
mot
ore
infe
ren
zial
e fo
rnit
o d
alC
LIP
S vi
ene
uti
lizz
ato
per
ap
pli
care
la c
onos
cen
za a
i dat
i.
Cic
lo d
'ese
cuzi
one
di re
gole
Cic
lo d
'ese
cuzi
one
di re
gole
a) S
i con
side
ra la
list
a de
lle r
egol
e po
ste
nell�
agen
da
appa
rten
enti
al m
odul
o co
rren
te d
efin
ito n
el fo
cus
stac
k�
Si s
elez
iona
que
lla c
he s
i tro
va a
ltop
della
lista
e la
si e
segu
e�
Se
non
ci s
ono
rego
le d
a at
tivar
e:�
Si e
limin
a il
mod
ulo
corr
ente
dal
focu
s st
ack
�S
ipas
sa il
con
trol
loal
mod
ulo
succ
essi
vo:
�S
e il
focu
sst
ack
è vu
oto
l�ese
cuzi
one
term
ina,
al
trim
enti
siat
tivan
o le
re
gole
de
l nu
ovo
mod
ulo
corr
ente
b) S
i ese
gue
la R
HS
del
la r
egol
a se
lezi
onat
a pe
r l�e
secu
zion
e
Cic
lo d
'ese
cuzi
one
di re
gole
Cic
lo d
'ese
cuzi
one
di re
gole
c) �il
risul
tato
del
pas
sob)
com
port
a la
mod
ifica
del
lam
emor
ia d
i la
voro
�qu
esto
pro
voca
l�atti
vazi
one
di a
ltre
rego
le o
ladi
satti
vazi
one
diqu
elle
già
pres
enti
nell�
agen
da�
le r
egol
e at
tivat
e ve
ngon
o m
esse
nel
l�age
nda
del
mod
ulo
in
cui s
ono
defin
ite e
l�or
dine
è d
eter
min
ato:
�S
alie
nce,
e�
Con
flict
res
olut
ion
stat
egy
�le
reg
ole
disa
ttiva
te v
engo
no e
limin
ate
dall�
agen
dad)
�
Se
è st
ata
defin
ita u
na r
ival
utaz
ione
dina
mic
a de
l sa
lienc
e,
allo
ra i
val
ori
dei
salie
nce
appa
rten
enti
alle
reg
ole
esis
tent
i ne
ll�ag
enda
, ven
gono
rival
utat
i; si
rip
rend
e da
l pun
to a
)
Cic
lo d
'ese
cuzi
one
di re
gole
Cic
lo d
'ese
cuzi
one
di re
gole
L� a
ge
nd
a è
lali
sta
di t
utt
e le
rego
lech
eh
ann
o la
par
te s
inis
tra
(LH
S) s
odd
isfa
tta
(e n
on s
ono
anco
ra s
tate
eseg
uit
e). O
gni
mod
ulo
ha
la s
ua
pro
pri
a ag
end
a.A
gisc
eco
me
un
o st
ack:
lare
gola
al t
opè
la p
rim
a ad
esse
re e
segu
ita.
Q
uan
do
un
a re
gola
vie
ne
atti
vata
, la
sua
pos
izio
ne
nel
l�age
nd
a è
basa
ta s
ui s
egu
enti
fat
tori
:�
al d
isop
rad
itu
tte
lere
gole
con
sa
lien
cep
iù b
asso
ed
al d
i sot
to
di t
utt
e le
rego
le c
onsa
lien
cep
iùal
to;
�fr
a re
gole
con
ste
sso
sali
ence
, èla
str
ateg
ia d
i ris
olu
zion
e d
elco
nfl
itto
(co
nfl
ict
reso
luti
on s
trat
egy)
a d
eter
min
are
la p
osiz
ion
e;
�se
un
a re
gola
è a
ttiv
ata
(in
siem
ead
alt
re)
per
la s
tess
am
odif
ica
del
laW
M, e
i pas
si a
) e
b) n
on s
ono
in g
rad
od
i sp
ecif
icar
el�o
rdin
e, a
llor
a vi
ene
ord
inat
ain
bas
e al
la s
iste
maz
ion
e d
elle
alt
rere
gole
atti
vate
insi
eme
ad e
ssa.
Stra
tegi
a di
riso
luzi
one
dei
con
flit
tiSt
rate
gia
diri
solu
zion
e dei
con
flit
ti
L�u
ten
te p
uò
asse
gnar
e u
na
pri
orit
à ad
un
a re
gola
tram
ite
la s
ali
en
ce r
ule
pro
per
ty.
I va
lori
di s
alie
nce
pos
son
o es
sere
valu
tati
: -
quan
do
vien
e d
efin
ita
la r
egol
a,
-qu
and
o vi
ene
atti
vata
la r
egol
a o
adog
ni e
secu
zion
e.
(def
rule
tes
t-1
(dec
lare
(sal
ien
ce 9
9))
(fir
e te
st-1
)=
>(p
rin
tou
t t
"Ru
lete
st-1
firi
ng.
"cr
lf))
(def
rule
tes
t-2
(dec
lare
(sa
lien
ce (
+ ?
*con
stra
int-
sali
ence
* 10
)))
(fir
ete
st-2
)=
>(p
rin
tou
t t
"Ru
le t
est-
2fi
rin
g."
crlf
))
Salien
ceSa
lien
ce
Le
rego
le a
ttiv
ate
son
o p
osiz
ion
ate
sop
ra t
utt
ele
rego
leco
n lo
stes
so s
alie
nce
ilfa
tto-
aat
tiva
la r
egol
a-1
ela
rego
la-2
ilfa
tto-
bat
tiva
la r
egol
a-3
ela
rego
la-4
All
ora
se v
ien
e as
seri
to il
fatt
o-a
pri
ma
del
fatt
o-b,
lare
gola
-3e
lare
gola
-4sa
ran
no
pos
te a
l di s
opra
del
lare
gola
-1e
del
lare
gola
-2n
ell�a
gen
da.
Per
òla
pos
izio
ne,
del
la r
egol
a-1
rela
tiva
alla
rego
la-2
ela
rego
la-3
rela
tiva
all
are
gola
-4sa
ràar
bitr
aria
.
Con
flic
t R
esol
uti
on:
Dep
th S
trat
egy
Con
flic
t R
esol
uti
on:
Dep
th S
trat
egy
Le
rego
le a
ttiv
ate
son
o p
osiz
ion
ate
ald
isot
to d
i tu
tte
lere
gole
con
lost
esso
sal
ien
ce.
ilfa
tto-
aat
tiva
la r
egol
a-1
ela
rego
la-2
ilfa
tto-
bat
tiva
la r
egol
a-3
ela
rego
la-4
All
ora
se v
ien
e as
seri
to il
fatt
o-a
pri
ma
del
fatt
o-b,
lare
gola
-1e
lare
gola
-2sa
ran
no
pos
te a
l di s
opra
del
lare
gola
-3e
del
lare
gola
-4n
ell�a
gen
da.
Per
òla
pos
izio
ne,
del
la r
egol
a-1
rela
tiva
alla
rego
la-2
ela
rego
la-3
rela
tiva
all
are
gola
-4sa
ràar
bitr
aria
.
Con
flic
t R
esol
.: B
read
th S
trat
egy
Con
flic
t R
esol
.: B
read
th S
trat
egy
Sim
pli
city
Str
ate
gy
Fra
tu
tte
lere
gole
con
lost
esso
sali
ence
,le
nu
ove
rego
leat
tiva
teso
no
pos
izio
nat
eal
di
sop
ra d
i tu
tte
le a
ttiv
azio
ni
di
rego
leco
n
mag
gior
eo
ugu
ale
spec
ific
ità
.L
asp
eci
fici
ty d
iu
n r
egol
aè
det
erm
inat
a d
al n
um
ero
di
con
fron
tid
a ef
fett
uar
en
ella
LH
Sd
ella
rego
la.
Co
mp
lex
ity
Str
ate
gy
Fra
tu
tte
lere
gole
con
ste
sso
sali
ence
, le
nu
ove
rego
leat
tiva
teso
no
pos
teal
di
sop
ra d
itu
tte
leat
tiva
zion
id
i re
gole
con
min
ore
o u
gual
esp
ecif
icit
à.
Con
flic
t R
es.:
Sim
plici
tyC
onfl
ict
Res
.: S
implici
ty-- C
omple
xity
Com
ple
xity
Fra
tu
tte
lere
gole
con
lost
esso
sali
ence
, le
nu
ove
rego
le a
ttiv
ate
son
o p
oste
uti
lizz
and
o la
str
ateg
ia O
PS5
. Ogn
i fat
to e
dog
ni
ista
nza
son
o et
ich
etta
ti c
on u
n �
tim
eta
g�p
er in
dic
are
quan
to
sian
o re
cen
tiri
spet
to a
gli a
ltri
fat
ti e
ista
nze
nel
sis
tem
a. I
p
atte
rn e
nti
ties
ass
ocia
ti a
d o
gni a
ttiv
azio
ne
dir
egol
a so
no
ord
inat
i in
mod
o d
ecre
scen
te p
er d
eter
min
are
la p
osiz
ion
e tr
a le
rego
le c
on lo
stes
so s
alie
nce
. Un
�att
ivaz
ion
e co
n u
np
iù r
ecen
tep
atte
rn e
nti
ties
è s
iste
mat
a p
rim
a d
i un
aat
tiva
zion
e co
n p
atte
rn
enti
ties
men
o re
cen
ti.
rule
-6:f
-1,f
-4ru
le-5
:f-1
,f-2
,f-3
,ru
le-1
:f-1
,f-2
,f-3
rule
-2:f
-3,f
-1ru
le-4
:f-1
,f-2
,ru
le-3
:f-2
,f-1
rule
-6:f
-4,f
-1ru
le-5
:f-3
,f-2
,f-1
,ru
le-1
:f-3
,f-2
,f-1
rule
-2:f
-3,f
-1ru
le-4
:f-2
,f-1
,ru
le-3
:f-2
,f-1
Con
flic
t R
esol
uti
on:
LEX S
trat
egy
Con
flic
t R
esol
uti
on:
LEX S
trat
egy
Fra
tu
tte
lere
gole
con
lost
esso
sali
ence
, le
nu
ove
rego
le a
ttiv
ate
son
o p
osiz
ion
ate
uti
lizz
and
ola
str
ateg
ia O
PS5
. Il p
rim
o �t
ime
tag�
del
pat
tern
en
tity
ass
ocia
to c
onil
pri
mo
pat
tern
èu
tili
zzat
op
er d
eter
min
are
dov
ein
seri
rel�a
ttiv
azio
ne.
Un
�att
ivaz
ion
e, il
cu
i p
rim
o �t
ime
tag�
del
pat
tern
è p
iùgr
and
e d
i alt
ri p
rim
i tag
del
leat
tiva
zion
i, è
inse
rita
pri
ma
del
leal
tre
atti
vazi
one
nel
l�age
nd
a.
Ese
mp
io: s
ei a
ttiv
azio
ni c
on l�
ord
inam
ento
ME
A(d
ove
la v
irgo
laal
la f
ine
del
l�att
ivaz
ion
e in
dic
a la
pre
sen
za d
i un
pat
tern
neg
ato)
rule
-2:f
-3,f
-1ru
le-3
:f-2
,f-1
rule
-6:f
-1,f
-4ru
le-5
:f-1
,f-2
,f-3
,ru
le-1
:f-1
,f-2
,f-3
rule
-4:f
-1,f
-2,Con
flic
t R
esol
uti
on:
MEA
Str
ateg
yC
onfl
ict
Res
oluti
on:
MEA
Str
ateg
y
Ad
ogn
i att
ivaz
ion
evi
ene
asse
gnat
ou
n n
um
ero
casu
ale
uti
lizz
ato
per
det
erm
inar
e la
su
a p
osiz
ion
eri
spet
toa
tutt
e qu
elle
con
lost
esso
sal
ien
ce.
Qu
esto
nu
mer
o ca
sual
evi
ene
rico
rdat
oqu
and
o vi
ene
cam
biat
a la
st
rate
gia
in m
odo
che
quan
do
vien
ese
lezi
onat
a d
inu
ovo
la
stra
tegi
a ra
nd
omvi
ene
rip
rod
otto
lost
esso
ord
inam
ento
.
Con
flic
t R
esol
ut.
: R
amdo
m S
trat
egy
Con
flic
t R
esol
ut.
: R
amdo
m S
trat
egy
La
LH
Sd
i un
a re
gola
CL
IPS
èco
stit
uit
a d
a u
na
seri
e d
i ele
men
tico
nd
izio
nal
i (C
Es)
ch
e d
evon
o es
sere
sod
dis
fatt
i aff
inch
éla
rego
la s
iap
osta
inag
end
a.
Tip
i di e
lem
enti
con
diz
ion
ali:
-p
att
ern
:con
ten
gon
ovi
nco
liu
tili
zzat
i per
det
erm
inar
e se
qual
che
pat
tern
enti
ties
(fac
ts o
r in
stan
ces)
sod
dis
fa il
pat
tern
.-t
est
:usa
to p
er v
alu
tare
esp
ress
ion
i-
an
d:u
nin
tero
gru
pp
od
i CE
sd
eve
esse
re s
odd
isfa
tto
-o
r: s
olo
un
ele
men
to d
i un
gru
pp
od
i CE
sd
eve
esse
re s
odd
isfa
tto
-no
t:u
n C
E n
on d
eve
esse
re s
odd
isfa
tto
-e
xis
ts: o
ccor
ren
za d
ialm
eno
un
mat
ch p
arzi
ale
-fo
rall
:un
insi
eme
diC
Es
è so
dd
isfa
tto
per
ogn
imat
ch p
arzi
ale
-lo
gic
al:
la c
reaz
ion
e d
ifat
ti e
ista
nze
su
lla
RH
S d
ipen
de
da
alcu
ne
con
diz
ion
i su
lla
LH
S
LHS
Sinta
ssi
LHS
Sinta
ssi
Sin
tass
i<
con
dit
ion
al-e
lem
ent>
::=
<p
atte
rn-C
E>
|<
assi
gned
-pat
tern
-CE
> |
<n
ot-C
E>
|<
and
-CE
>|
<or
-CE
>|
<lo
gica
l-C
E>
|<
test
-CE
>|
<ex
ists
-CE
> |
<fo
rall
-CE
>
LHS
Sinta
ssi
LHS
Sinta
ssi
I P
att
ern
co
nd
itio
na
le
lem
en
tsso
no
cost
itu
iti d
a u
na
coll
ezio
ne
di c
amp
i con
stra
ints
,wil
dca
rds,
eva
ria
bili
uti
lizz
ati
per
vin
cola
rel�i
nsi
eme
dei
fatt
i o is
tan
ze c
he
han
no
un
ma
tchi
ng
con
il p
atte
rn C
E.
I fi
eld
co
nst
rain
tsso
no
insi
emi d
i vin
coli
uti
lizz
ati p
erte
star
e u
nsi
ngo
lovi
nco
loo
slot
diu
np
atte
rn e
nti
ty. O
ltre
ai l
iter
alco
nst
rain
ts, i
lCL
IPS
forn
isce
altr
i tre
tip
i di v
inco
li: c
onn
ecti
ve
con
stra
ints
,pre
dic
ate
con
stra
ints
,ere
turn
valu
eco
nst
rain
ts.
I W
ild
card
sso
no
uti
lizz
ati n
ei p
atte
rn C
Es
per
ind
icar
ech
e u
n
sin
golo
cam
po
o gr
up
po
di c
amp
i pu
ò av
ere
un
ma
tchi
ng
con
qual
sias
icos
a.L
eV
ari
ab
ili
son
o u
tili
zzat
ep
er m
emor
izza
reil
valo
red
i un
ca
mp
o in
mod
o ch
e d
au
tili
zzar
lo s
ucc
essi
vam
ente
nel
la L
HS
di
un
a re
gola
, in
alt
riel
emen
ti c
ond
izio
nal
i,o
nel
laR
HS
diu
na
rego
la c
ome
argo
men
to d
i un
�azi
one.
Pat
tern
Con
diti
onal
Ele
men
tPat
tern
Con
diti
onal
Ele
men
t
Ilvi
nco
lop
iùel
emen
tare
(lit
era
l co
nst
rain
t) c
he
pu
ò es
sere
uti
lizz
ato
in u
n p
atte
rnC
E è
quel
lo c
he
def
inis
cep
reci
sam
ente
il
valo
re e
satt
od
a m
app
are
con
un
cam
po
Un
lit
era
l p
att
ern
CE
è c
osti
tuit
o d
a co
stan
ti (
floa
ts, i
nte
gers
, sy
mbo
ls,s
trin
gs, e
inst
ance
nam
es).
Non
con
tien
e va
riab
ili o
wil
dca
rds.
T
utt
i i v
inco
li in
un
lite
ral p
atte
rn d
evon
o av
ere
esat
tam
ente
un
mat
chin
gco
n t
utt
i i c
amp
i di u
n p
atte
rn e
nti
ty.
Un
ord
ered
pat
tern
CE
con
ten
ente
solo
lite
ral:
(<co
nst
ant-
1> ..
.<co
nst
ant-
n>
)
Un
def
tem
pla
tep
atte
rn C
Eco
nte
nen
te s
olo
lite
ral:
(<d
efte
mp
late
-nam
e>(<
slot
-nam
e-1>
<co
nst
ant-
1>)
... (<sl
ot-n
ame-
n>
<co
nst
ant-
n>
))
Lite
ralC
onst
rain
tLi
tera
lC
onst
rain
t
CL
IPS
ha
du
e si
mbo
li w
ild
card
che
pos
son
oes
sere
u
tili
zzat
i per
ilm
atc
hin
gn
ei c
amp
idiu
np
atte
rnsi
ng
le-f
ield
wil
dca
rd,d
enot
ato
dal
sim
bolo
�?�,
ma
pp
aog
niv
alor
e m
emor
izza
to in
esa
ttam
ente
un
cam
po
nel
pat
tern
enti
tym
ult
ifie
ld w
ild
card
,den
otat
o d
ai s
imbo
li �$
?�,m
ap
pa
ogn
i val
ore
in z
ero
op
iùca
mp
i in
un
pat
tern
en
tity
Wildc
ards
Sin
gle
eM
ult
ifie
ldW
ildc
ards
Sin
gle
eM
ult
ifie
ld
CLIPS>
(clear)
CLIPS>
(defrule
find-data
(data
?blue
red
$?)
=>)
CLIPS>
(reset)
CLIPS>
(agenda)
0find-data:
f-5
0find-data:
f-3
For
atotal
of
2activations.
CLIPS>
(facts)
f-0
(initial-fact)
f-1
(data
1.0
blue
"red")
f-2
(data
1blue)
f-3
(data
1blue
red)
f-4
(data
1blue
RED)
f-5
(data
1blue
red
6.9)
For
atotal
of
6facts.
CLIPS>
Wildc
ards
Sin
gle
eM
ult
ifie
ldW
ildc
ards
Sin
gle
eM
ult
ifie
ld
I M
ult
ifie
ld w
ild
card
e i
lite
ralc
onst
rain
ts p
osso
no
esse
reu
tili
zzat
i in
siem
e p
er f
orn
ire
del
lep
oten
ti c
apac
ità
di p
atte
rn-
mat
chin
g
(dat
a$
?Y
EL
LO
W$
?)
(dat
a Y
EL
LO
W b
lue
red
gree
n)
(dat
aY
EL
LO
Wre
d)
(dat
are
dY
EL
LO
W)
(dat
aY
EL
LO
W)
(dat
aY
EL
LO
W d
ata
YE
LL
OW
)
Wildc
ards
Sin
gle
eM
ult
ifie
ldW
ildc
ards
Sin
gle
eM
ult
ifie
ld
I si
mbo
li w
ild
card
rim
pia
zzan
o p
orzi
onid
i un
pat
tern
ed
acce
ttan
oog
niv
alor
e. I
lval
ore
di u
n c
amp
o es
sen
do
rim
pia
zzat
op
uò
esse
reca
ttu
rato
in u
na
va
ria
bil
e p
erco
nfr
onti
, vi
sual
izza
zion
i o a
ltre
man
ipol
azio
nis
ucc
essi
ve. Q
ues
tosi
otti
ene
face
nd
o se
guir
ed
iret
tam
ente
ilw
ild
card
dal
nom
ed
ella
vari
abil
e.
<co
nst
rain
t> ::
= <
con
stan
t> |
? |
$?
|<
sin
gle-
fiel
d-v
aria
ble>
| <
mu
ltif
ield
-var
iabl
e><
sin
gle-
fiel
d-v
aria
ble>
::=
?<va
riab
le-s
ymbo
l><
mu
ltif
ield
-var
iabl
e>::
=$
?<va
riab
le-s
ymbo
l>
Var
iabili Si
ngl
e e
Mult
ifie
ldV
aria
bili Si
ngl
e e
Mult
ifie
ld
CLIPS>
(clear)
CLIPS>
(reset)
CLIPS>
(assert
(data
2blue
green)
(data
1blue)
(data
1blue
red))
<Fact-3>
CLIPS>
(facts)
f-0
(initial-fact)
f-1
(data
2blue
green)
f-2
(data
1blue)
f-3
(data
1blue
red)
For
atotal
of
4facts.
CLIPS>
(defrule
find-data-1
(data
?x
?y
?z)
=>
(printout
t?x
":
"?y
":
"?z
crlf))
CLIPS>
(run)
1:
blue
:red
2:
blue
:green
CLIPS>
Var
iabili Si
ngl
e e
Mult
ifie
ldV
aria
bili Si
ngl
e e
Mult
ifie
ld
CLIPS>
(reset)
CLIPS>
(assert
(data
1blue)
(data
1blue
red)
(data
1blue
red
6.9))
<Fact-3>
CLIPS>
(facts)
f-0
(initial-fact)
f-1
(data
1blue)
f-2
(data
1blue
red)
f-3
(data
1blue
red
6.9)
For
atotal
of
4facts.
CLIPS>
(defrule
find-data-1
(data
?x
$?y
?z)
=>
(printout
t"?x
="
?x
crlf
"?y
="
?y
crlf
"?z
="
?z
crlf
"------"
crlf))
CLIPS>
(run)
Var
iabili Si
ngl
e e
Mult
ifie
ldV
aria
bili Si
ngl
e e
Mult
ifie
ld
?x
=1
?y
=(blue
red)
?z
=6.9
------
?x
=1
?y
=(blue)
?z
=red
------
?x
=1
?y
=()
?z
=blue
------
CLIPS>
Var
iabili Si
ngl
e e
Mult
ifie
ldV
aria
bili Si
ngl
e e
Mult
ifie
ld
CLIPS>(clear)
CLIPS>(deffactsdata(dataredgreen)(datapurpleblue)
(datapurplegreen) (data redbluegreen)
(datapurpleblue green) (data purplebluebrown))
CLIPS>(defrulefind-data-1 (datared ?x) (data purple ?x) =>)
CLIPS>(defrulefind-data-2 (datared $?x) (data purple$?x) =>)
CLIPS>(reset)
CLIPS>(facts)
f-0(initial-fact)
f-1 (data red green)
f-2(datapurpleblue)
f-3 (datapurplegreen)
f-4 (dataredbluegreen)
f-5 (datapurpleblue green)
f-6 (datapurpleblue brown)
Foratotal of7facts.
CLIPS>(agenda)
0find-data-2:f-4,f-5
0find-data-1:f-1,f-3
0find-data-2:f-1,f-3
Foratotal of 3activations.
CLIPS>
Var
iabili Si
ngl
e e
Mult
ifie
ldV
aria
bili Si
ngl
e e
Mult
ifie
ld
Son
o d
isp
onib
ili t
re c
on
ne
ctiv
eco
nst
rain
ts p
erco
lleg
are
sin
goli
vin
coli
e v
aria
bili
.-&
(an
d):
sod
dis
fatt
ose
idu
evi
nco
li a
dia
cen
tiso
no
sod
dis
fatt
i;-|
(o
r): s
odd
isfa
tto
seu
no
dei
du
e vi
nco
li a
dia
cen
tiè
sod
dis
fatt
o;
-~(n
ot)
: sod
dis
fatt
o se
il s
ucc
essi
vovi
nco
lo n
on s
ive
rifi
ca.
<term-1>&<term-2>
...
&<term-3>
<term-1>|<term-2>
...
|<term-3>
~<term>
<constraint>
::=
?|
$?
|<connected-constraint>
<connected-constraint>
::=
<single-constraint>
|<single-constraint>
&<connected-constraint>
|<single-constraint>
|<connected-constraint>
<single-constraint>
::=
<term>
|~<term>
<term>
::=
<constant>
|<single-field-variable>
|<multifield-variable>
Con
net
tivi
Con
net
tivi
CLIPS>(clear)
CLIPS>(deftemplatedata-B(slotvalue))
CLIPS>(deffacts AB (data-A green) (data-A blue)
(data-B(value red)) (data-B(valueblue)))
CLIPS>(defruleexample1-1 (data-A ~blue)=>)
CLIPS> (defrule example1-2 (data-B(value~red&~green))=>)
CLIPS> (defrule example1-3 (data-B(valuegreen|red))=>)
CLIPS>(reset)
CLIPS>(facts)
f-0(initial-fact)
f-1 (data-A green)
f-2(data-A blue)
f-3(data-B (valuered))
f-4 (data-B(valueblue))
For a total of 5 facts.
CLIPS>(agenda)
0example1-2: f-4
0example1-3: f-3
0example1-1: f-1
For atotalof3
activations.
CLIPS>
Con
net
tivi
Con
net
tivi
CLIPS>
(clear)
CLIPS>
(deftemplate
data-B
(slot
value))
CLIPS>
(deffacts
B(data-B
(value
red))
(data-B
(value
blue)))
CLIPS>
(defrule
example2-1
(data-B
(value
?x&~red&~green))
=>
(printout
t"?x
in
example2-1
="
?x
crlf))
CLIPS>
(defrule
example2-2
(data-B
(value
?x&green|red))
=>
(printout
t"?x
in
example2-2
="
?x
crlf))
CLIPS>
(reset)
CLIPS>
(run)
?x
in
example2-1
=blue
?x
in
example2-2
=red
CLIPS>
Con
net
tivi
Con
net
tivi
Avo
lte
èn
eces
sari
ovi
nco
lare
un
cam
po
inba
se a
lla
veri
tà d
i un
ad
ata
esp
ress
ion
ebo
olea
na.
U
n p
red
ica
teco
nst
rain
tp
erm
ette
che
un
ap
red
ica
tefu
nct
ion
(ch
eri
torn
a il
sim
bolo
FA
LS
E s
e n
on s
odd
isfa
tta
eil
sim
bolo
non
-FA
LSE
se
sod
dis
fatt
a)ve
nga
invo
cata
du
ran
te il
pro
cess
o d
i pat
tern
-mat
chin
g.T
ipic
amen
te, i
pre
dic
ate
con
stra
int
son
o u
tili
zzat
i in
co
ngi
un
zion
e co
nic
onn
ecti
ve c
onst
rain
te
un
ific
azio
ne
di
vari
abil
e(c
ioè
biso
gna
un
ific
are
la v
aria
bile
da
test
are
eco
nn
ette
rla
al p
red
icat
e co
nst
rain
t).
:<fu
nct
ion
-cal
l>
<te
rm>
::=
<co
nst
ant>
|<
sin
gle-
fiel
d-v
aria
ble>
|<
mu
ltif
ield
-var
iabl
e>|
:<fu
nct
ion
-cal
l>
Pre
dica
tiPre
dica
ti
CLIPS>
(clear)
CLIPS>
(defrule
example-1
(data
?x&:(numberp
?x))
=>)
CLIPS>
(assert
(data
1)
(data
2)
(data
red))
<Fact-2>
CLIPS>
(agenda)
0example-1:
f-1
0example-1:
f-0
For
atotal
of
2activations.
CLIPS>
Pre
dica
tiPre
dica
ti
CLIPS>
(clear)
CLIPS>
(defrule
example-4
(data
?y)
(data
?x&:(>
?x
?y))
=>)
CLIPS>
(assert
(data
3)
;f-0
(data
5)
;f-1
(data
9))
;f-2
<Fact-2>
CLIPS>
(agenda)
0example-4:
f-0,f-2
0example-4:
f-1,f-2
0example-4:
f-0,f-1
For
atotal
of
3activations.
CLIPS>
Pre
dica
tiPre
dica
ti
È p
ossi
bile
uti
lizz
are
ilva
lore
res
titu
ito
da
un
a fu
nzi
one
este
rna
per
vin
cola
reil
valo
red
iun
cam
po.
Il
retu
rn v
alu
e c
on
stra
int
(=)
per
met
te a
ll�u
ten
ted
ich
iam
are
un
a fu
nzi
one
este
rna
da
un
pat
tern
. Ilv
alor
e è
inco
rpor
ato
dir
etta
men
te n
el p
atte
rn n
ella
pos
izio
ne
in c
ui l
a fu
nzi
one
è st
ata
chia
mat
a, c
ome
se f
osse
sta
to u
nli
tera
lcon
stra
int,
ed
ogn
i m
atch
ing
pat
tern
s d
eve
ma
pp
are
ques
tova
lore
com
ese
lare
gola
fo
sse
stat
a sc
ritt
aco
n q
ues
tova
lore
. Si n
oti c
he
la fu
nzi
one
vien
eva
luta
ta o
gni v
olta
ch
evi
ene
con
trol
lato
il v
inco
lo.
=<function-call>
<term>
::=
<constant>
|<single-field-variable>
|<multifield-variable>
|:<function-call>
|=<function-call>
Val
ori di
rit
orno
Val
ori di
rit
orno
CLI
PS>
(cl
ear)
CLI
PS>
(deft
em
pla
tedata
(sl
ot
x)
(slo
t y))
CLI
PS>
(defr
ule
tw
ice (
data
(x ?
x)
(y =
(* 2
?x))
) =
>)
CLI
PS>
(ass
ert
(data
(x 2
) (y
4))
; f
-0(d
ata
(x 3
) (y
9))
) ;
f-1
<Fa
ct-1
>C
LIPS>
(agenda)
0twice:
f-0
For
atotal
of
1activation.
CLIPS>
Val
ori di
rit
orno
Val
ori di
rit
orno
CLIPS>
(clear)
CLIPS>
(defclass
DATA
(is-a
USER)
(role
concrete)
(pattern-match
reactive)
(slot
x(create-accessor
write)))
CLIPS>
(defrule
return-value-example-2
(object
(is-a
DATA)
(x
?x1))
(object
(is-a
DATA)
(x
?x2&=(+
5?x1)|=(-
12
?x1)))
=>)
CLIPS>
(make-instance
of
DATA
(x
4))
[gen1]
CLIPS>
(make-instance
of
DATA
(x
9))
[gen2]
CLIPS>
(make-instance
of
DATA
(x
3))
[gen3]
CLIPS>
(agenda)
0return-value-example-2:
[gen3],[gen2]
0return-value-example-2:
[gen2],[gen3]
0return-value-example-2:
[gen1],[gen2]
For
atotal
of
3activations.
CLIPS>
Val
ori di
rit
orno
Val
ori di
rit
orno
Alc
un
eaz
ion
i RH
S, c
ome
retr
act
eu
nm
ak
e-i
nst
an
ce,
oper
ano
su u
n in
tero
pat
tern
CE
. P
er in
dic
are
su q
ual
e fa
tto
o is
tan
za e
ssi a
gira
nn
o, p
uò
esse
reu
nif
icat
a u
na
vari
abil
e co
n i
fact
-ad
dre
sso
inst
an
ce-a
dd
ress
d
iun
pat
tern
CE
.
<assigned-pattern-CE>
::=
?<variable-symbol>
<-
<pattern-CE>
Indi
rizz
iIn
diri
zzi
(defrule
dummy
(data
1)
?fact
<-
(dummy
pattern)
=>(retract
?fact))
(defrule
compare-facts-1
?f1
<-
(color
~red)
?f2
<-
(color
~green)
(test
(neq
?f1
?f2))
=>(printout
t"Rule
fires
from
different
facts"
crlf))
(defrule
compare-facts-2
?f1
<-
(color
~red)
?f2
<-
(color
~green&:(neq
?f1
?f2))
=>(printout
t"Rule
fires
from
different
facts"
crlf))
Indi
rizz
iIn
diri
zzi
Un
a p
ossi
bili
tà a
ggiu
nti
va è
forn
ita
con
il t
est
con
dit
ion
al
ele
me
nt.
Ilte
st C
E è
sod
dis
fatt
o se
la c
hia
mat
a al
la
fun
zion
eco
n il
test
CE
èva
luta
ta n
on-F
AL
SEe
inso
dd
isfa
tta
se la
ch
iam
ata
alla
fun
zion
eè
valu
tata
FA
LSE
.
<test-CE>
::=
(test
<function-call>)
CLIPS>
(clear)
CLIPS>
(defrule
example-1
(data
?x)
(value
?y)
(test
(>=
(abs
(-
?y
?x))
3))
=>)
CLIPS>
(assert
(data
6)
(value
9))
<Fact-1>
CLIPS>
(agenda)
0example-1:
f-0,f-1
For
atotal
of
1activation.
CLIPS>
Tes
tT
est
IlC
Eo
rco
nse
nte
l�at
tiva
zion
e d
i un
a re
gola
da
un
od
ei C
E. S
eu
no
dei
CE
all�i
nte
rno
del
CE
or
è so
dd
isfa
tto,
all
ora
l�in
tero
CE
or
sarà
sod
dis
fatt
o. I
l CE
or
ha
lo s
tess
o ef
fett
o d
i scr
iver
e p
iùre
gole
con
LH
Se
RH
Ssi
mil
i.
<or-CE>
::=
(or
<conditional-element>+)
(defrule
system-fault
(error-status
unknown)
(or
(temp
high)
(valve
broken)
(pump
(status
off)))
=>
(printout
t"The
system
has
afault."
crlf))
Or
Or
IlC
LIP
S as
sum
ech
etu
tte
lere
gole
abbi
ano
un
an
dC
Eim
pli
cito
su t
utt
i i
con
dit
ion
alel
emen
tsd
ella
LH
S. Q
ues
tosi
gnif
ica
che
tutt
i i
con
dit
ion
alel
emen
tsn
ella
LH
Sd
evon
oes
sere
sod
dis
fatt
ip
erp
oter
att
ivar
ela
reg
ola.
IlC
LIP
Sfo
rnis
cean
che
un
an
dC
Ees
pli
cito
.
<and-CE>
::=
(and
<conditional-element>+)
(defrule
system-flow
(error-status
confirmed)
(or
(and
(temp
high)
(valve
closed))
(and
(temp
low)
(valve
open)))
=>
(printout
t"The
system
is
having
aflow
problem."
crlf))
And
And
Iln
ot
con
dit
ion
al
ele
me
nt
forn
isce
la p
ossi
bili
tà d
i ra
pp
rese
nta
re l�
asse
nza
di i
nfo
rmaz
ion
e. I
lno
tC
E è
sod
dis
fatt
oso
lo s
e il
con
dit
ion
al e
lem
ent
che
con
tien
e n
on è
sod
dis
fatt
o.
<n
ot-C
E>
::=
(not
<co
nd
itio
nal
-ele
men
t>)
Not
Not
(defrule
high-flow-rate
(temp
high)
(valve
open)
(not
(error-status
confirmed))
=>(printout
t"Recommend
closing
of
valve
due
to
high
temp�
crlf))
(defrule
check-valve
(check-status
?valve)
(not
(valve-broken
?valve))
=>
(printout
t"Device
"?valve
"is
OK"
crlf))
(defrule
double-pattern
(data
red)
(not
(data
red
?x
?x))
=>(printout
t"No
patterns
with
red
green
green!"
crlf
))
Not
Not
ex
ists
CE
forn
isce
u
n
mec
can
ism
o p
er
det
erm
inar
ese
un
gr
up
po
di
CE
èso
dd
isfa
tto
da
alm
eno
un
in
siem
ed
ip
atte
rnen
titi
es.
<ex
ists
-CE
>::
=(e
xist
s<
con
dit
ion
al-e
lem
ent>
+)
(def
rule
exam
ple
(exi
sts
(a?x
)(b
?x))
=>
)
èeq
uiv
alen
tea
(def
rule
exam
ple
(not
(not
(an
d(a
?x)
(b?x
))))
=>
)
Exis
tsEx
ists
fora
ll C
Efo
rnis
ce u
n m
ecca
nis
mo
per
det
erm
inar
e se
un
gr
up
po
di C
E è
sod
dis
fatt
o p
er o
gni o
ccor
ren
za d
i un
altr
o sp
ecif
icat
o C
E.
<fo
rall
-CE
> ::
=(f
oral
l <co
nd
itio
nal
-ele
men
t><
con
dit
ion
al-e
lem
ent>
+)
(def
rule
exa
mp
le(f
oral
l (a
?x)
(b ?
x) (
c ?x
))
=>
)
èeq
uiv
alen
tea
(def
rule
exa
mp
le(n
ot(a
nd
(a
?x)
(not
(an
d(b
?x)
(c ?
x)))
))=
>)
For
all
For
all
CLIPS>
(clear)
CLIPS>
(defrule
all-students-passed
(forall
(student
?name)
(reading
?name)
(writing
?name)
(arithmetic
?name))
=>
(printout
t"All
students
passed."
crlf))
CLIPS>
(reset)
CLIPS>
(agenda)
0all-students-passed:
f-0,
For
atotal
of
1activation.
CLIPS>
(assert
(student
Bob))
<Fact-1>
CLIPS>
(agenda)
CLIPS>
For
all
For
all
CLIPS>
(assert
(reading
Bob)
(writing
Bob))
<Fact-3>
CLIPS>
(agenda)
CLIPS>
CLIPS>
(assert
(arithmetic
Bob))
<Fact-4>
CLIPS>
(agenda)
0all-students-passed:
f-0,
For
atotal
of
1activation.
CLIPS>
CLIPS>
(assert
(student
John))
<Fact-5>
CLIPS>
(agenda)
CLIPS>
(retract
15)
CLIPS>
(agenda)
0all-students-passed:
f-0,
For
atotal
of
1activation.
CLIPS>
For
all
For
all
È p
ossi
bile
def
inir
e le
pro
pri
età
o le
cara
tter
isti
che
di u
na
rego
la.
Le
cara
tter
isti
che
son
o d
ich
iara
te n
ella
LH
S d
i un
reg
ola
uti
lizz
and
ola
par
ola
chia
ved
ecl
are
.In
un
are
gola
dev
ees
serc
iun
solo
com
and
od
ecl
are
ed
eve
app
arir
e p
rim
a d
i tu
tti i
CE
del
la L
HS
<declaration>
::=
(declare
<rule-property>+)
<rule-property>
::=
(salience
<integer-expression>)
|(auto-focus
<boolean-symbol>)
<boolean-symbol>
::=
TRUE
|FALSE
Pro
pri
età
delle
rego
lePro
pri
età
delle
rego
le
La
sali
en
ce p
erm
ette
di a
sseg
nar
eu
na
pri
orit
à ad
un
a re
gola
. Q
uan
do
ci s
ono
più
rego
le in
agen
da,
verr
à es
egu
ita
quel
laco
n
pri
orit
à p
iù a
lta.
Il
val
ore
del
sal
ien
ce d
eve
esse
reu
nin
tero
com
pre
sotr
a �
100
00
e
+10
00
0.
Se n
on s
pec
ific
ato,
il v
alor
e sa
lien
ce d
idef
ault
per
un
a re
gola
èze
ro.
(defrule
test-1
(declare
(salience
99))
(fire
test-1)
=>
(printout
t"Rule
test-1
firing."
crlf))
(defrule
test-2
(declare
(salience
(+
?*constraint-salience*
10)))
(fire
test-2)
=>
(printout
t"Rule
test-2
firing."
crlf))
Salien
ceSa
lien
ce
Ilco
stru
tto
de
fglo
ba
lp
erm
ette
la d
efin
izio
ne
el�a
cces
soa
vari
abil
i glo
bali
. È p
ossi
bile
acc
eder
e al
le v
aria
bili
glo
bali
in u
n
pro
cess
o d
ipat
tern
-mat
chin
g,m
a il
loro
cam
biam
ento
non
in
voca
il p
roce
sso
di p
atte
rn-m
atch
ing.
La
fun
zion
eb
ind
vien
eu
tili
zzat
a p
er s
etta
re il
loro
valo
re.
Il lo
ro v
alor
e or
igin
ale
vien
e ri
pri
stin
ato
uti
lizz
and
o il
com
and
ore
set
opp
ure
invo
can
do
la f
un
zion
eb
ind
sen
zava
lori
.
Pos
son
o es
sere
rim
osse
uti
lizz
and
o il
com
and
ocl
ea
ro
il
com
and
o u
nd
efg
lob
al.
(defglobal
[<defmodule-name>]
<global-assignment>*)
<global-assignment>
::=
<global-variable>
=<expression>
<global-variable>
::=
?*<symbol>*
Def
glob
alD
efgl
obal
L�u
sod
elle
vari
abil
igl
obal
iè
per
mes
soov
un
que
(com
ep
er l
eva
riab
ili l
ocal
i), m
a co
n d
ue
ecce
zion
i:
1. N
on p
osso
no
esse
reu
tili
zzat
eco
me
par
amet
ri i
n d
effu
nct
ion
,d
efm
eth
od, o
mes
sage
-han
dle
r;
2.N
on p
osso
no
esse
reu
tili
zzat
en
ello
stes
som
odo
incu
iso
no
usa
tele
var
iabi
lilo
cali
nel
la L
HS
di
un
are
gola
per
leg
are
un
va
lore
.
Reg
ola
ille
ga
le(d
efru
le e
xam
ple
(fac
t ?*
x*)
=>
)
Reg
ola
leg
ale
(def
rule
exam
ple
(fac
t?y
&:(
> ?
y?*
x*))
=>
)
Def
glob
alD
efgl
obal
(defrule
example
(fact
?y&:(>
?y
?*x*))
=>)
Qu
esta
reg
ola
non
vie
ne
mod
ific
ata
quan
do
cam
bia
ilva
lore
di
?*x*
.
Per
esem
pio
,se
?*x*
è4
evi
ene
aggi
un
toil
fatt
o (f
act
3), a
llor
ala
rego
lan
on è
sod
dis
fatt
a.
Se s
i cam
bia
il v
alor
ed
i?*x
* a
2,la
reg
ola
non
sarà
att
ivat
a.
(defglobal
?*x*
=3
?*y*
=?*x*
?*z*
=(+
?*x*
?*y*)
?*q*
=(create$
ab
c))
Def
glob
alD
efgl
obal
Ilco
stru
tto
de
ffu
nct
ion
per
met
tela
def
iniz
ion
ed
i nu
ove
fun
zion
i dir
etta
men
te in
CL
IPS.
Le
def
fun
ctio
ns
son
o eq
uiv
alen
tial
leal
tre
fun
zion
i,l�u
nic
a d
iffe
ren
zaè
che
led
effu
nct
ion
sso
no
scri
tte
inC
LIP
S ed
inte
rpre
tate
, men
tre
le f
un
zion
i est
ern
e so
no
scri
tte
in u
n li
ngu
aggi
o es
tern
o (c
ome
il C
)ed
eseg
uit
ed
iret
tam
ente
dal
CL
IPS.
Le
def
fun
ctio
ns
per
met
to l�
aggi
un
ta d
i n
uov
efu
nzi
oni s
enza
ric
omp
ilar
e il
CL
IPS.
(deffunction
<name>
[<comment>]
(<regular-parameter>*
[<wildcard-parameter>])
<action>*)
<regular-parameter>
::=
<single-field-variable>
<wildcard-parameter>
::=
<multifield-variable>
Un
a d
effu
nct
ion
dev
eav
ere
un
un
ico
nom
e, n
ones
iste
l�ove
rloa
din
g, e
dev
ees
sere
dic
hia
rata
pri
ma
die
sser
e u
sata
, ad
ec
cezi
onid
elle
def
fun
ctio
ns
rico
rsiv
e.
Def
funct
ion
Def
funct
ion
CLIPS>
(clear)
CLIPS>
(deffunction
print-args
(?a
?b
$?c)
(printout
t?a
""
?b
"and
"(length
?c)
"extras:
"?c
crlf))
CLIPS>
(print-args
12)
12
and
0extras:
()
CLIPS>
(print-args
ab
cd)
ab
and
2extras:
(c
d)
CLIPS>
Qu
and
o u
na
def
fun
ctio
n v
ien
ein
voca
ta, l
esu
eaz
ion
ison
oes
egu
ite
nel
l�ord
ine.
Il v
alor
e re
stit
uit
o d
a u
na
def
fun
ctio
n è
lava
luta
zion
ed
ell�u
ltim
aaz
ion
e.
Se u
na
def
fun
ctio
n n
on h
a az
ion
i ess
a re
stit
uis
ce il
sim
bolo
F
AL
SE.
Sesi
ver
ific
au
n e
rror
etu
tte
le a
zion
i non
anco
ra e
segu
ite
verr
ann
o ab
orti
te, e
ver
ràre
stit
uit
o il
sim
bolo
FA
LSE
.
Def
funct
ion
Def
funct
ion
(deffunction
factorial
(?a)
(if
(or
(not
(integerp
?a))
(<
?a
0))
then
(printout
t"Factorial
Error!"
crlf)
else
(if
(=
?a
0)
then
1else
(*
?a
(factorial
(-
?a
1))))))
La
rico
rsio
ne
mu
tua
fra
du
ed
effu
nct
ion
s ri
chie
de
un
a d
ich
iara
zion
efo
rwar
d:u
nd
ich
iara
zion
ese
nza
azi
oni.
(deffunction
foo
())
(deffunction
bar
()
(foo))
(deffunction
foo
()
(bar))
Def
funct
ion
Def
funct
ion
CL
IPS
sup
por
talo
svi
lup
po
el�e
secu
zion
e m
odu
lare
del
laco
nos
cen
za.
I m
odu
li C
LIP
S, c
reat
i con
il c
ostr
utt
od
efm
od
ule
, per
met
ton
oil
ragg
rup
pam
ento
di u
n in
siem
e d
i cos
tru
tti i
n m
odo
da
con
trol
lare
esp
lici
tam
ente
l�ac
cess
o ai
cos
tru
tti d
a al
tri m
odu
li.
Qu
esto
tip
o d
i con
trol
lo è
sim
ile
allo
scop
egl
obal
ee
loca
leu
tili
zzat
o in
lin
guag
gico
me
il C
o A
da.
Res
trin
gen
do
l�acc
esso
aic
ostr
utt
idef
tem
pla
te e
def
clas
s, i
mod
uli
pos
son
o fu
nzi
onar
eco
me
bla
ckbo
ard
s, p
erm
ette
nd
o so
loa
cert
i fat
ti e
a c
erte
ista
nze
di e
sser
e vi
sibi
li in
alt
ri m
odu
li.
I m
odu
li s
ono
usa
ti a
nch
e d
a re
gole
per
for
nir
e il
con
trol
lod
ell�e
secu
zion
e.
I mod
uli
I mod
uli
(defmodule
<module-name>
[<comment>]
<port-spec>*)
<port-spec>
::=
(export
<port-item>)
|(import
<module-name>
<port-item>)
<port-item>
::=
?ALL
|?NONE
|<port-construct>
?ALL
|<port-construct>
?NONE
|<port-construct>
<construct-name>+
<port-construct>
::=
deftemplate
|defclass
|defglobal
|deffunction
|defgeneric
I mod
uli
I mod
uli
(defmodule
FOO
(import
BAR
?ALL)
(import
YAK
deftemplate
?ALL)
(import
GOZ
defglobal
xy
z)
(export
defgeneric
+)
(export
defclass
?ALL))
(defrule
DETECTION::Find-Fault
(sensor
(name
?name)
(value
bad))
=>
(assert
(fault
(name
?name))))
(defglobal
DETECTION
?*count*
=0)
(defmessage-handler
DETECTION::COMPONENT
get-charge
()
(*
?self:flux
?self:flow))
(defmethod
DETECTION::+
((?x
STRING)
(?y
STRING))
(str-cat
?x
?y))
I mod
uli
I mod
uli
Def
init
o il
mod
ulo
è p
ossi
bile
spec
ific
are
i cos
tru
tti c
he
ne
fara
nn
op
arte
. I
cost
rutt
i def
fact
s,d
efte
mp
late
,def
rule
,def
fun
ctio
n,d
efge
ner
ic,
def
clas
s, e
def
inst
ance
s sp
ecif
ican
oil
mod
ulo
in c
ui s
aran
no
pre
sen
tico
me
par
te d
el n
ome.
Ilm
odu
lo d
elco
stru
tto
def
glob
alè
ind
icat
o sp
ecif
ican
do
il n
ome
del
mod
ulo
dop
o la
par
ola
chia
ve d
efgl
obal
.Il
mod
ulo
diu
nd
efm
eth
odè
spec
ific
ato
com
ep
arte
del
lo s
pec
ific
ator
ed
igen
eric
fun
ctio
n.
(defruleDETECTION::Find-Fault
(sensor (name ?name)(valuebad))
=>(assert (fault (name ?name))))
(defglobal DETECTION?*count*=0)
(defmessage-handlerDETECTION::COMPONENTget-charge()
(*?self:flux?self:flow))
(defmethodDETECTION::+ ((?xSTRING)(?y STRING))
(str-cat?x ?y))
I mod
uli
I mod
uli
CLIPS>
(clear)
CLIPS>
(defmodule
A)
CLIPS>
(defmodule
B)
CLIPS>
(defrule
foo
=>)
CLIPS>
(defrule
A::bar
=>)
CLIPS>
(list-defrules)
bar
For
atotal
of
1defrule.
CLIPS>
(set-current-module
B)
A CLIPS>
(list-defrules)
foo
For
atotal
of
1defrule.
CLIPS>
I mod
uli
I mod
uli
I co
man
di u
nd
efr
ule
ep
pd
efr
ule
rich
ied
ono
il n
ome
del
cost
rutt
o su
l qu
ale
oper
are.
C
on i
mod
uli
è p
ossi
bile
aver
e co
stru
ttic
on lo
ste
sso
nom
e m
ain
mod
uli
div
ersi
. M
od
ule
sp
eci
fie
r:è
la s
pec
ific
aes
pli
cita
del
mod
ulo
di u
n
nom
e(u
n s
ymbo
l), m
odu
le-n
ame:
:.P
er e
sem
pio
MA
IN::
fin
d-s
tuff
, in
dic
a ch
eil
cos
tru
tto
fin
d-
stu
ff è
nel
mod
ulo
MA
IN (
ilm
odu
lost
and
ard
del
CL
IPS)
. U
n m
odu
lo p
uò
anch
e es
sere
sp
ecif
icat
o im
pli
cita
men
te
poi
ché
esis
te s
emp
re u
n m
odu
lo �
corr
ente
�.
Il m
odu
lo c
orre
nte
vie
ne
cam
biat
o og
ni v
olta
ch
esi
uti
lizz
a il
cost
rutt
o d
efm
odu
le o
pp
ure
lafu
nzi
one
set-
curr
en
t-m
od
ule
I mod
uli
I mod
uli
CLIPS>
(clear)
CLIPS>
(defmodule
A)
CLIPS>
(defglobal
A?*x*
=0)
CLIPS>
(defmodule
B)
CLIPS>
(defglobal
B?*y*
=1)
CLIPS>
(ppdefglobal
y)
(defglobal
B?*y*
=1)
CLIPS>
(ppdefglobal
B::y)
(defglobal
B?*y*
=1)
CLIPS>
(ppdefglobal
x)
[PRNTUTIL1]
Unable
to
find
defglobal
xCLIPS>
(ppdefglobal
A::x)
(defglobal
A?*x*
=0)
CLIPS>
I mod
uli
I mod
uli
In g
ener
ale
ico
stru
tti
di
un
mod
ulo
non
pos
son
o es
sere
uti
lizz
ati
da
un
altr
om
odu
lo.U
nco
stru
tto
sid
ice
visi
bile
in
un
mod
ulo
seil
cost
rutt
o p
uò
esse
reu
tili
zzat
oin
quel
mod
ulo
. Q
uin
di,
sep
er
esem
pio
, ilm
odu
loB
vuol
eu
tili
zzar
eil
def
tem
pla
tefo
o d
efin
ito
nel
m
odu
loA
,all
ora
ilm
odu
loA
dev
ees
por
tare
ild
efte
mp
late
foo
eil
mod
ulo
Blo
dev
eim
por
tare
.
CLIPS>(clear)
CLIPS>(defmoduleA)
CLIPS> (deftemplate A::foo (slot x))
CLIPS>(defmoduleB)
CLIPS>(defrule B::bar (foo(x 3))=>)
[PRNTUTIL2] SyntaxError:Checkappropriate syntax for defrule
ERROR:
(defruleB::bar
(foo(
CLIPS>(clear)
CLIPS>(defmoduleA (exportdeftemplatefoo))
CLIPS> (deftemplate A::foo (slot x))
CLIPS>(defmoduleB (importAdeftemplatefoo))
CLIPS>(defrule B::bar (foo(x 3))=>)
CLIPS>
I mod
uli
I mod
uli
Ex
po
rt s
pe
cifi
cati
on
s
Un
mod
ulo
pu
ò es
por
tare
tutt
ii s
uoi
cos
tru
tti v
isib
ili:
exp
ort?
AL
LU
n m
odu
lop
uò
esp
orta
re t
utt
i i s
uoi
cos
tru
ttiv
isib
ili d
iun
tip
o p
arti
cola
re:e
xpor
t n
ame-
of-t
he-
con
stru
ct?A
LL
Un
mod
ulo
pu
òes
por
tare
sp
ecif
ici c
ostr
utt
i vis
ibil
i:ex
por
t n
ame-
of-t
he-
con
stru
ct-t
ype
nam
e-of
-on
e-or
-mor
e-vi
sibl
e-co
nst
ruct
s-of
-th
e-sp
ecif
ied
-typ
e
(def
mod
ule
A (
exp
ort
?AL
L))
(def
mod
ule
B (
exp
ort
def
tem
pla
te ?
AL
L))
(def
mod
ule
C (
exp
ort
def
glob
alfo
oba
rya
k))
I mod
uli
I mod
uli
Imp
ort
Sp
eci
fica
tio
n
Un
mod
ulo
pu
ò im
por
tare
tu
tti i
cost
rutt
i vis
ibil
idiu
n a
ltro
mod
ulo
:im
por
tm
odu
le-n
ame?
AL
LU
n m
odu
lo p
uò
imp
orta
re t
utt
i ico
stru
ttiv
isib
ili d
i un
tip
op
arti
cola
red
au
nal
tro
mod
ulo
:im
por
tm
odu
le-n
ame
nam
e-of
-th
e-co
nst
ruct
-ty
pe?
AL
LU
n m
odu
lo p
uò
imp
orta
re s
pec
ific
i cos
tru
tti v
isib
ilid
i un
altr
om
odu
lo:
imp
ort
mod
ule
-nam
en
ame-
of-t
he-
con
stru
ct-t
ype
nam
e-of
-on
e-or
-mor
e-vi
sibl
e-co
nst
ruct
s-of
-th
e-sp
ecif
ied
-typ
e
(def
mod
ule
A (
imp
ort
D?A
LL
))(d
efm
odu
le B
(im
por
t D
def
tem
pla
te ?
AL
L))
(def
mod
ule
C (
imp
ort
D d
efgl
obal
foo
bar
yak)
)
I mod
uli
I mod
uli
I fa
tti e
le is
tan
zea
pp
art
eng
ono
ai m
odu
li in
cu
i son
o d
efin
itii
corr
isp
ond
enti
def
tem
pla
tee
def
clas
s(e
non
aim
odu
lich
e li
crea
no)
.I
fatt
i ele
ista
nze
son
ovi
sibi
lin
ei m
odu
li c
he
imp
orta
no
i co
rris
pon
den
ti d
efte
mp
late
o d
efcl
ass.
Qu
esto
per
met
te u
na
base
di c
onos
cen
za p
arti
zion
ata
in m
odo
che
lere
gole
egl
ialt
rico
stru
tti p
osso
no
ved
ere
solo
le is
tan
ze e
i fat
ticu
i son
oin
tere
ssat
i. Si
not
i ch
e il
def
tem
pla
tein
itia
l-fa
ct d
eve
esse
rees
pli
cita
men
teim
por
tato
dal
mod
ulo
MA
IN
I mod
uli
I mod
uli
CLIPS>
(clear)
CLIPS>
(defmodule
A(export
deftemplate
foo
bar))
CLIPS>
(deftemplate
A::foo
(slot
x))
CLIPS>
(deftemplate
A::bar
(slot
y))
CLIPS>
(deffacts
A::info
(foo
(x
3))
(bar
(y
4)))
CLIPS>
(defmodule
B(import
Adeftemplate
foo))
CLIPS>
(reset)
CLIPS>
(facts
A)
f-1
(foo
(x
3))
f-2
(bar
(y
4))
For
atotal
of
2facts.
CLIPS>
(facts
B)
f-1
(foo
(x
3))
For
atotal
of
1fact.
CLIPS>
I mod
uli
I mod
uli
Ogn
i mod
ulo
ha
lasu
ap
rop
ria
rete
di p
atte
rn-m
atch
ing
per
lesu
ere
gole
ed
un
a su
a p
rop
ria
agen
da.
Qu
and
o vi
en d
ato
il c
oman
do
run
, vie
ne
eseg
uit
a l�a
gen
da
del
mod
ulo
att
ivo.
L�e
secu
zion
ed
elle
rego
leco
nti
nu
afi
nch
én
ond
iven
ta a
ttiv
o u
n a
ltro
mod
ulo
, non
ci s
ono
altr
ere
gole
nel
l�age
nd
a, o
pp
ure
vie
ne
eseg
uit
a la
fun
zion
ere
turn
da
un
aR
HS
diu
na
rego
la.
Qu
and
o u
n m
odu
lo a
ttiv
o te
rmin
a l�e
secu
zion
e d
elle
reg
ole
in
agen
da,
il c
urr
ent
focu
s vi
ene
rim
osso
dal
focu
sst
ack
ed
iven
taat
tivo
ilsu
cces
sivo
mod
ulo
sulf
ocu
sst
ack.
Pri
ma
che
un
a re
gola
ven
ga e
segu
ita,
ilm
odu
loco
rren
ted
iven
taqu
ello
in c
ui l
a re
gola
èd
efin
ita.
Il
curr
ent
focu
sp
uò
esse
red
efin
ito
uti
lizz
and
oil
com
and
ofo
cus.
I mod
uli
I mod
uli
CLIPS>(clear)
CLIPS>(defmoduleMAIN(export?ALL))
CLIPS>
(defruleMAIN::focus-example
=>(printout t "Firingrulein moduleMAIN."crlf)
(focusAB))
CLIPS>(defmodule A(import MAINdeftemplate
initial-fact))
CLIPS>(defruleA::example-rule
=>(printout t "Firingrule in module A." crlf))
CLIPS>(defmodule B(import MAINdeftemplate
initial-fact))
CLIPS>(defruleB::example-rule
=>(printout t "Firingrule in module B." crlf))
CLIPS>(reset)
CLIPS>(run)
Firingrulein moduleMAIN.
Firingrule inmoduleA.
Firingrule inmoduleB.
CLIPS>
I mod
uli
I mod
uli
I co
nst
rain
t at
trib
ute
s,as
soci
ati a
i cos
tru
tti d
efte
mp
late
s e
def
clas
ses,
per
met
ton
o d
i ver
ific
are
la v
alid
ità
dei
tip
i dei
val
ori
deg
li s
lot
quan
do
ven
gon
ocr
eati
tem
pla
te f
acts
e is
tan
ze.
Ven
gon
o an
che
uti
lizz
atin
ei p
atte
rn d
ella
LH
Sd
iun
are
gola
per
det
erm
inar
e l�a
ttiv
azio
ne
del
la r
egol
a.
Esi
ston
od
ue
tip
i di c
onst
rain
t ch
ecki
ng:
stat
ic e
dyn
amic
(s
et-
sta
tic-
con
stra
int-
che
ckin
ge
set-
dyn
am
ic-
con
stra
int-
che
ckin
g).
<constraint-attribute>
::=
<type-attribute>!|
<allowed-constant-attribute>
|<range-attribute>
|<cardinality-attribute>
Att
ribu
tiA
ttri
buti
<type-attribute>
::=
(type
<type-specification>)
<type-specification>
::=
<allowed-type>+
|?VARIABLE
<allowed-type>
:=
SYMBOL
|STRING
|LEXEME
|INTEGER
|FLOAT
|NUMBER
|INSTANCE-NAME
|INSTANCE-ADDRESS
|INSTANCE
|EXTERNAL-ADDRESS
|FACT-ADDRESS
Att
ribu
tiA
ttri
buti
all
ow
ed
co
nst
an
t a
ttri
bu
tes
per
met
ton
o d
i sp
ecif
icar
e le
co
stan
ti d
i un
o sp
ecif
ico
tip
o ch
eè
pos
sibi
le a
ssoc
iare
al v
alor
e d
iu
no
slot
.a
llo
we
d-v
alu
es
att
rib
ute
per
met
ted
isp
ecif
icar
eu
n in
siem
ed
ival
oric
he
è p
ossi
bile
ass
ocia
re a
d u
no
slot
.
(allowed-symbols
red
green
blue)
(allowed-values
red
green
blue)
Att
ribu
tiA
ttri
buti
<allowed-constant-attribute>
::=
(allowed-symbols!<symbol-list>)
|(allowed-strings
<string-list>)
|(allowed-lexemes
<lexeme-list>
|(allowed-integers!<integer-list>)
|(allowed-floats!<float-list>)
|(allowed-numbers!<number-list>)
|(allowed-instance-names
<instance-list>)
|(allowed-values!<value-list>)
<symbol-list>
::=
<symbol>+
|?VARIABLE
<string-list>
::=
<string>+
|?VARIABLE
<lexeme-list>
::=
<lexeme>+
|?VARIABLE
<integer-list>
::=
<integer>+
|?VARIABLE
<float-list>
::=
<float>+
|?VARIABLE
<number-list>
::=
<number>+
|?VARIABLE
<instance-name-list>
::=
<instance-name>+
|?VARIABLE
<value-list>
::=
<constant>+
|?VARIABLE
Att
ribu
tiA
ttri
buti
ran
ge
att
rib
ute
: in
terv
allo
nu
mer
ico
per
iva
lori
diu
no
slot
(qu
and
o p
er lo
slo
t u
tili
zzia
mo
valo
ri n
um
eric
i)
<range-attribute>
::=
(range
<range-specification>
<range-specification>)
<range-specification>
::=
<number>
|?VARIABLE
card
ina
lity
att
rib
ute
: res
trin
ge il
nu
mer
o d
i cam
pid
i un
m
ult
ifie
ldsl
ot.
<cardinality-attribute>
::=
(cardinality
<cardinality-specification>
<cardinality-specification>
<cardinality-specification>
::=
<integer>
|?VARIABLE
Att
ribu
tiA
ttri
buti
De
fau
ltv
alu
es
1) I
lti
po
di
de
fau
ltp
er
losl
ot
è s
celt
o d
all
a l
ista
de
i ti
pi:
SY
MB
OL
, S
TR
ING
, IN
TE
GE
R,
FL
OA
T,
INS
TA
NC
E-N
A M
E ,
I N
S T
A N
C E
-A
D D
R E
S
S ,
F A
C T
-A
DD
RE
SS
, E
XT
ER
NA
L-A
DD
RE
SS
.2
) S
eil
tip
o d
i d
efa
ult
ha
un
a a
llo
we
d c
on
sta
nt
rest
rict
ion
, a
llo
ra v
ien
esc
elt
o c
om
e d
efa
ult
il
pri
mo
va
lore
sp
eci
fica
to n
ell
oa
llo
we
dco
nst
an
ta
ttri
bu
te3
) S
e i
lv
alo
red
i d
efa
ult
no
n è
sta
to s
pe
cifi
cato
al
pa
sso
2 e
il
tip
o d
i d
efa
ult
è I
NT
EG
ER
o F
LO
AT
ed
è
sp
eci
fica
toil
ra
ng
e a
ttri
bu
te,
all
ora
vie
ne
u
tili
zza
toco
me
va
lore
di
de
fau
lt i
l m
inim
ova
lore
d
ell
�in
terv
all
o s
e n
on
è ?
VA
RIA
BL
E,
alt
rim
en
tiil
m
ass
imo
se
no
n è
?VA
RIA
BL
E.
Att
ribu
tiA
ttri
buti
4)Se
ilva
lore
did
efau
ltn
on è
stat
o sp
ecif
icat
o n
éal
pas
so2
né
al
pas
so 3
, all
ora
vien
e u
tili
zzat
oil
valo
red
i def
ault
def
au
lt. E
sso
assu
me
valo
ren
ilp
er il
tip
oSY
MB
OL
, ""
per
ilti
po
STR
ING
, 0p
er il
tip
o IN
TE
GE
R, 0
.0 p
er il
tip
o F
LO
AT
, [n
il]
per
il t
ipo
INST
AN
CE
-NA
ME
, un
pu
nta
tore
ad
un
a is
tan
za f
itti
zia
per
ilti
po
INST
AN
CE
-AD
DR
ESS
, un
pu
nta
tore
ad
un
fat
to fi
ttiz
iop
er il
tip
oF
AC
T-A
DD
RE
SS, e
il p
un
tato
re N
UL
L p
er il
tip
o E
XT
ER
NA
L-A
DD
RE
SS.
5)Se
ilva
lore
did
efau
ltd
a d
eriv
are
èp
er u
n s
ingl
e fi
eld
slo
t,al
lora
vien
eu
sato
ilva
lore
der
ivat
o d
ai p
assi
1 a
4. I
l val
ore
di
def
ault
per
un
mu
ltif
ield
slo
t è
un
mu
ltif
ield
valu
ed
ilu
ngh
ezza
zero
. Se
ilm
ult
ifie
ldsl
oth
au
na
card
inal
ità
min
ima
mag
gior
e d
i ze
ro,a
llor
avi
ene
crea
tou
nm
ult
ifie
ld v
alu
e co
n u
na
lun
ghez
zad
ella
min
ima
card
inal
ità.
Att
ribu
tiA
ttri
buti
CLIPS>
(deftemplate
bar
(slot
a(type
SYMBOL
INTEGER))
(slot
b(type
INTEGER
FLOAT))
(slot
c(type
SYMBOL
STRING)))
CLIPS>
(defrule
error
(bar
(a
?x))
(bar
(b
?x))
(bar
(c
?x))
=>)
[RULECSTR1]
Variable
?x
in
CE
#3
slot
chas
constraint
conflicts
which
make
the
pattern
unmatchable
ERROR:
(defrule
error-4
(bar
(a
?x))
(bar
(b
?x))
(bar
(c
?x))
=>)
Att
ribu
tiA
ttri
buti
CLIPS>
(deftemplate
foo
(multislot
x(cardinality
?VARIABLE
3)))
CLIPS>
(deftemplate
bar
(multislot
y(cardinality
?VARIABLE
2)))
CLIPS>
(deftemplate
woz
(multislot
z(cardinality
7?VARIABLE)))
CLIPS>
(defrule
error
(foo
(x
$?x))
(bar
(y
$?y))
(woz
(z
$?x
$?y))
=>)
[CSTRNCHK1]
The
group
of
restrictions
found
in
CE
#3
do
not
satisfy
the
cardinality
restrictions
for
slot
z
ERROR:
(defrule
error
(foo
(x
$?x))
(bar
(y
$?y))
(woz
(z
$?x
$?y))
=>)
Att
ribu
tiA
ttri
buti
CLIPS>
(deftemplate
foo
(slot
x(type
SYMBOL)))
CLIPS>
(defrule
Error
(foo
(x
?x))
(test
(>
?x
10))
=>)
[RULECSTR2]
Previous
variable
bindings
of
?x
caused
the
type
restrictions
for
argument
#1
of
the
expression
(>
?x
10)
found
in
CE
#2
to
be
violated
ERROR:
(defrule
error
(foo
(x
?x))
(test
(>
?x
10))
=>)
CLIPS>
Att
ribu
tiA
ttri
buti
Pre
dic
ate
Fu
nct
ion
s(numberp
<expression>)
Testing
for
numbers
(floatp
<expression>)
Testing
for
floats
(integerp
<expression>)
Testing
for
Integers
(lexemep
<expression>)
Testing
for
Strings
or
Symbols
(stringp
<expression>)
Testing
for
Strings
(symbolp
<expression>)
Testing
for
Symbols
(evenp
<integer-expression>)
Testing
for
Even
Numbers
(oddp
<integer-expression>)
Testing
for
Odd
Numbers
(multifieldp
<expression>)
Testing
for
Multifield
Values
(pointerp
<expression>)
Testing
for
External-Address
(eq
<expression>
<expression>+)
Comparing
for
Equality
(neq
<expression>
<expression>+)
Comparing
for
Inequality
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Co
mp
ari
ng
Nu
mb
ers
fo
r E
qu
ali
tya
nd
In
eq
ua
lity
(=
<numeric-expression>
<numeric-expression>+)
(<>
<numeric-expression>
<numeric-expression>+)
(>
<numeric-expression>
<numeric-expression>+)
(>=
<numeric-expression>
<numeric-expression>+)
(<
<numeric-expression>
<numeric-expression>+)
(<=
<numeric-expression>
<numeric-expression>+)
Bo
ole
an
(and
<expression>+)
(or
<expression>+)
(not
<expression>)
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Mu
ltif
ield
Fu
nct
ion
sC
rea
tin
g(create$
<expression>*)
CLIPS>
(create$
hammer
drill
saw
screw
pliers
wrench)
(hammer
drill
saw
screw
pliers
wrench)
CLIPS>
(create$
(+
34)
(*
23)
(/
84))
(7
62)
Sp
ecif
yin
g(nth$
<integer-expression>
<multifield-expression>)
Fin
din
g(member$
<expression>
<multifield-expression>)
Co
mp
ari
ng
(subsetp
<multifield-expression>
<multifield-expression>)
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Del
etio
n o
f fi
eld
s in
am
ult
ifie
ld(delete$
<multifield-expression>
<begin-integer-expression>
<end-integer-expression>)
CLIPS>(delete$ (create$ hammerdrillsawplierswrench)34)
(hammerdrillwrench)
CLIPS>(delete$ (create$ computerprinterhard-disk)1 1)
(printer hard-disk)
Cre
ati
ng
Mu
ltif
ield
Va
lues
fro
mS
trin
gs.
(explode$
<string-expression>)
CLIPS>(explode$"hammerdrillsawscrew")
(hammer drill saw screw)
CLIPS>(explode$"1 2abc34 \"abc\" \"def\"")
(12abc 3 4 "abc""def")
CLIPS>(explode$ "?x~)")
("?x" "~" ")")
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Cre
ati
ng
Str
ing
s fr
om
Mu
ltif
ield
Va
lues
(implode$
<multifield-expression>)
CLIPS>(implode$ (create$hammerdrillscrewdriver))
"hammer drill screwdriverwrenchplierssaw�
CLIPS>(implode$(create$
1 "abc" def "ghi"2))
"1"abc"def"ghi"2�
CLIPS>(implode$(create$ "abc def ghi"))
""abc def ghi"�
Ex
tra
ctin
ga
Su
b-s
equ
ence
fro
m a
Mu
ltif
ield
Va
lue
(subseq$
<multifield-value>
<begin-integer-expression>
<end-integer-expression>)
CLIPS>(subseq$ (create$ hammerdrillwrenchpliers) 34)
(wrench pliers)
CLIPS>(subseq$(create$
1 "abc" def "ghi"2)1 1)
(1)
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Rep
laci
ng
Fie
lds
wit
hin
aM
ult
ifie
ldV
alu
e(replace$
<multifield-expression>
<begin-integer-expression>
<end-integer-expression>
<single-or-multi-field-expression>+)
CLIPS>(replace$ (create$ drill wrench pliers) 3 3 machete)
(drillwrenchmachete)
CLIPS>(replace$(create$ abcd)23x y (create$ qrs))
(axyqrsd)
CLIPS>
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Inse
rtin
g F
ield
s w
ith
in a
Mu
ltif
ield
Va
lue
(insert$
<multifield-expression>
<integer-expression>
<single-or-multi-field-expression>+)
CLIPS>
(insert$
(create$
ab
cd)
1x)
(x
ab
cd)
CLIPS>
(insert$
(create$
ab
cd)
4y
z)
(a
bc
yz
d)
CLIPS>
(insert$
(create$
ab
cd)
5(create$
qr))
(a
bc
dq
r)
CLIPS>
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Get
tin
gth
eF
irst
Fie
ld f
rom
aM
ult
ifie
ldV
alu
e
CLIPS>
(first$
(create$
ab
c))
(a)
CLIPS>
(first$
(create$))
()
CLIPS>
Get
tin
gA
llb
ut
the
Fir
st F
ield
fro
m a
Mu
ltif
ield
Va
lue
CLIPS>
(rest$
(create$
ab
c))
(b
c)
CLIPS>
(rest$
(create$))
()
CLIPS>
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Det
erm
inin
gth
e N
um
ber
of
Fie
lds
in a
Mu
ltif
ield
Va
lue
CLIPS> (length$ (create$ abc d e fg))
7 CLIPS>
Del
etin
gS
pec
ific
Va
lues
wit
hin
a M
ult
ifie
ld V
alu
eCLIPS>(delete-member$
(create$aba c)ba)
(c)
CLIPS>(delete-member$(create$a b cc b a)(create$ ba))
(abcc)
CLIPS>
Rep
laci
ng
Sp
ecif
ic V
alu
es w
ith
in a
Mu
ltif
ield
Va
lue
CLIPS>(replace-member$(create$ a b ab)(create$a b a) a b)
(abaabaabaa ba)
CLIPS>(replace-member$(create$ ab ab)(create$ ab a)
(create$ab))
(abaaba)
CLIPS>
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Str
ing
Fu
nct
ion
s(str-cat
<expression>*)
(sym-cat
<expression>*)
(sub-string
<integer-expression>
<integer-expression>
<string-expression>)
(str-index
<lexeme-expression>
<lexeme-expression>)
(eval
<string-or-symbol-expression>)
(build
<string-or-symbol-expression>)
(upcase
<string-or-symbol-expression>)
(lowcase
<string-or-symbol-expression>)
(str-compare
<string-or-symbol-expression>
<string-or-symbol-expression>)
(str-length
<string-or-symbol-expression>)
(check-syntax
<construct-or-function-string>)
(string-to-field
<string-or-symbol-expression>)
Azi
oni e
funzi
oni
Azi
oni e
funzi
oni
Log
ical
Nam
es: s
tdin
, std
out,
wcl
ips,
wd
ialo
g, w
dis
pla
y,w
erro
r, w
war
nin
g, w
trac
e.
Com
mon
I/O
Fu
nct
ion
s: o
pen
, clo
se,p
rin
tou
t, r
ead
, rea
dli
ne,
fo
rmat
,ren
ame,
rem
ove
(open
<file-name>
<logical-name>
[<mode>])
(close
[<logical-name>])
(printout
<logical-name>
<expression>*)
(read
[<logical-name>])
(readline
[<logical-name>])
(format
<logical-name>
<string-expression>
<expression>*)
(rename
<old-file-name>
<new-file-name>)
(remove
<file-name>)
CLI
PS
I/O
CLI
PS
I/O
Ad
dit
ion
:(+
<n
um
eric
-exp
ress
ion
><
nu
mer
ic-e
xpre
ssio
n>
+)
Subt
ract
ion
:(-
<n
um
eric
-exp
ress
ion
><
nu
mer
ic-e
xpre
ssio
n>
+)
Mu
ltip
lica
tion
:(*
<n
um
eric
-exp
ress
ion
><
nu
mer
ic-e
xpre
ssio
n>
+)
Div
isio
n:
(/<
nu
mer
ic-e
xpre
ssio
n>
<n
um
eric
-exp
ress
ion
>+
)
Inte
ger
Div
isio
n:
(div
<n
um
eric
-exp
ress
ion
><
nu
mer
ic-e
xpre
ssio
n>
+)
Max
imu
man
d M
inim
um
Nu
mer
icV
alu
e:(m
ax<
nu
mer
ic-e
xpre
ssio
n>
+)
(min
<n
um
eric
-exp
ress
ion
>+
)
Funzi
oni m
atem
atic
he
Funzi
oni m
atem
atic
he
(abs
<numeric-expression>)
(float
<numeric-expression>)
(integer
<numeric-expression>)
acos
(arccosine),
acosh
(hyperbolic
arccosine),
acot
(arccotangent),
acoth
(hyperbolic
arccotangent),
acsc
(arccosecant),
acsch
(hyperbolic
arccosecant),
asec
(arcsecant),
asech
(hyperbolic
arcsecant),
asin
(arcsine),
asinh
(hyperbolic
arcsine),
atan
(arctangent),
atanh
(hyperbolic
arctangent),
cos
(cosine),
cosh
(hyperbolic
cosine),
cot
(cotangent),
coth
(hyperbolic
tangent),
csc
(cosecant),
csch
(hyperbolic
cosecant),
sec
(secant),
sech
(hyperbolic
secant),
sin
(sine),
sinh
(hyperbolic
sine),
tan
(tangent),
tanh
(hyperbolic
tangent).
(deg-grad
<numeric-expression>),
(deg-rad
<numeric-
expression>),
(grad-deg
<numeric-expression>),
(rad-deg
<numeric-
expression>),
(pi)
Funzi
oni m
atem
atic
he
Funzi
oni m
atem
atic
he
(sqrt
<numeric-expression>)
(**
<numeric-expression>
<numeric-expression>)
(exp
<numeric-expression>)
(log
<numeric-expression>)
(log10
<numeric-expression>)
(round
<numeric-expression>)
(mod
<numeric-expression>
<numeric-expression>)
Funzi
oni m
atem
atic
he
Funzi
oni m
atem
atic
he
Bin
din
g V
aria
bles
(bind
<variable>
<expression>*)
CLIPS> (defglobal?*x* = 3.4)
CLIPS>?*x*
3.4
CLIPS>(bind ?*x* (+ 8 9))
17CLIPS>?*x*
17CLIPS> (bind?*x* (create$ a bcd))
(abcd)
CLIPS>?*x*
(abcd)
CLIPS>(bind?*x* d e f)
(de f)
CLIPS>?*x*
(de f)
CLIPS>(bind?*x*)
3.4
CLIPS>?*x*
3.4
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
If�
then
�el
se(if
<expression>
then
<action>*
[else
<action>*])
(defrule
closed-valves
(temp
high)
(valve
?v
closed)
=>(if
(=
?v
6)
then
(printout
t"The
special
valve
"?v
"is
closed!"
crlf)
(assert
(perform
special
operation))
else
(printout
t"Valve
"?v
"is
normally
closed"
crlf)))
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
Wh
ile
(while
<expression>
[do]
<action>*)
(defrule
open-valves
(valves-open-through
?v)
=>
(while
(>
?v
0)
(printout
t"Valve
"?v
"is
open"
crlf)
(bind
?v
(-
?v
1))))
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
Loo
p-f
or-c
oun
t(loop-for-count
<range-spec>
[do]
<action>*)
<range-spec>
::=
<end-index>
|(<loop-variable>
<start-index>
<end-index>)
|(<loop-variable>
<end-index>)
<start-index>
::=
<integer-expression>
<end-index>
::=
<integer-expression>
CLIPS>(loop-for-count2(printout t "Hello world" crlf))
Hello World
Hello world
FALSE
CLIPS>
(loop-for-count (?cnt1 2 4) do
(loop-for-count (?cnt2 1 3) do
(printout t ?cnt1 " " ?cnt2 crlf)))
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
21
22
23
31
32
33
41
42
43
FALSE
CLIPS>
(progn
<expression>*)
CLIPS>
(progn
(setgen
5)
(gensym))
gen5
CLIPS>
(progn$
<list-spec>
<expression>*)
<list-spec>
::=
<multifield-expression>
|(<list-variable>
<multifield-expression>)
CLIPS>
(progn$
(?field
(create$
abc
def
ghi))
(printout
t"-->
"?field
""
?field-index
"<--"
crlf))
-->
abc
1<--
-->
def
2<--
-->
ghi
3<--
CLIPS>
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
(return
[<expression>])
CLIPS>
(deffunction
sign
(?num)
(if
(>
?num
0)
then
(return
1))
(if
(<
?num
0)
then
(return
-1))
0)
CLIPS>
(sign
5)
1 CLIPS>
(sign
-10)
-1
CLIPS>
(sign
0)
0 CLIPS>
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
(break)
CLIPS>
(deffunction
iterate
(?num)
(bind
?i
0)
(while
TRUE
do
(if
(>=
?i
?num)
then
(break))
(printout
t?i
"")
(bind
?i
(+
?i
1)))
(printout
tcrlf))
CLIPS>
(iterate
1)
0 CLIPS>
(iterate
10)
01
23
45
67
89
CLIPS>
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali
(switch
<test-expression>
<case-statement>*
[<default-statement>])
<case-statement>
::=
(case
<comparison-expression>
then
<action>*)
<default-statement>
::=
(default
<action>*)
CLIPS>
(defglobal
?*x*
=0)
CLIPS>
(defglobal
?*y*
=1)
CLIPS>
(deffunction
foo
(?val)
(switch
?val
(case
?*x*
then
*x*)
(case
?*y*
then
*y*)
(default
none)))
CLIPS>
(foo
0)
*x*
CLIPS>
(foo
1)
*y*
CLIPS>
(foo
2)
none
CLIPS>
Funzi
oni Pro
cedu
rali
Funzi
oni Pro
cedu
rali