0
votes

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?

1
There is no assignment in Prolog. The variable X is unified (if possible) to token (a, b, c). Nonetheless, yes, you can. - Enigmativity
Thanks. And, after the unification, how can i extract from X the name of main functor, eg. 'token'? - user3062889

1 Answers

2
votes

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