" so that by typing "a ++> b", you will create a li...">

How to define a statement in the prolog to create a list?

I want to define the operator "++>" so that by typing "a ++> b", you will create a list [a, b].

I wrote the following code, but it does not seem to do the job.

++>(X,Y) :-
 [X,Y].

:- op(500,xfy,++>).
+5
source share
3 answers
:- op(500,xfy,++>).
++>(X,Y,[X,Y]).

And use it like

?- ++>(1,2,X).
X = [1, 2].

Actually, Prolog is not oriented computation, so operators are simply synonymous with terms. You need the term \ 3, where one item is a list of the other two. Therefore, you cannot use a 2-position operator in this case. By the way, you cannot use in this situation, because it was used only in arithmetic cases.

0

:

++>((X,Y),Z) :-Z= [X,Y].

:- op(500,xfy,++>).
0

[a,b,c] - '.'(a,'.'(b,'.'(c)))). , :

:- op(500,xfy,'++>').

convert('++>'(A,B),[A|R]) :-
    convert(B,R).
convert(Any,[Any]).

:

| ?- X = 1++>2++>3, convert(X,Y).                                    
X = 1++>2++>3
Y = [1,2,3] ?
yes
0

All Articles