<s>
B-Prolog	B-Language
was	O
a	O
high-performance	O
implementation	O
of	O
the	O
standard	O
Prolog	B-Language
language	I-Language
with	O
several	O
extended	O
features	O
including	O
matching	O
clauses	O
,	O
action	O
rules	O
for	O
event	O
handling	O
,	O
finite-domain	O
constraint	O
solving	O
,	O
arrays	O
and	O
hash	O
tables	O
,	O
declarative	O
loops	O
,	O
and	O
tabling	O
.	O
</s>
<s>
First	O
released	O
in	O
1994	O
,	O
B-Prolog	B-Language
is	O
now	O
a	O
widely	O
used	O
CLP	B-Application
system	O
.	O
</s>
<s>
The	O
constraint	O
solver	O
of	O
B-Prolog	B-Language
was	O
ranked	O
top	O
in	O
two	O
categories	O
in	O
the	O
Second	O
International	O
Solvers	O
Competition	O
,	O
and	O
it	O
also	O
took	O
the	O
second	O
place	O
in	O
P	O
class	O
in	O
the	O
second	O
ASP	O
solver	O
competition	O
and	O
the	O
second	O
place	O
overall	O
in	O
the	O
third	O
ASP	O
solver	O
competition	O
.	O
</s>
<s>
B-Prolog	B-Language
underpins	O
the	O
PRISM	O
system	O
,	O
a	O
logic-based	O
probabilistic	O
reasoning	O
and	O
learning	O
system	O
.	O
</s>
<s>
B-Prolog	B-Language
is	O
a	O
commercial	O
product	O
,	O
but	O
it	O
can	O
be	O
used	O
for	O
learning	O
and	O
non-profit	O
research	O
purposes	O
free	O
of	O
charge	O
(	O
since	O
version	O
7.8	O
for	O
individual	O
users	O
,	O
including	O
commercial	O
individual	O
users	O
,	O
B-Prolog	B-Language
is	O
free	O
of	O
charge	O
)	O
.	O
</s>
<s>
B-Prolog	B-Language
is	O
not	O
anymore	O
actively	O
developed	O
,	O
but	O
it	O
forms	O
the	O
basis	O
for	O
the	O
Picat	O
programming	O
language	O
.	O
</s>
<s>
The	O
compilation	O
of	O
matching	O
clauses	O
is	O
much	O
simpler	O
than	O
that	O
of	O
normal	O
Prolog	B-Language
clauses	O
because	O
no	O
complex	O
program	O
analysis	O
or	O
specialization	O
is	O
necessary	O
;	O
and	O
the	O
generated	O
code	O
tends	O
to	O
be	O
more	O
compact	O
and	O
faster	O
.	O
</s>
<s>
The	O
B-Prolog	B-Language
compiler	O
and	O
most	O
of	O
the	O
library	O
predicates	O
are	O
written	O
in	O
matching	O
clauses	O
.	O
</s>
<s>
To	O
overcome	O
this	O
,	O
B-Prolog	B-Language
provides	O
a	O
simple	O
and	O
yet	O
powerful	O
language	O
,	O
called	O
Action	O
Rules	O
(	O
AR	O
)	O
,	O
for	O
programming	O
agents	O
.	O
</s>
<s>
Agents	O
are	O
a	O
more	O
general	O
notion	O
than	O
delay	O
constructs	O
in	O
early	O
Prolog	B-Language
systems	O
and	O
processes	O
in	O
concurrent	O
logic	O
programming	O
languages	O
in	O
the	O
sense	O
that	O
agents	O
can	O
be	O
responsive	O
to	O
various	O
kinds	O
of	O
events	O
including	O
instantiation	O
,	O
domain	O
,	O
time	O
,	O
and	O
user-defined	O
events	O
.	O
</s>
<s>
A	O
user-defined	O
event	O
takes	O
the	O
form	O
of	O
event(X,O )	O
where	O
X	O
is	O
a	O
variable	O
,	O
called	O
a	O
suspension	O
variable	O
,	O
that	O
connects	O
the	O
event	O
with	O
its	O
handling	O
agents	O
,	O
and	O
O	O
is	O
a	O
Prolog	B-Language
term	O
that	O
contains	O
the	O
information	O
to	O
be	O
transmitted	O
to	O
the	O
agents	O
.	O
</s>
<s>
It	O
has	O
served	O
as	O
an	O
intermediate	O
language	O
for	O
compiling	O
Constraint	B-Application
Handling	I-Application
Rules	I-Application
(	O
CHR	O
)	O
and	O
Answer	B-Application
Set	I-Application
Programs	I-Application
(	O
ASP	O
)	O
.	O
</s>
<s>
Like	O
many	O
Prolog-based	O
finite-domain	O
constraint	O
solvers	O
,	O
B-Prolog	B-Language
'	O
s	O
finite-domain	O
solver	O
was	O
heavily	O
influenced	O
by	O
the	O
CHIP	B-Application
system	O
.	O
</s>
<s>
The	O
first	O
fully-fledged	O
solver	O
was	O
released	O
with	O
B-Prolog	B-Language
version	O
2.1	O
in	O
March	O
1997	O
.	O
</s>
<s>
Thanks	O
to	O
the	O
employment	O
of	O
AR	O
as	O
the	O
implementation	O
language	O
,	O
the	O
constraint	O
solving	O
part	O
of	O
B-Prolog	B-Language
is	O
relatively	O
small	O
(	O
3800	O
lines	O
of	O
Prolog	B-Language
code	O
and	O
6000	O
lines	O
of	O
C	O
code	O
,	O
including	O
comments	O
and	O
spaces	O
)	O
but	O
its	O
performance	O
is	O
very	O
competitive	O
.	O
</s>
<s>
In	O
B-Prolog	B-Language
,	O
the	O
maximum	O
arity	O
of	O
a	O
structure	O
is	O
65535	O
.	O
</s>
<s>
To	O
facilitate	O
creating	O
arrays	O
,	O
B-Prolog	B-Language
provides	O
a	O
built-in	O
,	O
called	O
new_array(X,Dims )	O
,	O
where	O
X	O
must	O
be	O
an	O
uninstantiated	O
variable	O
and	O
Dims	O
a	O
list	O
of	O
positive	O
integers	O
that	O
specifies	O
the	O
dimensions	O
of	O
the	O
array	O
.	O
</s>
<s>
To	O
facilitate	O
accessing	O
array	O
elements	O
,	O
B-Prolog	B-Language
supports	O
the	O
array	O
subscript	O
notation	O
X[I1,...,In],	O
where	O
X	O
is	O
a	O
structure	O
and	O
each	O
Ii	O
is	O
an	O
integer	O
expression	O
.	O
</s>
<s>
This	O
common	O
notation	O
for	O
accessing	O
arrays	O
is	O
,	O
however	O
,	O
not	O
part	O
of	O
the	O
standard	O
Prolog	B-Language
syntax	O
.	O
</s>
<s>
Prolog	B-Language
relies	O
on	O
recursion	O
to	O
describe	O
loops	O
.	O
</s>
<s>
The	O
lack	O
of	O
powerful	O
loop	O
constructs	O
has	O
arguably	O
made	O
Prolog	B-Language
less	O
acceptable	O
to	O
beginners	O
and	O
less	O
productive	O
to	O
experienced	O
programmers	O
because	O
it	O
is	O
often	O
tedious	O
to	O
define	O
small	O
auxiliary	O
recursive	O
predicates	O
for	O
loops	O
.	O
</s>
<s>
The	O
emergence	O
of	O
constraint	O
programming	O
constructs	O
such	O
as	O
CLP(FD )	O
has	O
further	O
revealed	O
this	O
weakness	O
of	O
Prolog	B-Language
as	O
a	O
modeling	O
language	O
.	O
</s>
<s>
B-Prolog	B-Language
provides	O
a	O
built-in	O
,	O
called	O
foreach	O
,	O
for	O
iterating	O
over	O
collections	O
and	O
the	O
list	B-Language
comprehension	I-Language
notation	O
for	O
constructing	O
lists	O
.	O
</s>
<s>
Recurrences	O
have	O
to	O
be	O
read	O
procedurally	O
and	O
thus	O
do	O
not	O
fit	O
well	O
with	O
Prolog	B-Language
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
we	O
adopt	O
the	O
list	B-Language
comprehension	I-Language
notation	O
from	O
functional	O
languages	O
.	O
</s>
<s>
A	O
list	B-Language
comprehension	I-Language
is	O
a	O
list	O
whose	O
first	O
element	O
has	O
the	O
functor	O
'	O
:	O
'	O
.	O
</s>
<s>
A	O
list	O
of	O
this	O
form	O
is	O
interpreted	O
as	O
a	O
list	B-Language
comprehension	I-Language
in	O
calls	O
to	O
@	O
=	O
/2	O
and	O
arithmetic	O
constraints	O
.	O
</s>
<s>
A	O
list	B-Language
comprehension	I-Language
is	O
treated	O
as	O
a	O
foreach	O
call	O
with	O
an	O
accumulator	O
in	O
the	O
implementation	O
.	O
</s>
<s>
Calls	O
to	O
foreach	O
and	O
list	B-Language
comprehensions	I-Language
are	O
translated	O
into	O
tail-recursive	O
predicates	O
.	O
</s>
<s>
The	O
loop	O
constructs	O
considerably	O
enhance	O
the	O
modeling	O
power	O
of	O
CLP(FD )	O
.	O
</s>
<s>
The	O
following	O
gives	O
a	O
program	O
for	O
the	O
N-queens	O
problem	O
in	O
B-Prolog	B-Language
:	O
</s>
<s>
B-Prolog	B-Language
implements	O
a	O
tabling	O
mechanism	O
,	O
called	O
linear	O
tabling	O
,	O
which	O
is	O
based	O
on	O
iterative	O
computation	O
of	O
looping	O
subgoals	O
rather	O
than	O
suspension	O
of	O
them	O
to	O
compute	O
the	O
fixed	O
points	O
.	O
</s>
<s>
The	O
PRISM	O
system	O
,	O
which	O
heavily	O
relies	O
on	O
tabling	O
,	O
has	O
been	O
the	O
main	O
driving	O
force	O
for	O
the	O
design	O
and	O
implementation	O
of	O
B-Prolog	B-Language
'	O
s	O
tabling	O
system	O
.	O
</s>
<s>
In	O
B-Prolog	B-Language
,	O
as	O
in	O
XSB	O
,	O
tabled	O
predicates	O
are	O
declared	O
explicitly	O
by	O
declarations	O
in	O
the	O
following	O
form	O
:	O
</s>
<s>
B-Prolog	B-Language
supports	O
table	O
modes	O
,	O
which	O
allow	O
the	O
system	O
to	O
use	O
only	O
input	O
arguments	O
in	O
variant	O
checking	O
and	O
table	O
answers	O
selectively	O
.	O
</s>
