turner@imagen.UUCP (02/09/87)
Here is the AI Expert magazine source postings for February, I have left the \015 at the end of each line because the PC seems to like lines ending that way. I also now have back issues of the source code dating back to Nov. 86, so as not to clutter up the net, send me email if you want any back issues or TOC's. ----cut here-------cut here-------cut here-------cut here-------cut here--- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # aiapp.feb # compil.feb # contnt.feb # expert.feb # files.feb # lispvc.feb # This archive created: Mon Feb 9 08:45:39 1987 # By: D'arc Angel (The Houses of the Holy) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'aiapp.feb'" '(8199 characters)' if test -f 'aiapp.feb' then echo shar: "will not over-write existing file 'aiapp.feb'" else sed 's/^ X//' << \SHAR_EOF > 'aiapp.feb' X X AI Apprentice X Figures and Listings X AI EXPERT magazine -- February 1987 X X X X |----------| |----------| |----------| X | cons | | cons | | cons | X |----------| |----------| |----------| X | --------->| --------> | ----->NIL X |----------| |----------| |----------| X | | | | | | X |----|-----| |----|-----| |----|-----| X | | | X V V V X |----------| |----------| |----------| X | functor | | constant | | variable | X |----------| |----------| |----------| X | likes | | vicky | | skiing | X |----------| |----------| |----------| X X XFigure 1. XLinked list representation of "likes(vicky,skiing)." X X |----------| |----------| |----------| X | cons | | cons | | cons | X |----------| |----------| |----------| X | --------->| --------> | ----->NIL X |----------| |----------| |----------| X | | | | | | X |----|-----| |----|-----| |----|-----| X | | | X V V V X |----------| |----------| |----------| |---------| |---------| X | functor | | constant | | cons | | cons | | cons | X |----------| |----------| |----------| |---------| |---------| X | list | | a | | -------->| -------->| -------> NIL X |----------| |----------| |----------| |---------| |---------| X | | | | | | X |----|-----| |----|----| |----|----| X | | | X V V V X |----------| |---------| |---------| X | functor | | constant| | constant| X |----------| |---------| |---------| X | list | | b | | nil | X |----------| |---------| |---------| X XFigure 2 XThe internal representation of list(a,list(b,nil)). X X X X sentence ::- rule | query | command X rule ::- head '.' | head ':-' tail '.' X query ::- '?-' tail '.' X command ::- '@' file_name '.' X head ::- goal X tail ::- goal | goal ',' tail X goal ::- constant | variable | structure X constant ::- {quoted string} | {token beginning with 'a' .. 'z'} X variable ::- {identifier beginning with 'A' .. 'Z' or '_' } X structure ::- functor '(' component_list ')' X functor ::- {token beginning with 'a' .. 'z'} X component_list ::- term | term ',' component_list X term ::- goal | list X list ::- '[]' | '[' element_list ']' X element_list ::- term | term ',' element_list | term | term X file_name ::- {legitimate DOS file name, must be surrounded with X single quotes if it contains a '.',':' or '\'} X X XFigure 3 XVTPROLOG Grammar. X X X PROCEDURE list(VAR l_ptr : node_ptr) ; X VAR X elem_list : node_ptr ; X X PROCEDURE element_list(VAR e_list : node_ptr) ; X VAR X e_list2 : node_ptr ; X BEGIN X term(e_list) ; X IF token = ',' X THEN X BEGIN X scan(source,token) ; X element_list(e_list) ; X END X ELSE IF token = '|' X THEN X BEGIN X e_list2 := NIL ; X scan(source,token) ; X term(e_list2) ; X e_list := append_list(e_list,head(e_list2)) ; X END ; X END ; (* element_list *) X X BEGIN X scan(source,token) ; X IF token = ']' X THEN X BEGIN X l_ptr := append_list(l_ptr,cons(NIL,NIL)) ; X scan(source,token) ; X END X ELSE X BEGIN X elem_list := NIL ; X element_list(elem_list) ; X IF token = ']' X THEN X BEGIN X scan(source,token) ; X l_ptr := append_list(l_ptr,cons(elem_list,NIL)) ; X END X ELSE error('Missing '']''.') ; X END ; X END ; (* list *) X XFigure 4 XA routine to recognize lists. X X |----------| |----------| |----------| X | cons | | cons | | cons | X |----------| |----------| |----------| X | --------->| --------> | ----->NIL X |----------| |----------| |----------| X | | | | | | X |----|-----| |----|-----| |----|-----| X | | | X V V V X |----------| |----------| |----------| X | constant | | constant | | constant | X |----------| |----------| |----------| X | a | | b | | c | X |----------| |----------| |----------| X XFigure 5 XThe internal representation of [a,b,c]. X X |----------| |----------| |----------| X | cons | | cons | | variable | X |----------| |----------| |----------| X | --------->| --------> | Z | X |----------| |----------| |----------| X | | | | X |----|-----| |----|-----| X | | X V V X |----------| |----------| X | variable | | variable | X |----------| |----------| X | X | | Y | X |----------| |----------| X XFigure 6 XThe internal structure of [X,Y|Z]. X X Xitem | Item within the query Xin the | Xrule | constant variable functor list X | (C2) (V2) (F2) (L2) X |-------------------------------------------------------------------- Xconstant | succeed if succeed fail fail X(C1) | C1 = C2 bind V2 to C1 X | Xvariable | succeed succeed succeed succeed X(V1) | bind V1 to C2 bind V1 to V2 bind V1 to F2 bind V1 to L2 X | Xfunctor | fail succeed succeed if fail X(F1) | bind V2 to F1 expressions have X | same functor and X | arity and each X | of components X | can be unified X | Xlist | fail succeed fail succeed if X(L1) | bind V2 to L1 heads can be unified X | and tails can be X | unified X XTable 1 XUnification table for rules and queries. X SHAR_EOF if test 8199 -ne "`wc -c < 'aiapp.feb'`" then echo shar: "error transmitting 'aiapp.feb'" '(should have been 8199 characters)' fi fi echo shar: "extracting 'compil.feb'" '(5186 characters)' if test -f 'compil.feb' then echo shar: "will not over-write existing file 'compil.feb'" else sed 's/^ X//' << \SHAR_EOF > 'compil.feb' X X X Compiling LISP Procedures X by Bruce A. Pumplin X February 1987 LISP issue X Tables and Listings X X X X XTable 1. X X X MOVEI Ri CONST Load register i with a constant X ( the load immediate instruction ) X X PUSH SP Ri Push the contents of Ri onto the stack X X POP SP Ri Pop the top of the stack into Ri X X PUSHJ SP LOC The subroutine entry instruction: X Push the current contents of X the program counter onto the X stack and branch to memory loc- X ation LOC X X CALL LOC The same as PUSHJ SP LOC X X POPJ SP The subroutine return instruction: X Pop the top of the stack into X the program counter X X MOVE Ri LOC Load Ri with the contents of LOC X X MOVE Ri Rj Load Ri with the contents of Rj X X MOVEM Ri LOC Store the contents of Ri in memory X location LOC X X JUMP LOC Unconditional branch to memory location X LOC X X JUMPF Ri LOC Branch to memory location LOC if Ri X contains the constant False X X JUMPT Ri LOC Branch to memory location LOC if Ri X does not contain the constant False X (Note: anything other than False is X assumed to be True) X X X XListing 1. X X X ;;; THE PRIMARY PROCEDURES X X X (DEFUN COMPEXP (EXP) X (COND ((ISCONST EXP) X (LIST (MKSEND 1 EXP))) X (T (COMPAPPLY (FUNC EXP) X (COMPLIS (ARGLIST EXP)) X (LENGTH (ARGLIST EXP)))) X ) ) X X X (DEFUN COMPLIS (U) X (COND ((NULL U) '()) X ((NULL (REST U)) X (COMPEXP (FIRST U))) X (T (APPEND-3 (COMPEXP (FIRST U)) X (LIST (MKALLOC 1)) X (COMPLIS (REST U)))) X ) ) X X X (DEFUN COMPAPPLY (FN VALS N) X (APPEND-3 VALS X (MKLINK N) X (LIST (MKCALL FN)) X ) ) X X X XListing 2. X X ;;; THE RECOGNIZER PROCEDURE X X X (DEFUN ISCONST (X) X (OR (NUMBERP X) X (EQ X T) X (EQ X NIL) X (AND (NOT (ATOM X)) X (EQ (FIRST X) 'QUOTE)) X ) ) X X X ;;; THE SELECTOR PROCEDURES X X X (DEFUN FUNC (X) (FIRST X)) X (DEFUN ARGLIST (X) (REST X)) X X X ;;; THE CONSTRUCTOR PROCEDURES X X (DEFUN MKSEND (DEST VAL) (LIST 'MOVEI DEST VAL)) X (DEFUN MKALLOC (DEST) (LIST 'PUSH 'SP DEST)) X (DEFUN MKCALL (FN) (LIST 'CALL FN)) X (DEFUN MKLINK (N) X (COND ((= N 1) '()) X (T (CONCAT (MKMOVE N 1) X (MKLINK1 (SUB1 N)))) X ) ) X (DEFUN MKLINK1 (N) X (COND ((ZEROP N) '()) X (T (CONCAT (MKPOP N) X (MKLINK1 (SUB1 N)))) X ) ) X (DEFUN MKPOP (N) (LIST 'POP 'SP N)) X (DEFUN MKMOVE (DEST VAL) (LIST 'MOVE DEST VAL)) X X XListing 3. X X ;;; THE AUXILIARY PROCEDURES X X X (DEFUN FIRST (X) (CAR X)) X (DEFUN REST (X) (CDR X)) X (DEFUN CONCAT (ELEMENT SEQUENCE) X (COND ((LISTP SEQUENCE) X (CONS ELEMENT SEQUENCE)) X (T '()) X ) ) X X (DEFUN APPEND-3 (L1 L2 L3) X (APPEND L1 (APPEND L2 L3)) X ) X X (DEFUN LISP (X) X (COND ((CONSP X) T) X ((NULL X) T) X (T NIL) X ) ) X X X XListing 4. X X STEP INSTRUCTION R1 R2 STACK (Top...Bottom) X ----------------------------------------------------------------- X X 0 ?? ?? --- X 1 (MOVEI 1 (QUOTE A)) A ?? --- X 2 (CALL G) A Return-Address X (G A) ?? --- X 3 (PUSH SP 1) (G A) ?? (G A) X 4 (MOVEI 1 (QUOTE B)) B ?? (G A) X 5 (CALL H) B ?? Return-Address (G A) X (H B) ?? (G A) X 6 (MOVE 2 1) (H B) (H B) (G A) X 7 (POP SP 1) (G A) (H B) --- X 8 (CALL F) (G A) (H B) Return-Address X (F ) ?? --- X X SHAR_EOF if test 5186 -ne "`wc -c < 'compil.feb'`" then echo shar: "error transmitting 'compil.feb'" '(should have been 5186 characters)' fi fi echo shar: "extracting 'contnt.feb'" '(867 characters)' if test -f 'contnt.feb' then echo shar: "will not over-write existing file 'contnt.feb'" else sed 's/^ X//' << \SHAR_EOF > 'contnt.feb' X X X X X Contents -- AI EXPERT X "LISP Special Issue" X February 1987 X X X XARTICLES X XLISP vs. C For Implementing Expert Systems Xby Gerald R. Barber X XMemory Management in LISP Xby Richard P. Gabriel X XCompiling LISP Procedures Xby Bruce A. Pumplin X XAgainst the Tide of Common LISP Xby John R. Allen X X XDEPARTMENTS X XBrain Waves X"The Future of LISP: Stayin' Alive" XGuy Steele, Common LISP Chairman X XAI Insider Xby Susan Shepard X XExpert's Toolbox X"Solving SFRL's Problems with a Representation Language Language" Xby Jonathan Amsterdam X XAI Apprentice X"Using lists in PROLOG" Xby Beverly and Bill Thompson X XIn Practice X"AI Applications" Xby Harvey Newquist X XSoftware Review: X"LISP on the Micro" X echo shar: "15 control characters may be missing from 'contnt.feb'" SHAR_EOF if test 867 -ne "`wc -c < 'contnt.feb'`" then echo shar: "error transmitting 'contnt.feb'" '(should have been 867 characters)' fi fi echo shar: "extracting 'expert.feb'" '(3467 characters)' if test -f 'expert.feb' then echo shar: "will not over-write existing file 'expert.feb'" else sed 's/^ X//' << \SHAR_EOF > 'expert.feb' X X X Expert's Toolbox X "Solving SFRL Problems with a Representation Language Language" X Listing 1 X X X;; FRLL--A Frame Representation Language Language. X;; Copyright 1986 by Jonathan Amsterdam. X(DEFVAR *FRAMES* NIL) ; A list of all the frames ever created (with FPUT or X ; DEFFRAME). X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; X;; Interface functions. X(DEFMACRO DEFFRAME (NAME &REST SLOTS-AND-VALUES) X `(PROGN X (PUSHNEW ',NAME *FRAMES*) ; PUSHNEW adds an item to a list if it X ; isn't already there. X ,@(LET ((RESULT NIL)) X (DO ((S-AND-V SLOTS-AND-VALUES (CDDR S-AND-V))) X ((NULL S-AND-V) (REVERSE RESULT)) X (PUSH `(FPUT ',NAME ',(CAR S-AND-V) ',(CADR S-AND-V)) X RESULT))))) X XDEFMACRO DEF-RAW-FRAME (NAME &REST SLOTS-AND-VALUES) X ; Need this to avoid invoking the full FGET mechanism in defining core X ; frames. X `(PROGN X (PUSHNEW ',NAME *FRAMES*) X ,@(LET ((RESULT NIL)) X (DO ((S-AND-V SLOTS-AND-VALUES (CDDR S-AND-V))) X ((NULL S-AND-V) (REVERSE RESULT)) X (PUSH `(FPUT-ON-FRAME ',NAME ',(CAR S-AND-V) ,(CADR S-AND-V)) X RESULT))))) X(DEFUN FGET (FRAME SLOT) X (OR (FGET-ON-FRAME FRAME SLOT) X (FUNCALL (FGET SLOT 'GET-VALUE) FRAME SLOT))) X XDEFUN FPUT (FRAME SLOT VALUES) X (LET ((FUNCTION (FGET SLOT 'PUT-VALUE))) X (IF FUNCTION XFUNCALL FUNCTION FRAME SLOT VALUES) X(FPUT-ON-FRAME FRAME SLOT VALUES)))) X(DEFUN FGET-ON-FRAME (FRAME SLOT) X (CDR (ASSOC SLOT (GET FRAME 'FRAME)))) X(DEFUN FPUT-ON-FRAME (FRAME SLOT VAL) X (LET ((FRAME-LIST (GET FRAME 'FRAME))) X (LET ((OLD-SLOT (ASSOC SLOT FRAME-LIST))) X (IF OLD-SLOT X (RPLACD OLD-SLOT VAL) X (PUSHNEW FRAME *FRAMES*) X (SETF (GET FRAME 'FRAME) (CONS (CONS SLOT VAL) FRAME-LIST)))))) X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; X;; Functions which live in the initial network X(DEFUN GET-VALUE-FUNCTION (FRAME SLOT) X (N-INHERITANCE FRAME SLOT (FGET SLOT 'INHERITS-THROUGH))) (DEFUN N-INHERITANCE (FRAME SLOT PATH-SLOT) X ;; Returns the first value found, along PATH-SLOT, using N pattern. X (OR (FGET-ON-FRAME FRAME SLOT) X (DOLIST (PARENT (LISTIFY (FGET FRAME PATH-SLOT))) X(LET ((RESULT (N-INHERITANCE PARENT SLOT PATH-SLOT))) X (IF RESULT (RETURN RESULT)))))) X(DEFUN LISTIFY (X) X (IF (NOT (LISTP X)) (LIST X))) X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; X;; Basic core of network. X(DEF-RAW-FRAME FRAME X AKO 'FRAME) X(DEF-RAW-FRAME SLOT X AKO 'FRAME X GET-VALUE 'FGET-ON-FRAME X PUT-VALUE 'FPUT-ON-FRAME) X XDEF-RAW-FRAME N-INHERITANCE-SLOT X SLOT-TYPE 'SLOT X GET-VALUE 'GET-VALUE-FUNCTION) X XDEF-RAW-FRAME GET-VALUE X SLOT-TYPE 'N-INHERITANCE-SLOT X ;; Set GET-VALUE's GET-VALUE slot explicitly to make it all work.! X.. X GET-VALUE 'GET-VALUE-FUNCTION X INHERITS-THROUGH 'SLOT-TYPE) X(DEF-RAW-FRAME PUT-VALUE X SLOT-TYPE 'N-INHERITANCE-SLOT X INHERITS-THROUGH 'SLOT-TYPE) X(DEF-RAW-FRAME SLOT-TYPE X SLOT-TYPE 'SLOT) X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; X;; Network used in example X(DEFFRAME CUISINE X SLOT-TYPE N-INHERITANCE-SLOT X INHERITS-THROUGH RESTAURANT-TYPE) X(DEFFRAME CHINESE-RESTAURANT X CUISINE CHINESE) X(DEFFRAME MARY-CHUNGS X RESTAURANT-TYPE CHINESE-RESTAURANT) X X;;; End of file. SHAR_EOF if test 3467 -ne "`wc -c < 'expert.feb'`" then echo shar: "error transmitting 'expert.feb'" '(should have been 3467 characters)' fi fi echo shar: "extracting 'files.feb'" '(939 characters)' if test -f 'files.feb' then echo shar: "will not over-write existing file 'files.feb'" else sed 's/^ X//' << \SHAR_EOF > 'files.feb' X X X Articles and Departments that have X Additional On-Line Files X X AI EXPERT X February 1987 X (Note: Contents page is in file CONTNT.FEB) X X X X XARTICLES RELEVANT FILES X-------- -------------- X XFebruary Table of Contents CONTNT.FEB X XLISP vs. C For Implementing Expert Systems LISPVC.FEB Xby Gerald R. Barber X XCompiling LISP Procedures COMPIL.FEB Xby Bruce A. Pumplin X X XDEPARTMENTS X XExpert's Toolbox EXPERT.FEB X"Solving SFRL's Problems with a XRepresentation Language Language" Xby Jonathan Amsterdam X XAI Apprentice AIAPP.FEB X"Using lists in PROLOG" Xby Beverly and Bill Thompson X echo shar: "6 control characters may be missing from 'files.feb'" SHAR_EOF if test 939 -ne "`wc -c < 'files.feb'`" then echo shar: "error transmitting 'files.feb'" '(should have been 939 characters)' fi fi echo shar: "extracting 'lispvc.feb'" '(2994 characters)' if test -f 'lispvc.feb' then echo shar: "will not over-write existing file 'lispvc.feb'" else sed 's/^ X//' << \SHAR_EOF > 'lispvc.feb' X X X LISP vs. C X For Implementing Expert Systems X February 1987 X Listings 1 & 2 X XListing 1. X XThis example illustrates several aspects of LISP that Xare useful in building expert systems. Symbols are to represent Xinformation such as room types and as variables to hold specific Xrooms and doors. Lists aggregate related information, doors with Xtheir corresponding rooms. The MAKE-... functions automatically Xallocate the necessary memory to hold the structures. When a Xstructure becomes unaccessible, it is reclaimed by LISP's garbage Xcollector. X X X;;; We will now create a collections of structures that represent X;;; 2 rooms a hall and a bathroom. All halls will open onto the X;;; hall. X X;;; The structure for information about a room. X(defstruct room X type ;the kind of room, eg, BEDROOM X doors-to-rooms ;doors and the rooms they lead to X ) X X;;; The structure for information about a door. X(defstruct door X type ;the type of door X height ;in inches X width :in inches X ) X X;;; Make the hall. X(setf hall (make-room :type 'hall)) ;no connecting rooms yet X X;;; The door from bedroom1 to the hall. X(setf bedroom1-door (make-door :type 'oak :height 72 :width 40)) X X;;; The 1st bedroom with its door to the hall X(setf bedroom1 (make-room :type 'bedroom X :doors-to-rooms (list bedroom1-door X hall))) X X;;; The door from bedroom2 to the hall. X(setf bedroom2-door (make-door :type 'maple :height 72 :width 40)) X X;;; The 2nd bedroom with its door to the hall X(setf bedroom2 (make-room :type 'master-bedroom X :doors-to-rooms (list bedroom2-door X hall))) X X;;; The Bathroom door X(setf bathroom-door (make-door :type 'pine :height 72 :width 40)) X X;;; The bathroom with its door to the hall X(setf bathroom (make-room :type 'bathroom X :doors-to-rooms (list bathroom-door X hall))) X X;;; Now we connect the hall to its corrensponding rooms X(setf (room-doors-to-rooms hall) X (list bathroom-door bathroom X bedroom1-door bedroom1 X bedroom2-door bedroom2)) X X X XListing 2. X;;; An example of the use of a macro. This is from an assembler, X;;; it is used to build the necessary databases to assemble the X;;; JLE and JNG instructions during PASS2 of the assembler. X(PASS2 (JLE JNG) #B01111110 CONDITIONAL-BRANCH) X X;;; This is what the above macro translates into to. As you can X;;; see, the above form is more clear to the reader as well as X;;; easier for the programmer to type. X(PROGN X (SETF (GET 'JNG 'BIT-CODE) '126) X (SETF (GET 'JNG 'PASS2) 'CONDITIONAL-BRANCH) X (SETF (GET 'JLE 'BIT-CODE) '126) X (SETF (GET 'JLE 'PASS2) 'CONDITIONAL-BRANCH)) SHAR_EOF if test 2994 -ne "`wc -c < 'lispvc.feb'`" then echo shar: "error transmitting 'lispvc.feb'" '(should have been 2994 characters)' fi fi exit 0 # End of shell archive -- --------------- C'est la vie, C'est le guerre, C'est la pomme de terre Mail: Imagen Corp. 2650 San Tomas Expressway Santa Clara, CA 95052-8101 UUCP: ...{decvax,ucbvax}!decwrl!imagen!turner AT&T: (408) 986-9400