2

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.

false
  • 10,264
  • 13
  • 101
  • 209
sant016
  • 195
  • 1
  • 2
  • 14
  • 1
    Not sure what you want. For variable names [see this](http://stackoverflow.com/a/7948525/772868). – false Oct 27 '15 at 14:06

1 Answers1

3

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])])
pts
  • 80,836
  • 20
  • 110
  • 183