This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/library/varnumbers.yap

46 lines
774 B
Plaintext
Raw Normal View History

2015-11-18 15:06:25 +00:00
/**
* @file varnumbers.yap
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
* @date 2006
2017-04-13 21:42:34 +01:00
*
2015-11-18 15:06:25 +00:00
* @brief opposite to numbervars
2017-04-13 21:42:34 +01:00
*
*
2015-11-18 15:06:25 +00:00
*/
:- module(varnumbers, [
numbervars/1,
max_var_number/3,
varnumbers/2
]).
2015-11-18 15:06:25 +00:00
/**
* @defgroup varnumbers Variabilize term.
2017-04-13 21:42:34 +01:00
* @ingroup library
*
2015-11-18 15:06:25 +00:00
*/
numbervars(Term) :-
numbervars(Term, 0, _).
max_var_number(V,Max,Max) :- var(V), !.
max_var_number('$VAR'(I),Max0,Max) :- !,
Max is max(I,Max0).
max_var_number(S,Max0,Max) :-
functor(S,_,Ar),
max_var_numberl(0,Ar,S,Max0,Max).
max_var_numberl(I0,Ar,T,Max0,Max) :-
( I0 =:= Ar ->
Max0 = Max
;
I is I0+1,
arg(I,T,A),
max_var_number(A,Max0,MaxI),
max_var_numberl(I,Ar,T,MaxI,Max)
).
varnumbers(GT, VT) :-
2011-11-14 14:36:24 +00:00
unnumbervars(GT, VT).