Reputation: 43
Is it possible in prolog to do an assignment like Variable = TermCompound?
For example: X = token (a, b, c).
And, if you can do it, from X is it possible to derive the arguments and the functor of the compound term?
Upvotes: 1
Views: 419
Reputation: 18663
See your Prolog system documentation on the ISO standard predicates =/2
, functor/3
, =../2
, and arg/3
. Sample calls:
| ?- X = token(a, b, c).
X = token(a,b,c)
yes
| ?- X = token(a, b, c), functor(X, Name, Arity).
Arity = 3
Name = token
X = token(a,b,c)
yes
| ?- X = token(a, b, c), X =.. [Name| Arguments].
Arguments = [a,b,c]
Name = token
X = token(a,b,c)
yes
| ?- X = token(a, b, c), arg(2, X, Argument).
Argument = b
X = token(a,b,c)
yes
Upvotes: 3