TmCrafz
TmCrafz

Reputation: 184

SWI Prolog give all variables in list of lists specific value

I have a List like this: [[X,Y],[X],[Y],[X,Y,Z]].

Now I want to give every free Variable of X the value "true". Like:

?- assign_val(X,[[X,Y],[X],[Y],[X,Y,Z]], true, R).
R = [[true,Y],[true],[Y],[true,Y,Z]]

How to archive this?

Upvotes: 1

Views: 118

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476740

These are not different variables, there is only one variable X that simply occurs multiple times.

You thus can simply assign true to X. The fact that this item in an expression is irrelevant. You can implement this as:

assign_val(X, R, X, R).

But as you see, the R is not necessary here.

Upvotes: 2

Related Questions