Predicate declaration for using recursion on lists of objects with custom type
Posted: 2 May 2021 8:45
Hello,
I am beginning with Visual Prolog and encountering an issue with a predicate declaration. My predicate should be used in order to extract string values within custom objects 'inw', which are contained in a list of lists of lists, but I also want to keep the lists of lists structure. I tested this predicate using SWI Prolog :
Used like this:
There it works as intended, however in Visual Prolog, the issue is that I cannot declare the input to be either inw* or inw*** or just inw, I always get an error looking like :
error c504 : The expression has type 'database::inw', which is incompatible with the type 'database::inw*'
(with inw* as declared input type)
or
error c504 : The expression has type 'A', which is incompatible with the type 'database::inw'
(when I use A* as input type)
This is likely due to the third clause, where I use H1 as input (and it is not legal to Vprolog). I tried creating a custom domain but I am still not comfortable with that and it did not work.
(error c504 : The expression has type 'A$*', which is incompatible with the type 'database::inw_cpnd')
Is there any simple way to solve this problem ? Should I quit using this kind of recursion ? Is there a correct way to declare the domain that I should use ?
Thanks,
Paul
I am beginning with Visual Prolog and encountering an issue with a predicate declaration. My predicate should be used in order to extract string values within custom objects 'inw', which are contained in a list of lists of lists, but I also want to keep the lists of lists structure. I tested this predicate using SWI Prolog :
Code: Select all
inw_str([],[]):-
!.
inw_str([H|T], Words):-
H=inw(Word,_,_), % Word is the relevant string value that I want to keep
inw_str(T,Acc),
Words= [Word|Acc].
inw_str([H1|T1], [H2|T2]):-
inw_str(T1,T2),
inw_str(H1,H2).
Code: Select all
?- inw_str([[[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)]]], Res).
Res = [[[bonjour, le, monde], [salut, ca, va], [test]], [[bonjour, le, monde], [salut, ca, va], [test]]] ;
false.
error c504 : The expression has type 'database::inw', which is incompatible with the type 'database::inw*'
(with inw* as declared input type)
or
error c504 : The expression has type 'A', which is incompatible with the type 'database::inw'
(when I use A* as input type)
This is likely due to the third clause, where I use H1 as input (and it is not legal to Vprolog). I tried creating a custom domain but I am still not comfortable with that and it did not work.
(error c504 : The expression has type 'A$*', which is incompatible with the type 'database::inw_cpnd')
Is there any simple way to solve this problem ? Should I quit using this kind of recursion ? Is there a correct way to declare the domain that I should use ?
Thanks,
Paul