Putting arguments in a list

From: Andreas Nauerz (nospam_at_web.de)
Date: 10/26/04

  • Next message: DEMAINE Benoit-Pierre: "newby question about lists"
    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


  • Next message: DEMAINE Benoit-Pierre: "newby question about lists"

    Relevant Pages

    • Re: Could not load foreign predicates in SWI Prolog 5.6.
      ... > foregin predicate (in C language) and use it in SWI Prolog. ... > into the prolog interpreter, ...
      (comp.lang.prolog)
    • Could not load foreign predicates in SWI Prolog 5.6.
      ... foregin predicate (in C language) and use it in SWI Prolog. ... into the prolog interpreter, then load_foreign_librarycall doesnt ...
      (comp.lang.prolog)
    • sub_atom implementation
      ... I am using SWI Prolog. ... I have two issues regarding sub_atom/5 predicate. ... Is it possible to say sub_atom/5 that I want first longer sub atoms without ... tailoring a new predicate? ...
      (comp.lang.prolog)
    • Dynamic construction of variables from strings
      ... domain specific language to Prolog goals which are then executed using ... according to the SWI Prolog manual, will unify Goal with foo. ... My problem is that foo, hello and X must be constructed dynamically ... be accomplished using the atom_chars predicate. ...
      (comp.lang.prolog)
    • arithmetic_function (SWI)
      ... This is an issue regarding arithmetic_function/1 predicate under SWI Prolog. ... Suppose I define a new arithmetic function, namely a constant c/0, in this ... So it seems that predicate e/1 associated with arithmetic function e/0 it is ...
      (comp.lang.prolog)