On Apr 24, 2:04 pm, inv <
inv2...@gmail.com> wrote:
> Hello,
> I wrote a program on bprolog - and looks like it works, but I decided
> to move to SWI-prolog and found the following error:
> ERROR: '.'/2: Type error: `[]' expected, found `[1,1]' ("x" must hold
> one character)
> Exception: (8) ff([1, 1], me, you, 100, 200, _G66, _G67) ? creep
>
> I think I am not the first who asks this question, but how to create a
> path? I wanted to create a path for minimum R value, but at the time I
> am just trying to build every possible path.
>
> Could you please explain what is wrong here: why [] is not the same
> type like [1,1], hot to join them?
That's not what's causing the error but note that [] is an atom and
[1,1] is a compound term. So, they are not of the same type. But
that's no different from any other language that supports lists: you
don't terminate a list with a list but with a special value. E.g.
Pascal uses NIL, C/C++ uses NULL. Prolog uses the atom []. Also note
that the [_|_] is just syntactic sugar for '.'/2. E.g. [1,2,3] is the
same as '.'(1, '.'(2, '.'(3, []))):
?- [1,2,3] = '.'(1, '.'(2, '.'(3, []))).
true.
> listing:
>
> tr(me,_,P,R) :- R is P.
> tr(_,me,P,R) :- R is P.
>
> tr(F,you,P,R) :- F\==you,R is P*2.
> tr(you,T,P,R) :- T\==you,R is P*0.9.
>
> ff(L,FF,F,PP,P,R,LR) :-
> length(L,LN),LN<3
> ,tr(F,TT,P,RR)
> ,append([1],L,LL)
> ,ff(LL,FF,TT,PP,RR,R,LR)
> .
>
> ff(L,FF,F,PP,P,R,LR) :-
> length(L,LN),LN>=3
> ,P>PP,FF=F
> ,R is P,LR is L
> .
>
> f(P,RR) :- ff([],me,me,P,P,R,LR),max(R,RR).
>
> run:
> f(100,RR).
>
> I googled, checked slashdot, but found the same error, but it is not
> clear how to fix it.
>
> Thank you.
The error is in the second clause for the ff/7 predicate. The second
argument of the is/2 built-in predicate must be an arithmetic
expression but, in LR is L, L is a list. Hence the error you get
(there's an exception, however, when L is a singleton list containing
an integer).
Btw, you don't need to use append/3 to concatenate a list with a
single element to another list...
Cheers,
Paulo