reentrant maxval and minval.
This commit is contained in:
parent
a90e006be0
commit
cca1461747
@ -226,17 +226,26 @@ minval(V,_,GMax) :-
|
|||||||
nb_getval(min_arg, V.GMax).
|
nb_getval(min_arg, V.GMax).
|
||||||
|
|
||||||
|
|
||||||
maxval(_,_,_) :-
|
|
||||||
nb_setval(max, -inf),
|
|
||||||
nb_setval(max_arg, '$none'),
|
|
||||||
fail.
|
|
||||||
maxval(V,G,GMax) :-
|
maxval(V,G,GMax) :-
|
||||||
call(G),
|
Memory = f(-inf,[]),
|
||||||
nb_getval(max, V0),
|
(
|
||||||
V > V0,
|
call(G),
|
||||||
nb_setval(max, V),
|
arg(1, Memory, V0),
|
||||||
nb_setval(max_arg, V.GMax),
|
V > V0,
|
||||||
fail.
|
nb_setarg(1, Memory, V),
|
||||||
maxval(V,_,GMax) :-
|
nb_setarg(2, Memory, V.GMax)
|
||||||
nb_getval(max_arg, 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)
|
||||||
|
).
|
||||||
|
Reference in New Issue
Block a user