Understanding how to use arg/3 and univ/2 in Prolog -
i have database in prolog , i'm trying return henry owns , owns car , truck. i've tried can think of return henry owns , can't find solution. know how return owns car or truck individually ?- owns(x,car(,,_))., not @ same time. appreciated.
owns(bill, car(ford, mustang, 1964)). owns(sue, car(pontiac, gto, 1967)). owns(george, car(honda, civic, 2013)). owns(betty, truck(ford, f150, 2013)). owns(henry, motorcycle(honda, goldwing, 2010)).
prolog has relational data model, allows recursive terms instead of atomics only, sql, , doesn't give names 'columns'. loosely:
╒═════════════╤═════════════╕ │ sql │ prolog │ ╞═════════════╪═════════════╡ │ table │ predicate │ │ record │ clause │ │ table name │ functor │ │ column │ argument │ ╘═════════════╧═════════════╛
so, knowledge attributes position required. conventionally, can associate attribute' names in functors:
% owner of kind listed kinds_owner(kinds, owner) :- owns(owner, object), object =.. [kind|_], member(kind, kinds). % owners of kind listed kinds_owners(kinds, owners) :- setof(owner, kinds_owner(kinds, owner), owners). ?- kinds_owner([truck,motorcycle],x). x = betty ; x = henry. ?- kinds_owners([truck,motorcycle],xs). xs = [betty, henry].
Comments
Post a Comment