Re: Another little problem



phantastic@xxxxxxxxxx wrote:

repeat
h(Z,F,G)
F = G
G = Z
while Z <> empty

Hi,
in I think in prolog you have to convert this into recursion.
Which variable holds the result of your computation ? F,G or Z ?
Z makes no sens, as it is [] at the end.
G also makes no sense as it is G := Z at the end.
So I think it is F, right ?
So how about this:

pred(F,F,G) :- h([],F,G).
pred(Fout,F,G) :-
h(Z,F,G),
pred(Fout,G,Z).

Regards
Thorsten

.



Relevant Pages

  • Re: Another little problem
    ... in I think in prolog you have to convert this into recursion. ... i hate the recursion!! ... Z makes no sens, as it is at the end. ...
    (comp.lang.prolog)
  • Re: advice from a newbie
    ... previous opinion that Prolog's reliance on recursion ... Here's the usual Prolog implementation of reverse/2 ... Do there exist "closed" backtrack points as well then? ... Deterministic is a word used to describe predicates ...
    (comp.lang.prolog)
  • Re: pls confirm what approach is more efficient
    ... > recursion is a good thing because it can be transformed into iteration, ... > therefore stack usage is constant. ... > something more efficient that doesn't consume resources linear to the ... > Prolog, how can the most resource efficient implementation be picked ...
    (comp.lang.prolog)
  • Re: Minsky still posting
    ... >> claims to have found Prolog and recursion incredibly difficult to ... > mainly a hobbiest. ... He had problems understanding just about the simplest bit of Prolog ... I've spent my academic career in logic programming, ...
    (comp.lang.prolog)
  • Re: advice from a newbie
    ... I am extremely proud of the combination of using an aggregate ... seem to mistrust recursion and feel that Prolog ... and I would really like a version of member/2 which does not ... Probably Prolog programmers don't even know this, ...
    (comp.lang.prolog)