Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning PROLOGUE

Name: Anonymous 2009-05-20 23:49

Good PROLOGUE books, please. I read S&A.

Name: Anonymous 2009-05-21 20:09

>>5
twofibs(0, 1, 0).
twofibs(N, F1, F0) :-
  atomic(N), N > 0,
  Q is N >> 1, R is N /\ 1, twofibs(Q, A, B),
  X is A * A + B * B, Y is B * (A << 1 + B),
  ( R =:= 0 -> F1 is X, F0 is Y; F1 is Y, F0 is X + Y ).

fib(N, F) :-
  A is abs(N),
  S is sign(N),
  R is N /\ 1,
  twofibs(A, _, F0),
  ((S =:= -1, R =:= 0) -> F is -F0; F is F0).


and here's a prime sieve for you:
:- use_module(library(chr)).
:- chr_constraint prime/1.
prime(X) \ prime(Y) <=> 0 is Y mod X | true.
primes(1). primes(N) :- prime(N), succ(M,N), primes(M).


>>13
lisp has been obsolete for almost 40 years.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List