sant016
sant016

Reputation: 345

How to preserve a variable name in Prolog?

I'm trying to write a program which evaluates a function and does some operations on it.

dynamic evaluate/2.
begin :- writeln("Write your function"), read(Line),  
              assert((evaluate(X, Y) :- Y is Line)).

Since in SWI-prolog variable names are changed to _«number», when I try to call evaluate(), it doesn't work.

Any solutions to this?

Thanks.

Upvotes: 2

Views: 472

Answers (1)

pts
pts

Reputation: 87281

Use read_term/2 (http://www.swi-prolog.org/pldoc/man?predicate=read_term/2) with the variable_names option instead of read(Line):

read_term(Line, [variable_names(['X'=X])])

Upvotes: 3

Related Questions