From cca1461747a55a49f4fdd40fb3b1fdddeb25a7e7 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 3 Nov 2010 09:45:18 +0000 Subject: [PATCH] reentrant maxval and minval. --- packages/meld/meldi.yap | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/meld/meldi.yap b/packages/meld/meldi.yap index 17b6b4885..62e9ea388 100644 --- a/packages/meld/meldi.yap +++ b/packages/meld/meldi.yap @@ -226,17 +226,26 @@ minval(V,_,GMax) :- nb_getval(min_arg, V.GMax). -maxval(_,_,_) :- - nb_setval(max, -inf), - nb_setval(max_arg, '$none'), - fail. maxval(V,G,GMax) :- - call(G), - nb_getval(max, V0), - V > V0, - nb_setval(max, V), - nb_setval(max_arg, V.GMax), - fail. -maxval(V,_,GMax) :- - nb_getval(max_arg, V.GMax). + Memory = f(-inf,[]), + ( + call(G), + arg(1, Memory, V0), + V > V0, + nb_setarg(1, Memory, V), + nb_setarg(2, Memory, V.GMax) + ; + arg(2, Memory, V.GMax) + ). +minval(V,G,GMin) :- + Memory = f(+inf,[]), + ( + call(G), + arg(1, Memory, V0), + V < V0, + nb_setarg(1, Memory, V), + nb_setarg(2, Memory, V.GMin) + ; + arg(2, Memory, V.GMin) + ).