The problem is the following web query returns all parts for a specific
model. I am trying to make it such that, if I ask for model, major, and
minor, then only a single part will be returned.
page_content(_Request) -->
html(
[
form([action='/search', method='POST'], [
p([], [
label([for=model], 'Model '),
input([name=model, type=textarea])
]),
p([], [
label([for=major], 'Major '),
input([name=major, type=textarea])
]),
p([], [
label([for=minor], 'Minor '),
input([name=minor, type=textarea])
]),
p([], input([name=submit, type=submit, value='Search'], []))
])]).
I think I understand memberchk, findall, and maplist individually, but I
don't understand how this queries the facts below in the parts file.
Could someone briefly explain this so that I can understand it and make
the needed changes.
query_verse(Request) :-
member(method(post), Request), !,
http_read_data(Request, Data, []),
format('Content-type: text/html~n~n', []),
format('<p>', []),
memberchk(model=Model, Data),
findall(p(Model, Major, Minor, Desc),
part(Model, Major, Minor, Desc), Descriptions),
maplist(desc, Descriptions),
format('</p>').
desc(p(M,A,I,D)) :- format("~q ~q:~q - ~q</br>", [M,A.I.D]).
This is my
parts.pl file.
:- module(parts,[part/4]).
% part(model, major, minor, description).
part(jeep, 100, 1000, 'description of 100-1000').
part(jeep, 100, 1001, 'description of 100-1001').
part(jeep, 100, 1002, 'description of 100-1002').
part(jeep, 101, 1000, 'description of 101-1000').
part(jeep, 101, 1001, 'description of 101-1001').
part(jeep, 101, 1002, 'description of 101-1002').
part(ford, 101, 1000, 'description of 101-1000').