I am reading a tutorial and I find it hard to understand how to recurse a single list. Could someone give me a quick explanation of what the base case must be and why, and also what to do in the recursion. My code is:
type(string).
type(int).
instance(X,Y):- X, Y.
variable(_).
statement([]).
statement(A|B):- A, statement(B).
Purpose of the code is to make a light type checker to check things like this:
String s; int i; i = s.length();
I am passing this as a test:
statement([instance(type(string), variable(s))]).
I decided to put it in a list and recurse it and then just put it after the if. If it matches one of the rules, it’ll be true. Currently I am just making sure I can get the type instantiation to work. Any help would be welcome! Thanks in advance.
You are missing a pair of square brackets in
It should be
The rest of your recursive rule looks fine.