Tuesday, 15 July 2014

prolog using recursion to find successor -



prolog using recursion to find successor -

i'm trying larn prolog , started recursion topic. came across illustration successor.

numeral(0). numeral(succ(x)) :- numeral(x)

i understand how works in theory. takes number x , succ increments it. questions here is, succ in-built predicate? or there else going on in example. illustration taken learnprolognow.org

then came across exercise

pterm(null). pterm(f0(x)) :- pterm(x). pterm(f1(x)) :- pterm(x).

it meant represent binary, 0 f0(null), 1 f1(null), 2(10) f0(f1(null)), 3(11) f1(f1(null)) etc. question asks define predicate (p1, p2) p2 successor of p1 using pterms. explain question in more detail me? way see now, have traverse through p1 until nail end , compare p2, i'm not sure syntax. hints useful

seems inspecting top level argument enough. hint

psucc(pterm(f0(x)), pterm(f1(f0(x)))). ...

prolog

No comments:

Post a Comment