![]() ![]() ![]() |
![]() |
This compiler supports all the features of the standard (or will support them soon) but also gives many possibilities which you have not with another Prolog compiler. Our philosophy was to give you maximal freedom and let you do as you like best. There is another philosophy, which says that if one's hands are tied, mistakes will be fewer. We do not share this thesis, and made an extension of the language which allow many constructions which other Prolog compilers would understand as syntax errors.
Here are the differences:
In the Standard, you can write a list using square brackets '[' and
']'. For example:
[] - the empty
list.
[a, b, c]
- list of elements a, b, c
.
[X|Y] - list
with head X and
tail Y .
[a, b | T]
- list beginning with elements a,
b and tail T
.
In Strawberry Prolog you can write every of the above lists. You can
write even a list like:
[ | T] - list
beginning with nothing, its tail being T
, same as T .
Of course, this is an absolutely useless extension.
In the Standard you can write a functor with arguments like this:
f( a, b, c)
.
In Strawberry Prolog you have a functor and a list of arguments. This
means that you can type between (
and ) everything
you can type between [
and ] . For example:
f() -
f
with an empty list of arguments.
f( a, b | T)
- f with its argument
list beginning with elements a,
b and tail T
.
f( | T) -
f with T
as its argument list.
The place of the functor can be occupied by a variable too:
X( a) - functor
X (variable) with
argument a .
X( | Y) -
functor
X (variable)
with list of arguments Y
(variable).
This makes extremely easy to define the operator =..
in Strawberry Prolog. Here is the definition:
X(|Y)=..[X|Y].
Remark: You must have no space between the functor and the ( . This is so both here and in the Standard.
In Strawberry Prolog we have a somewhat strange internal representation
of atoms. For example:
abc is equivalent
to [a, b | c]
.
This raises the problem that you can create a list like [a,
b | c] , and to be surprised at its being printed as
abc . Nevertheless
it is rather unlikely to happen. The advantage of this is that you can
use patterns like:
[a, _ | c]
- which will be unifiable with every atom of three characters, the first
one being a ,
and last one c
.
[_ | bc] -
which will be unifiable with every atom of three characters that ends with
bc .
[a, b | _]
- which will be unifiable with every atom of three or more characters that
starts with ab
.
Unfortunately, you can not write a pattern that is unifiable with all the atoms with some given end.
As an example, try running the program:
?- X=c, write( [a,b|X]).
Change X=c
with X=[c] , X=f(c)
and X=cd .