One individual in this group said that his issue of The Book of Shen
has virtually nothing on Prolog. I decided to write some demos for
the Shen Prolog to help such points.
It very soon turns out that one really does need the capability to
call Shen functions from inside the Shen Prolog. The below attempt to
write the C. A. R. Hoare's Quicksort cannot be written without the
capability to call the Shen/Common LISP comparison predicates "<",
">", ">=" etc etc from inside the Shen Prolog.
------------------------------------------------------------
\*
*
* Shen demo #n+1 by AJY 2015-05-25
*
* C A R Hoare's Quicksort with Shen
*
* Adapted from the author's files for Mats Carlsson's YAQ LISP based
* Prolog, which has the functionality to call LISP from Prolog
* predicates.
*\
\* First some necessary list op machinery:
*\
(defprolog qappend
[] X X <--;
[X | Y] Z [X | U] <--
(qappend Y Z U);)
\* H is the pivot element *\
(defprolog quisort-split
H [A | X] [A | Y] Z <--
(=< A H)
(quisort-split H X Y Z);
H [A | X] Y [A | Z] <--
(> A H)
(quisort-split H X Y Z);
Ignore [] [] [] <-- ;)
(defprolog quisort
[] [] <--;
[H | T] S <--
(quisort-split H T A B)
(quisort A A1)
(quisort B B1)
(qappend A1 [H | B1] S);)
----------------------------------------------------------------------------------------
yours, AJY