Re: how to make this in prolog
From: Alan Bal jeu (jeu_at_sympatico.deleteme.ca)
Date: 03/26/04
- Previous message: Linux Man: "Re: Logical Or"
- In reply to: raf_go: "how to make this in prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Mar 2004 21:53:55 -0500
"raf_go" <raf_go@go2.pl> wrote in message
news:c3v3m9$dl0$1@atlantis.news.tpi.pl...
> I nead make somthink like that in prolog
>
> x=1;
> y=2;
>
> for(...){
> a= 2^x * (2^y - 1);
> cout<<a;
> x+=1;
> y+=1;
> }
>
> for help thanks.
Prolog does not have loops, but it does have recursion.
Prolog has assignment (as a special case of unification),
but not reassignment. This isn't a problem, because of recursion.
Variables are capitals, sequencing is done using a comma,
arithmetic using 'is'.
So:
weird_predicate :-
X = 1,
Y = 2,
weird_predicate(X, Y).
weird_predicate(X, Y) :-
..., %% you didn't specify how to stop, but you can do that here.
A is 2 ^ X * (2^Y - 1),
write(A),
X1 is X + 1,
Y1 is Y + 1,
weird_predicate(X1, Y1).
- Previous message: Linux Man: "Re: Logical Or"
- In reply to: raf_go: "how to make this in prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|