About the Shen Prolog

68 views
Skip to first unread message

Antti Ylikoski

unread,
May 25, 2015, 8:14:45 AM5/25/15
to qil...@googlegroups.com
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


Mark Tarver

unread,
May 25, 2015, 9:54:54 AM5/25/15
to qil...@googlegroups.com, antti.y...@gmail.com
This facility exists already.

Mark

Mark Tarver

unread,
May 25, 2015, 4:04:12 PM5/25/15
to qil...@googlegroups.com, dr.mt...@gmail.com, antti.y...@gmail.com

Antti Ylikoski

unread,
May 25, 2015, 4:16:22 PM5/25/15
to qil...@googlegroups.com, antti.y...@gmail.com
Thank you Mark, I was being pretty careless.

Following is a working Quicksort for those who feel they need some demos:


-------------------------------------------------------------------------------------------------

\*
 *
 * 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
 *\

\* 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 <--
    (when (<= A H))
    (quisort-split H X Y Z);
  H [A | X] Y [A | Z] <--
    (when (> A H))
    (quisort-split H X Y Z);
  Ignore [] [] [] <-- ;)


\\ (prolog? (quisort [88 1 6 3 7 3 4 5 777 6 8 8 99] Sorted) (return Sorted))

(defprolog quisort
  [] [] <--;
  [H | T] S <--
    (quisort-split H T A B)
    (quisort A A1)
    (quisort B B1)
    (qappend A1 [H | B1] S);)

------------------------------------------------------------------------

yours, A. J. Y.

Mark Tarver

unread,
May 25, 2015, 4:26:27 PM5/25/15
to qil...@googlegroups.com
It's ok - a lot of stuff to learn.

mark

--
You received this message because you are subscribed to a topic in the Google Groups "Shen" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qilang/v91SWveC-hk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qilang+un...@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at http://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages