In ISO-Prolog there are no types, and some ISO-prolog terms are not typeable in Visual Prolog and will subsequently not be valid, and hence not exist.
Let us first consider your test data, it contains sub-terms like this:
In ISO-Prolog such terms just exists and you have have whatever name/string you like. In Visual Prolog you will have to decide whether 'bonjour' is one of the values a fixed predefined/enumerated set of values. If it is then you can define the domain like this:
Code: Select all
domains
word =
bonjour;
le;
monde;
salut:
ca;
va;
test.
Such a domain will defines the
exact set of values that can be used.
My guess is that such enumeration types is not what you have in mind here, and in that case you will have to use strings instead in Visual Prolog:
In your test data all the inw-terms have that form
inw(<string>, <string>, <string>), and that would correspond to a domain like this:
Code: Select all
domains
inw = inw(string Word, string X, string Y).
OK, that was the "simple" difference between ISO and Visual Prologs terms.
The more difficult one is that in ISO-Prolog any term is allowed anywhere, so you can call a predicate with an inw-term or a list of something, or a string or a number or whatever you like. And you can also write clauses to take care of any of these cases.
But in Visual Prolog a term/type is either an inw-term/inw-type or a list term/list type. You cannot mix inw-terms and list terms like that.
Your test data is valid in Visual Prolog, but it has type inv*** (list-of list-of list-of inw):
Code: Select all
constants
test : inw*** =
[
[
[inw("bonjour", "b", "c"), inw("le", "d", "e"), inw("monde", "f", "g")],
[inw("salut", "h", "i"), inw("ca", "d", "d"), inw("va", "v", "v")],
[inw("test", "c", "c")]
],
[
[inw("bonjour", "b", "c"), inw("le", "d", "e"), inw("monde", "f", "g")],
[inw("salut", "h", "i"), inw("ca", "d", "d"), inw("va", "v", "v")],
[inw("test", "c", "c")]
]
].
But this term (which is valid in ISO-Prolog) does not exist in Visual Prolog:
Code: Select all
constants
illegal : ??? =
[
[
[inw("bonjour", "b", "c"), inw("le", "d", "e"), inw("monde", "f", "g")],
[inw("salut", "h", "i"), inw("ca", "d", "d"), inw("va", "v", "v")],
[inw("test", "c", "c")]
],
[inw("bonjour", "b", "c"), inw("le", "d", "e"), inw("monde", "f", "g")],
[inw("salut", "h", "i"), inw("ca", "d", "d"), inw("va", "v", "v")],
[inw("test", "c", "c")]
].
Some parts have three levels of list but other parts are only two levels and that not legal in Visual Prolog all elements in a list must have same type (and different levels of list makes different type).
Your clauses deals with (assumes) an arbitrary level of lists, and that is where problem with giving the clauses a type comes from.
I am not really sure whether you want arbuitraty levels of lists of if you actually have a more "rigid" list struct in mind like in these domains:
Code: Select all
domains
chapter = paragrap*.
paragraph = sentence*.
sentence = inw*.
inw= inw(string Word, string X, string Y).
But assuming that you want arbitrary levels of lists in a proper solution to your entire problem could be like this:
Code: Select all
implement main
domains
inw = inw(string A, string B, string C).
domains
nestList{Type} =
one(Type);
list(nestList{Type}* List).
constants
test : nestList{inw} =
list(
[
list(
[
list([one(inw("bonjour", "b", "c")), one(inw("le", "d", "e")), one(inw("monde", "f", "g"))]),
list([one(inw("salut", "h", "i")), one(inw("ca", "d", "d")), one(inw("va", "v", "v"))]),
list([one(inw("test", "c", "c"))])
]),
list(
[
list([one(inw("bonjour", "b", "c")), one(inw("le", "d", "e")), one(inw("monde", "f", "g"))]),
list([one(inw("salut", "h", "i")), one(inw("ca", "d", "d")), one(inw("va", "v", "v"))]),
list([one(inw("test", "c", "c"))])
])
]).
class predicates
getInwWords : (nestList{inw} Inw) -> nestList{string} WordList.
clauses
getInwWords(one(inw(Word, _, _))) = one(Word).
getInwWords(list(List)) = list(getInwWords_list(List)).
class predicates
getInwWords_list : (nestList{inw}* InwList) -> nestList{string}* WordList.
clauses
getInwWords_list([]) = [].
getInwWords_list([H | T]) = [getInwWords(H) | getInwWords_list(T)].
clauses
run() :-
Words = getInwWords(test),
stdio::writef("Words = %\n", Words).
end implement main
goal
console::runUtf8(main::run).
The way I have dealth with arbitraty list level is to have a functor domain (nestList) which is:
- either one element or
- a list of a such nestList "things"
I have made the domain polymorphic (parameterized over the
Type of the elements), that way it can be used both for the:
- nestList{inw} the input of the predicate and
- nestList{string} the output of the predicate
I have also split the predicate in two and turned it into a
function (which has no pendant in ISO-Prolog).
This is probably a big mouthful so don't hesitate to ask more.