I am new to prolog programming and have been told in a tutorial to define a list of structures (in a script) so that I can query it as a database. However I find it impossible to define this list as a variable in a script. When I define a list such as
X=[a,b,c].
I just receive an error saying
No permission to modify static_procedure `(=)/2'
Does prolog not support defining variables such as this? I am using SWI-Prolog under linux.
In Prolog we speak of logical variables, to mean identity between literals.
That is, a program it’s a set of rules that collectively state what’s true about our literals, and that literals are uninterpreted. We write rules using variables to describe relations about individuals, and while trying to prove if our query can become true, Prolog binds variables as rules dictate.
A list it’s just syntax sugar for a binary relation between a term (the head) and (note the recursion here) a list. Usually, when we speak of a database, we use facts (rules without a body, always true) that binds atomic literals.
So that tutorial probably expresses the task in different words than you report, or it’s somewhat misleading. You could anyway store lists in your database as such:
and write your program like:
Then you can query your program like:
and Prolog, trying to prove myprog/1, attempt to prove mylist/1 and member/2…
To prove mylist(L) the variable L get bound to [a,b,c].
HTH