Discussions related to Visual Prolog
Gass
Posts: 22
Joined: 17 Aug 2017 8:51

project only goal

Post by Gass »

hi,
it is possible to use the only goal project to test clauses like this.

Code: Select all

class predicates     power1:(real, integer, real). clauses power1(A,B,C):-         bound(A),bound(B),!,         C=exp(B*ln(A)). goal    power1(4,3,D).
It gives me an error at the predicates level
thanks
Gass
Posts: 22
Joined: 17 Aug 2017 8:51

project console

Post by Gass »

here a more complicated way to solve the problem:

Code: Select all

implement main     open core class predicates     power1 : (real, integer, real [out]). clauses     power1(A, B, C) :-         bound(A),         bound(B),         !,         C = math::exp(B * math::ln(A)). clauses     run() :-         power1(4, 4, C),         stdio::write(" c = ", C),         _ = console::readChar(). end implement main goal     console::runUtf8(main::run).
Harrison Pratt
VIP Member
Posts: 459
Joined: 5 Nov 2000 0:01

Re: project console

Post by Harrison Pratt »

I suggest using the [</>] button to format your code display.

Code: Select all

class predicates     power1 : (real A, integer B, real PowerAB [out]). clauses     power1(A, B, C) :-         C = math::exp(B * math::ln(A)).   clauses     run() :-         power1(4, 3, D),         stdio::write("\n", D),         _ = console::readLine().   end implement main   goal     console::runUtf8(main::run).
User avatar
Thomas Linder Puls
VIP Member
Posts: 1468
Joined: 28 Feb 2000 0:01

Re: project only goal

Post by Thomas Linder Puls »

Goal mode does not exist any more.

Regarding the calculation itself you should notice the power operator (^):

Code: Select all

clauses     run() :-         stdio::writef("Power(4, 3) = %\n", 4 ^ 3).
See also Arithmetic Operators.
Regards Thomas Linder Puls
PDC