Lambda-Prolog treasure

This is our yield from the Lambda-Prolog treasure hunt.

List reverse

In Lambda-Prolog:
type reverse (list A) -> (list A) -> o.
reverse [] [].
reverse [H|T] Y :- reverse T Z, append Z [H] Y.
In Haskell:
reverse [] = []
reverse (h:t) = (reverse t) ++ [h]

Dynamic scoping

  1. magic_number_plus_one X gives X : 4
  2. foo X gives X : 3
  3. Lambda-Prolog's modularity is as bad as Lisp 1.5. A caller can change the bindings of any free variables in the callee.

Red vs. green cuts

min 2 5 5 incorrectly answers true. A simple way to fix it is
min X Y Z :- X <= Y, !, X = Z.
min X Y Y.
In Haskell, this corresponds to
min x y z | (x < y) = (x == z).
min x y z | (y == z) = True.

Loops

read_all :- repeat, read X, eof X, !.

PLE Home page
Last modified: Tue Jan 30 22:29:38 EST 1996