Re: Help I'm stuck!

From: Pere Montolio (tmp123_at_menta.net)
Date: 08/11/04

  • Next message: rhapsody: "Re: Help I'm stuck!"
    Date: 11 Aug 2004 02:07:08 -0700
    
    

    "rhapsody" <blurrynight@yahoo.com> wrote in message news:<c8fef06a6b1dda57c1479b15827e547a@localhost.talkaboutprogramming.com>...
    > Help I'm stuck, can anybody tell me how to retrieve sc() with the maximum

    You have two options:
    a) The first one is to use the functions findall, setof, bagof or
    similars. It is a perfectly valid option, usually the best option. It
    is based on convert statements to list, and process the list.
    b) A second one, stronger, but sometimes useful because involves
    different resources, is to handle with dynamic statements
    (assert/retract), like in:

    ( Note1: Text between "" is as comment. You can be it.
      Note2: Written without test, errors are posible. )

    :- dynamic current_maximum/1.

    do :-
      sc(P1,P2,VALUE),
      maximum(VALUE),
      fail.
    do.

    maximum(VALUE) :-
      current_maximum(MAX),
      "if MAX >= VALUE",
      !. /* if MAX > VALUE, nothing else to do, go next */
    maximum(VALUE) :- /* MAX < VALUE, modify current maximum */
      "retract current_maximum",
      "asserta current_maximum(VALUE)".

    I'm sure some other readers of this group can do improvements and
    corrections to this example.


  • Next message: rhapsody: "Re: Help I'm stuck!"