1

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?

2
  • There is no assignment in Prolog. The variable X is unified (if possible) to token (a, b, c). Nonetheless, yes, you can. Commented Jan 13, 2019 at 11:18
  • Thanks. And, after the unification, how can i extract from X the name of main functor, eg. 'token'? Commented Jan 13, 2019 at 11:39

1 Answer 1

3

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.