Re: Help I'm stuck!

From: Pento (robby.goetschalckx_at_cs.kuleuven.ac.be.NOSPAM)
Date: 08/13/04

  • Next message: Jan Wielemaker: "Re: How to return clause in findall/3"
    Date: Fri, 13 Aug 2004 09:25:02 +0000 (UTC)
    
    

    reader <no-spam@sonic.net> wrote in
    news:jGPSc.7175$54.109433@typhoon.sonic.net:

    > /*
    > You have declared your data to be a database, so just
    > use retract to find the maximum score:
    > */
    >
    > Predicates
    > find_max(integer,integer).
    >
    > Clauses
    >
    > find_max(In,Out) :-
    > retract(sc(_,_,ExamScore)),
    > !,
    > elem_max(In,ExamScore,Next),
    > find_max(Next,Out).
    > find_max(In,In).
    >
    > GOAL find_max(0,Max).

    I'm not a big fan of assert/retract, so I'm not sure of this, but shouln't
    you assert the things you retracted again when the max is found ?

    -- 
    Pento
    De wereld was soep, en het denken meestal een vork,
    tot smakelijk eten leidde dat zelden. - H. Mulisch
    

  • Next message: Jan Wielemaker: "Re: How to return clause in findall/3"

    Relevant Pages

    • Re: Newbie: accumulators
      ... assert and retract in a nice way. ... of the assert/retract thing, your code does not even go near to solving ... No it doesn't count the backtracking. ... it uses a pair of accumulator variables per item of state. ...
      (comp.lang.prolog)
    • Convert a "global variable"
      ... I use assert / retract to set a value which should be accessible in the same ... way as a global variable in a functional language. ... I could pass the "global" variable as argument between all predicates of my ...
      (comp.lang.prolog)