Putting arguments in a list
From: Andreas Nauerz (nospam_at_web.de)
Date: 10/26/04
- Previous message: Roberto Bagnara: "Re: Giant bug in XSB 2.6?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 26 Oct 2004 23:45:21 +0200
Hi there,
assume there is a predicate as_find/3.
If you issue an as_find(...,Y,X), then X is usually instantiated to more
than one value, X = 1 or 2 or 3 for example. This result depends on Y.
What as_find exactly does is unimportant at this point.
I now have a predicate as_search/2 which allows the user to specify Y via
console input.
The input is processed (as long as the user has not entered 'genug.') and a
list should be build up containing all possible solutions. So, with respect
to the example above, the list should contain [1,2,3].
I have tried to implement that but have the remaining problem that only 1
(!) of the 3 solutions is put into the list.
Any idea ?
% The as_find section
% Only one element left
as_find([[Key,Data]|_],Key,Data).
% Iteratre recursivly through the list
as_find([_|T],Key,Data):-as_find(T,Key,Data).
% The as_search I/O section
as_search(List):-read(Key),check_input(List,Key).
check_input(_,Key):-Key == genug, write('stop'), fail.
check_input(List, Key):-not(Key == genug), as_find(List,Key,Data),
output(Data). %, as_search(List).
output(Data):-Data =.. Solutionlist, write(Solutionlist).
I am using SWI Prolog btw...
Thanks a lot !
Regards,
Andreas
- Previous message: Roberto Bagnara: "Re: Giant bug in XSB 2.6?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|