1
votes

I'm new to prolog .. i tried this code but got error and don't know why ?!

de(F,L,R):-
R=[F|L].

is that because rule must have a recursion ? the error is

ERROR: Syntax error: Operator expected
1
No, a rule does not need recursion. If I test this locally, I do not get an error anyway. - Willem Van Onsem
i tested it as de[a,[a,1,2,3],Z]. - user7721156
well that is indeed a syntax error, you need to use parenthesis when calling a predicate, so de(a, [a,3,4,5,2], Z). - Willem Van Onsem
ohhh, thanks i missed it really - user7721156

1 Answers

0
votes

In your comment, you specify what you did wrong:

i tested it as de[a,[a,1,2,3],Z].

When you call a predicate, you use parenthesis ((…)), square brackets ([…]) are used to construct lists. You thus should call the predicate with parenthesis:

?- def(a,[a,1,2,3],Z).
Z = [a, a, 1, 2, 3].