value(+string_or_atom)

This predicate converts a string or an atom, containing an arithmetic expression, to an arithmetic value. It is not necessary to use a '.' to indicate the end of the arithmetic expression, it is however not an error to do so.

see also: arithmetic in Prolog is/2

Examples
X is value("3+455-23"). X is 435
X is value("45*78."). X is 3510
X is value("2+6+sqrt(16)-(2*3)"). X is 6
X is value("2+value(""2+3"")"). X is 7
X is value('5+7'). X is 12

 

Exceptions
Arg is not a valid atom or string argument a type_error(evaluable, Arg) exception is thrown

 

 

info@trinc-prolog.com