users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable listing


From: Dieter Büttner
Subject: Re: variable listing
Date: Mon, 29 Dec 2003 21:22:32 +0100
User-agent: KMail/1.5.4

Hi Tomas,
try the following code. I held it tail recursive as far as possible, therefore 
the Accu-variable. 
The query "get_vars(tt(a(X,c,Y,d(f(Z),U))), V). ", for example, will be 
answered by 
V = [X,Y,Z,U],
as you wished.

Greetings
Dieter


get_vars(Term, VariableList) :-
        =..(Term, TermList),
        w_get_vars(TermList, VariableList, []).

w_get_vars([], Accu, Accu).

w_get_vars([L1|LR], VarL, Accu) :-
        atomic(L1),
        w_get_vars(LR, VarL, Accu).

w_get_vars([L1|LR], VarL, Accu) :-
        var(L1),
        append(Accu, [L1], NewAccu),
        w_get_vars(LR, VarL, NewAccu).

w_get_vars([L1|LR], VarL, Accu) :-
        \+(atomic(L1)),
        \+(var(L1)),
        get_vars(L1, VarL_2),
        append(Accu, VarL_2, NewAccu),
        w_get_vars(LR, VarL, NewAccu).




> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog





reply via email to

[Prev in Thread] Current Thread [Next in Thread]