[comp.ai] Common lisp code for R. Shank's books

cww@cadre.dsl.pitt.edu (Charles William Webster) (09/15/89)

Does anyone know of someplace I can get the common Lisp code
for the micro-programs in Inside Computer Understanding
and Inside Case-Based Reasoning?  I have also heard that
there are Prolog versions floating around.

Thanks

Charles Webster

maner@bgsuvax.UUCP (Walter Maner) (09/16/89)

From article <1989Sep14.211029.14070@cadre.dsl.pitt.edu>, by cww@cadre.dsl.pitt.edu (Charles William Webster):
> Does anyone know of someplace I can get the common Lisp code
> for the micro-programs in Inside Computer Understanding
> and Inside Case-Based Reasoning?  I have also heard that
> there are Prolog versions floating around.
> 

I put a similar question to Chris Riesbeck and received the following reply.
Because of the general nature of the reply, I think it is appropriate to
post it to the net.

----

From riesbeck-chris@YALE.ARPA Mon Jul 10 11:32:00 1989
Date: Mon, 10 Jul 89 11:05:05 EDT
Subject: Re: INSIDE COMPUTER UNDERSTANDING
To: Walter Maner<maner@andy.bgsu.edu>
    
    Do the five mini-programs discussed in _ICU_ exist in a Common Lisp
    form yet?

No.  A few years ago, several people expressed interest to Erlbaum in doing
the conversion, but I heard nothing more.  There's a new volume (plug,
plug) coming out any second now from Erlbaum, called Inside Case-Based
Reasoning (Riesbeck and Schank), that covers more recent Yale work.  It's
in Common Lisp.

    If not (since you recently did a fine job of porting the code in the
    first edition of _Artificial Intelligence Programming_ to Common Lisp)
    do you have any suggestions about how we might best proceed to convert
    the _ICU_ examples from UCI-Lisp to Common Lisp?

AIP 2 was a major rewrite.  Many of the extensions we made to UCI Lisp
became standard in Common Lisp (naturally, since we got them from MacLisp)
and Scheme).

    Is there a UCI-->CL converter robust enough to do part of the work?

A year or two ago I made up a short UCI package in Common Lisp that
supports most of the ICU code directly.  The advantage of this approach for
teaching is that the code matches the text.  If you use a Common Lisp
conversion, then the students read one thing in the text and see something
else in their code.

I'm including the UCI package here, since it's short.  Note that you do
have to make certain changes to the UCI code (the most pervasive being
replacing colons with dashes) and you have to include the extensions
(LET, LOOP, MSG, FOR, etc.) from the text.
    
=================

#|                      UCI Lisp Package

This file sets up a Common Lisp environment that looks like the subset of
UCI Lisp used in Inside Computer Understanding by Schank and Riesbeck,
Lawrence Erlbaum Associates, Publishers, 1981.

To use this, start up your Common Lisp, load this file or a compiled
version of it, then type

    (SETQ *PACKAGE* (FIND-PACKAGE 'UCI))

This puts you into the UCI environment.  Now load your files, e.g., McSAM
or McELI.

If at any point you want to return to normal Common Lisp, type

    (SETQ *PACKAGE* (FIND-PACKAGE 'USER))

THIS DOES NOT AFFECT YOUR UCI ENVIRONMENT.  If you type the first
expression again, you will be returned to the UCI environment, with
everything defined just as it was when you left it.

Differences between the UCI environment and Common Lisp:

    SOME returns a list rather than T or NIL (see Inside Computer
    Understanding. p. 66)

    SPRINT (p. 60) always prettyprints in the first column.

Changes you have to make to the UCI code in Inside Computer Understanding:

    Replace /<special character> with \<special character> (p. 42).
    E.g., (DRM /? (LAMBDA ...  => (DRM \? (LAMBDA ... (p. 70)

    Replace the ] super-parentheses (p. 42) with the necessary number of 
    right parentheses.

    Replace : in names with a hyphen (-), e.g., ROLE:PAIR => ROLE-PAIR.

Define the functions and macros in Chapter 4, pp. 66-73, including LET
and LOOP, but 

    you don't have to define PUSH and POP (p. 69)

    ignore the macro-related code on pp. 73-74.

|#

(provide 'uci)
(in-package 'uci :use '(lisp system))
(shadow '(lisp:let lisp:loop lisp:some))

(defmacro de (&rest l) `(defun ,@l))

(defmacro defprop (id val prop) `(putprop ',id ',val ',prop))

(defmacro df (name vars &rest l)
 `(defmacro ,name (&rest ,@vars )
   `(let ((,',(car vars) ',,(car vars))) ,@',l)))

(defun difference (&rest l) (apply #'- l))

(defmacro dm (name vars &rest l)
 (let ((var (gensym)))
  `(defmacro ,name (&rest ,var)
    (let ((,(car vars) (cons ',name ,var))) ,@l))))

(defmacro drm (ch fn)
 (let ((stream-var (gensym)) (char-var (gensym)))
  `(set-macro-character (coerce ',ch 'character)
    #'(lambda (,stream-var ,char-var)
       (declare (ignore ,stream-var ,char-var))
       ,@(cddr fn)))))

(defun explode (x)
 (map 'list
      #'(lambda (c) (intern (string c)))
      (princ-to-string x)))

(defun minus (x) (- x))

(defmacro msg (&rest l)
 `(prog nil
        ,@(mapcar #'(lambda (x)
                     (cond ((eql x 't) `(terpri))
                           ((stringp x) `(princ ,x))
                           (t `(prin1 ,x))))
                  l)))
(defun plus (&rest l) (apply #'+ l))

(defun putprop (id val prop) (setf (get id prop) val))

(defmacro selectq (key &rest cases)
 `(case ,key
    ,@(do ((cases cases (cdr cases))
           (result nil
                   `(,@result (,(cond ((consp (caar cases)) (caar cases))
                                      (t (list (caar cases))))
                               ,@(cdar cases)))))
          ((null (cdr cases)) `(,@result (t ,(car cases)))))))

(defun some (fn l) (member-if fn l))

(defun sprint (exp col)
 (declare (ignore col))
 (pprint exp))

(defun times (&rest l) (apply #'* l))

-------


-- 
CSNet    maner@andy.bgsu.edu           | 419/372-8719
InterNet maner@andy.bgsu.edu 129.1.1.2 | BGSU Comp Sci Dept
UUCP     ... !osu-cis!bgsuvax!maner    | Bowling Green, OH 43403
BITNet   MANER@BGSUOPIE