Hi pd, > > > : (? (factorial @X 120)) > > > -> NIL > > > > This is another issue. This Pilog version of factorial cannot do reverse > > lookup, > > as it calculate numeric values via Lisp calls. > ... > Ok, I suspected that but is there any way to do arithmetic in pilog? My > understanding is you have to use picolisp for arithmetic > > How should be declared factorial primitive to be compatible with reverse > lookup?
I have not tried. How is it in real Prolog? To take an example a bit simpler than the factorial function, you could start with addition as: (be + (@A @B @C) (^ @A (- @C @B)) ) (be + (@A @B @C) (^ @B (- @C @A)) ) (be + (@A @B @C) (^ @C (+ @A @B)) ) With that, you can do thing like: : (? (+ 3 4 7)) -> T : (? (+ 3 4 @X)) @X=7 : (? (+ 3 @X 7)) @X=4 : (? (+ @X 4 7)) @X=3 But where will that end? Should we also handle two or three variables, generating all combinations of natural numbers? This could surely be done (similar to what 'append/3' does for lists), but I never saw a need for that. > May you tell me what syntax is the right one for prolog primitives > translated to pilog? > > prolog pilog > p(r(b)). (be p (r (b))) -(1)- or > (be p ((r (b)))) -(2)- or I would say the first one. > (be p ((r b))) -(3)- > p(z(a),b) (be p ((z a) b)) -(1)- or > (be p ((z (a)) b)) -(2)- The second one. But I think it does not matter, you can pass any pattern to a predicate, it is matched in any case. > what is supposed to mean (be p (r (b))) if anything? Yeah, there is no "meaning". It is just a pattern. : (? (p r @X)) @X=(b) $: (? (p q @X)) -> NIL : (? (p @A @B)) @A=r @B=(b) : (? (p @A (@B))) @A=r @B=b > May you explain the estructure of a pilog environment (and the use of unify > function) The environments are nested association lists, with numbers for the levels and then the symbols for the values at these levels. > and how pilog clauses are converted to property lists? what > kind of unification algorithm uses pilog? maybe in a PilCon session They are not converted at all. They are stored directly as a list under the 'T' property of the predicate's symbol. Unification looks them up for each level. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe