I have some doubts about the :-op operator in Prolog, because I don't know how to handle it. My exercise is focused on creating a predicate that, from an attribute-value list, whose format is [a1=>v1, a2=>v2,...,aN=>vN], obtains the value of an attribute that is Ask him.
Example: ?- value(shape, [color=>blue, shape=>spherical, weight=>light, material=>plastic], X). X=spherical.
To do this, we suggest defining the => operator in the logical base.
The directive
op/3
allows you to declare atoms that will be syntactically treated as operators with a certain class (infix, suffix, or prefix), associativity, and precedence.=>/2
In your case, you need an infix operator that is not associative:Now you can handle the atom
'=>'(x,y)
asx => y
(although internally these two structures are equivalent).Finally, you can write your predicate
valor/3
as:Here is more information about operators in Prolog.
Wow, amazing. It worked for me without problems. Thanks for the collaboration.