Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cvl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!rlgvax!cvl!jcw From: jcw@cvl.UUCP (Jay C. Weber) Newsgroups: net.sources Subject: XLISP, part 1 of 4 Message-ID: <1189@cvl.UUCP> Date: Fri, 20-Jul-84 11:05:30 EDT Article-I.D.: cvl.1189 Posted: Fri Jul 20 11:05:30 1984 Date-Received: Mon, 23-Jul-84 01:30:21 EDT Organization: U. of Md. Computer Vision Lab Lines: 839 This is the fairly portable C implementation of XLISP that I mentioned a little while ago. I received literally dozens of replies voicing interest, and only one snide message asking me not to post it. So here it is, written by David Betz, who I believe works for DEC and may be on the net. If you have any sort of system that has a C compiler and not LISP, give this a look over. It has been written pretty nicely, and is rumored to have been successfully ported to a number of systems, including an Apple with Aztec C, an IBM PC with CI-C86, a Vax 11/780 with Berkeley Unix, etc. (although I only have experrience with getting it going with CI-C86 and Unix). This portion contains a sample Unix Makefile, code for LONGJMP on an IBM PC under CI-C86, and the XLISP document (already roffed). Tear at the dotted line and run sh(1) over it. Jay Weber ..!seismo!rlgvax!cvl!jcw ..!seismo!rochester!jay jay@rochester.arpa P.S. My posting this does not mean that I support it. Problems with it would be more appropriately addressed to the author, although I don't know the whereabouts or disposition of him. ----------------------------------------------------- : Run this shell script with "sh" not "csh" PATH=:/bin:/usr/bin:/usr/ucb export PATH /bin/echo 'Extracting Makefile' sed 's/^X//' <<'//go.sysin dd *' >Makefile X# X# Makefile for David Betz' XLISP interpreter X# XCFLAGS = -I. -Dunix -O X XOBJS=xlisp.o xldmem.o xleval.o xlread.o xlio.o xlprin.o xlbind.o xlstr.o\ X xlfio.o xlsubr.o xlfmath.o xllist.o xlobj.o xlkmap.o xldebug.o X Xxlisp :$(OBJS) X cc -o xlisp $(OBJS) //go.sysin dd * /bin/chmod 664 Makefile /bin/echo -n ' '; /bin/ls -ld Makefile /bin/echo 'Extracting longjmp.asm' sed 's/^X//' <<'//go.sysin dd *' >longjmp.asm X XCODE SEGMENT BYTE PUBLIC X ASSUME CS:CODE X X PUBLIC setjmp, longjmp X Xsetjmp PROC NEAR X X POP AX ; Fetch return address from stack X POP BX ; Buffer pointer X X MOV [BX],BP ; Save BP X MOV [BX+2],SP ; , SP at return X MOV [BX+4],AX ; and IP X X PUSH BX ; Restore stack X PUSH AX X RET X Xsetjmp ENDP X X Xlongjmp PROC NEAR X X POP AX X POP BX X MOV BP,[BX] X MOV SP,[BX+2] X PUSH AX X X MOV AX,[BX+4] X JMP AX X Xlongjmp ENDP X XCODE ENDS X END //go.sysin dd * /bin/chmod 664 longjmp.asm /bin/echo -n ' '; /bin/ls -ld longjmp.asm /bin/echo 'Extracting xlisp.doc' sed 's/^X//' <<'//go.sysin dd *' >xlisp.doc X X X X X XLISP: An Experimental Object Oriented Language X X X by X David Betz X 114 Davenport Ave. X Manchester, NH 03103 X X (603) 625-4691 X X X XLISP is an experimental programming language combining some X of the features of LISP with an object oriented extension X capability. It was implemented to allow experimentation X with object oriented programming on small computers. There X are currently implementations running on the PDP-11 under X RSX-11, RT-11, and UNIX V7, on the VAX-11 under VAX/VMS and X Berkeley VAX/UNIX and on the Z-80 running CP/M-80. It is X completely written in the programming language 'C' and is X believed to be easily extended with user written builtin X functions and classes. It is available free of charge and X is in the public domain. X X Many traditional LISP functions are built into XLISP. In X addition, XLISP defines the object classes 'Object', X 'Class', and 'Keymap' as primitives. 'Object' is the only X class that has no superclass and hence is the root of the X class heirarchy tree. 'Class' is the class of which all X classes are instances (it is the only object that is an X instance of itself). 'Keymap' is a class whose instances X are mappings from input key sequences to messages. X X This document is intended to be a brief description of X XLISP. It assumes some knowledge of LISP and some X understanding of the concepts of object oriented X programming. X X XLISP: An Experimental Object Oriented Language Page 2 X XLISP Command Loop X X X When XLISP is started, it issues the following prompt: X X > X X This indicates that XLISP is waiting for an expression to be X typed. When an incomplete expression has been typed (one X where the left and right parens don't match) XLISP changes X its prompt to: X X n> X X where n is an integer indicating how many levels of parens X remain unclosed. X X When a complete expression has been entered, XLISP attempts X to evaluate that expression. If the expression evaluates X successfully, XLISP prints the result of the evaluation and X then returns to the initial prompt waiting for another X expression to be typed. X X Input can be aborted at any time by typing the EOF key. X Another EOF will exit from XLISP. X X XLISP: An Experimental Object Oriented Language Page 3 X DATA TYPES AND THE EVALUATOR X X X XLISP data types X X There are several different data types available to XLISP X programmers. X X X o symbols X X o strings X X o integers X X o objects X X o file pointers X X o lists X X o subrs (builtin functions) X X X The XLISP evaluator X X The process of evaluation in XLISP: X X o Integers, strings, objects, file pointers, and X subrs evaluate to themselves X X o Symbols evaluate to the value associated with their X current binding X X o Lists are evaluated by evaluating the first element X of the list X X o If it evaluates to a subr, the builtin function X is executed using the remaining list elements X as arguments (they are evaluated by the subr X itself) X X o If it evaluates to a list, the list is assumed X to be a function definition and the function is X evaluated using the values of the remaining X list elements as arguments X X o If it evaluates to an object, the second list X element is evaluated and used as a message X selector. The message formed by combining the X selector with the values of the remaining list X elements is sent to the object. X X X X XLISP: An Experimental Object Oriented Language Page 4 X LEXICAL CONVENTIONS X X X XLISP lexical conventions: X X The following conventions are followed when entering XLISP X programs: X X Comments in XLISP code begin with a semi-colon character and X continue to the end of the line. X X Symbol names in XLISP can consist of any sequence of X non-blank printable characters except the following: X X ( ) . ' " ; X X Symbol names must not begin with a digit. X X Integer literals consist of a sequence of digits optionally X beginning with a '+' or '-'. The range of values an integer X can represent is limited by the size of a C 'int' on the X machine that XLISP is running on. X X Literal strings are sequences of characters surrounded by X double quotes. Within quoted strings the '\' character is X used to allow non-printable characters to be included. The X codes recognized are: X X \\ means the character '\' X \n means newline X \t means tab X \r means return X \e means escape X \nnn means the character whose octal code is nnn X X The single quote character can be used as a shorthand for a X call on the function 'quote': X X 'foo X is equivalent to: X (quote foo) X X XLISP: An Experimental Object Oriented Language Page 5 X OBJECTS X X X Objects: X X Definitions: X X o selector - a symbol used to select an appropriate X method X X o message - a selector and a list of actual arguments X X o method - the code that implements a message X X Since XLISP was created to provide a simple basis for X experimenting with object oriented programming, one of the X primitive data types included was 'object'. In XLISP, an X object consists of a data structure containing a pointer to X the object's class as well as a list containing the values X of the object's instance variables. X X Officially, there is no way to see inside an object (look at X the values of its instance variables). The only way to X communicate with an object is by sending it a message. When X the XLISP evaluator evaluates a list the value of whose X first element is an object, it interprets the value of the X second element of the list (which must be a symbol) as the X message selector. The evaluator determines the class of the X receiving object and attempts to find a method corresponding X to the message selector in the set of messages defined for X that class. If the message is not found in the object's X class and the class has a super-class, the search continues X by looking at the messages defined for the super-class. X This process continues from one super-class to the next X until a method for the message is found. If no method is X found, an error occurs. X X When a method is found, the evaluator binds the receiving X object to the symbol 'self', binds the class in which the X method was found to the symbol 'msgclass', and evaluates the X method using the remaining elements of the original list as X arguments to the method. These arguments are always X evaluated prior to being bound to their corresponding formal X arguments. The result of evaluating the method becomes the X result of the expression. X X XLISP: An Experimental Object Oriented Language Page 6 X OBJECTS X X X Classes: X X Object THE TOP OF THE CLASS HEIRARCHY X X Messages: X X print THE DEFAULT OBJECT PRINT ROUTINE X returns the object X X show SHOW AN OBJECT'S INSTANCE VARIABLES X returns the object X X class RETURN THE CLASS OF AN OBJECT X returns the class of the object X X isnew THE DEFAULT OBJECT INITIALIZATION ROUTINE X returns the object X X sendsuper [...] SEND SUPERCLASS A MESSAGE X the message selector X the message arguments X returns the result of sending the message X X X Class THE CLASS OF ALL OBJECT CLASSES (including itself) X X Messages: X X new CREATE A NEW INSTANCE OF A CLASS X returns the new class object X X isnew [] INITIALIZE A NEW CLASS X the superclass X returns the new class object X X answer ADD A MESSAGE TO A CLASS X the message symbol X the formal argument list X this list is of the form: X (... [/ ...]) X where X a formal argument X a local variable X a list of executable expressions X returns the object X X ivars DEFINE THE LIST OF INSTANCE VARIABLES X the list of instance variable symbols X returns the object X X cvars DEFINE THE LIST OF CLASS VARIABLES X the list of class variable symbols X returns the object X X XLISP: An Experimental Object Oriented Language Page 7 X OBJECTS X X X When a new instance of a class is created by sending the X message 'new' to an existing class, the message 'isnew' X followed by whatever parameters were passed to the 'new' X message is sent to the newly created object. X X When a new class is created by sending the 'new' message to X the object 'Class', an optional parameter may be specified X indicating of which class the newly generated class is to be X a subclass. If this parameter is omitted, the new class X will be a subclass of 'Object'. X X Example: X X ; create 'Foo' as a subclass of 'Object' X (setq Foo (Class 'new)) X X ; create 'Bar' as a subclass of 'Foo' X (setq Bar (Class 'new Foo)) X X A class inherits all instance variables, class variables, X and methods from its super-class. X X XLISP: An Experimental Object Oriented Language Page 8 X OBJECTS X X X The 'Keymap' Class: X X A keymap is data structure that translates a sequence of X keystrokes into a message. X X In order to create a keymap: X X (setq km (Keymap 'new)) X X In order to add a key definition to a keymap (km): X X (km 'key "\eA" 'up) X (km 'key "\eB" 'down) X (km 'key "\eC" 'right) X (km 'key "\eD" 'left) X X Executing a keymap: X X (setq env (list ob1 ob2 ob3 ob4)) X (km 'process env) X X When the process message is sent, its method enters a X character input loop calling kbin to get single unechoed X characters from the keyboard. When a sequence of characters X is found that matches one of the sequences defined in a key X function call, the corresponding message is sent. The X method tries to send the message to each of the objects in X the environment list. It stops when it finds an object that X knows how to answer the message. Along with the message X selector given in the key definition, the sequence of X matched characters is passed as a single string parameter. X X Keymap X X new CREATE A NEW KEYMAP X returns a new keymap X X isnew INITIALIZE THE NEW KEYMAP X returns the keymap X X key ADD A KEY DEFINITION TO A KEYMAP X the string defining the key X the symbol for the message X returns the keymap X X process PROCESS INPUT USING A KEYMAP X list of active objects X returns the keymap when a message evaluates to nil X X XLISP: An Experimental Object Oriented Language Page 9 X SYMBOLS X X X Symbols: X X X o self - the current object (within a message X context) X X o msgclass - the class in which the current method X was found X X o currentenv - the environment list for the current X invocation of kmprocess X X o oblist - the object list X X X XLISP: An Experimental Object Oriented Language Page 10 X FUNCTIONS X X X Utility functions: X X (load ) LOAD AN XLISP SOURCE FILE X the filename string X returns the filename X X (mem) SHOW MEMORY ALLOCATION STATISTICS X returns nil X X (gc) FORCE GARBAGE COLLECTION X returns nil X X (alloc ) CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT X the number of nodes to allocate X returns the old number of nodes to allocate X X (expand ) EXPAND MEMORY BY ADDING SEGMENTS X the number of segments to add X returns the number of segments added X X XLISP: An Experimental Object Oriented Language Page 11 X FUNCTIONS X X X Functions: X X (eval ) EVALUATE AN XLISP EXPRESSION X the expression to be evaluated X returns the result of evaluating the expression X X (set ) SET THE VALUE OF A SYMBOL X the symbol being set X the new value X returns the new value X X (setq ) SET THE VALUE OF A SYMBOL X the symbol being set (quoted) X the new value X returns the new value X X (print ...) PRINT A LIST OF VALUES X the expressions to be printed X returns nil X X (princ ...) PRINT A LIST OF VALUES WITHOUT QUOTING X the expressions to be printed X returns nil X X (quote ) RETURN AN EXPRESSION UNEVALUATED X or X ' X the expression to be quoted (quoted) X returns unevaluated X X (if [ ]) EXECUTE EXPRESSIONS CONDITIONALLY X test expression X expression evaluated if texpr is non-nil or non-zero X expression evaluated if texpr is nil or zero X returns the value of the expression evaluated X X (while ...) ITERATE WHILE AN EXPRESSION IS TRUE X test expression evaluated at start of each iteration X expressions evaluated as long as evaluates to X non-nil or non-zero X returns the result of the last expression evaluated X X (repeat ...) ITERATE USING A REPEAT COUNT X integer expression indicating the repeat count X expressions evaluated times X returns the result of the last expression evaluated X X (foreach ...) ITERATE FOR EACH ELEMENT IN A LIST X symbol to assign each list element to (quoted) X list to iterate through X expressions evaluated for each element in the list X returns the result of the last expression evaluated X X XLISP: An Experimental Object Oriented Language Page 12 X FUNCTIONS X X X (defun ...) DEFINE A NEW FUNCTION X symbol to be defined (quoted) X list of formal arguments (quoted) X this list is of the form: X (... [/ ...]) X where X is a formal argument X is a local variable X expressions constituting the body of the X function (quoted) X returns the function symbol X X (cond ...) EVALUATE CONDITIONALLY X pair consisting of: X ( ) X where X is a predicate expression X is evaluated if the predicate X is not nil X returns the value of the first expression whose predicate X is not nil X X (exit) EXIT XLISP X returns never returns X X XLISP: An Experimental Object Oriented Language Page 13 X FUNCTIONS X X X I/O Functions: X X (fopen ) OPEN A FILE X the file name string X the open mode string X returns a file pointer X X (fclose ) CLOSE A FILE X the file pointer X returns nil X X (getc []) GET A CHARACTER FROM A FILE X the file pointer (default is stdin) X returns the character (integer) X X (putc []) PUT A CHARACTER TO A FILE X the character to put (integer) X the file pointer (default is stdout) X returns the character (integer) X X (fgets []) GET A STRING FROM A FILE X the file pointer (default is stdin) X returns the input string X X (fputs []) PUT A STRING TO A FILE X the string to output X the file pointer (default is stdout) X returns the string X X XLISP: An Experimental Object Oriented Language Page 14 X FUNCTIONS X X X String Functions: X X (strcat ...) CONCATENATE STRINGS X string expressions X returns result of concatenating the strings X X (strlen ) COMPUTE THE LENGTH OF A STRING X the string expression X returns the length of the string X X (substr []) RETURN SUBSTRING X string expression X starting position X optional length (default is rest of string) X returns substring starting at for X X (ascii ) NUMERIC VALUE OF CHARACTER X string expression X returns numeric value of first character (according to ASCII) X X (chr ) CHARACTER EQUIVALENT OF ASCII VALUE X numeric expression X returns one character string with ASCII equivalent of X X (atoi ) CONVERT AN ASCII STRING TO AN INTEGER X string expression X returns the integer value of the string expression X X (itoa ) CONVERT AN INTEGER TO AN ASCII STRING X integer expression X returns the string representation of the integer value X X XLISP: An Experimental Object Oriented Language Page 15 X FUNCTIONS X X X List Functions: X X (head ) RETURN THE HEAD ELEMENT OF A LIST X or X (car the list X returns the first element of the list X X (tail ) RETURN THE TAIL ELEMENTS OF A LIST X or X (cdr ) X the list X returns the list minus the first element X X (list ...) CREATE A LIST OF VALUES X evaluated expressions to be combined into a list X returns the new list X X (nth ) RETURN THE NTH ELEMENT OF A LIST X the number of the element to return X the list to return the nth element of X returns the nth element or nil if the list isn't that long X X (append ...) APPEND LISTS X lists whose elements are to be appended X returns the new list X X (cons ) CONSTRUCT A NEW LIST ELEMENT X becomes the head (car) of the new list X becomes the tail (cdr) of the new list X returns the new list X X (null ) CHECKS FOR AN EMPTY LIST X the list to check X returns t if the list is empty, nil otherwise X X (atom ) CHECKS FOR AN ATOM (ANYTHING THAT ISN'T A LIST) X the expression to check X returns t if the value is an atom, nil otherwise X X (listp ) CHECKS FOR A LIST X the expression to check X returns t if the value is a list, nil otherwise X X XLISP: An Experimental Object Oriented Language Page 16 X FUNCTIONS X X X (type ) RETURNS THE TYPE OF THE EXPRESSION X the expression to return the type of X returns nil if the value is nil otherwise one of the symbols: X SYM for symbols X OBJ for objects X LIST for list nodes X KMAP for keymap nodes X SUBR for internal subroutine nodes X STR for string nodes X INT for integer nodes X FPTR for file pointer nodes X X (eq ) CHECKS FOR THE EXPRESSIONS BEING THE SAME X the first expression X the second expression X returns t if they are equal, nil otherwise X X (equal ) CHECKS FOR THE EXPRESSIONS BEING EQUAL X the first expression X the second expression X returns t if they are equal, nil otherwise X X (read [ ]) READ AN XLISP EXPRESSION X the string to use as input (optional) X returns the expression read X X (reverse ) REVERSE A LIST X the list to reverse X returns a new list in the reverse order X X (length ) FIND THE LENGTH OF A LIST X the list to find the length of X returns the length X X XLISP: An Experimental Object Oriented Language Page 17 X FUNCTIONS X X X Arithmetic Functions: X X (+ ...) ADD A LIST OF VALUES X expressions to be added X returns the result of the addition X X (- ...) SUBTRACT A LIST OF VALUES X expressions to be subtracted X returns the result of the subtraction X X (* ...) MULTIPLY A LIST OF VALUES X expressions to be multiplied X returns the result of the multiplication X X (/ ...) DIVIDE A LIST OF VALUES X expressions to be divided X returns the result of the division X X (% ...) MODulus A LIST OF VALUES X expressions to be MODulused X returns the result of mod X X (& ...) THE BITWISE AND OF A LIST OF VALUES X expressions to be ANDed X returns the bit by bit ANDing of expressions X X (| expressions to be ORed X returns the bit by bit ORing of expressions X X (~ ) THE BITWISE NOT OF A VALUE X expression to be NOTed X returns the bit by bit inversion of expression X X (min ...) THE SMALLEST OF A LIST OF VALUES X expressions to be checked X returns the smallest value of the list X X (max ...) THE LARGEST OF A LIST OF VALUES X expressions to be checked X returns the largest value of the list X X (abs ) THE ABSOLUTE VALUE OF AN EXPRESSION X integer expression X returns the absolute value of the expression X X XLISP: An Experimental Object Oriented Language Page 18 X FUNCTIONS X X X Boolean Functions: X X (&& ...) THE LOGICAL AND OF A LIST OF VALUES X expressions to be ANDed X returns the result of anding the expressions X (evaluation of expressions stops after the first X expression that evaluates to false) X X (|| ...) THE LOGICAL OR OF A LIST OF VALUES X expressions to be ORed X returns the result of oring the expressions X (evaluation of expressions stops after the first X expression that evaluates to true) X X (! ) THE LOGICAL NOT OF A VALUE X expression to be NOTed X return logical not of X X XLISP: An Experimental Object Oriented Language Page 19 X FUNCTIONS X X X Relational Functions: X X The relational functions can be used to compare integers and X strings. The functions '==' and '!=' can also be used to X compare other types. The result of these comparisons is X computed the same way as for 'eq'. X X (< ) TEST FOR LESS THAN X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with X X (<= ) TEST FOR LESS THAN OR EQUAL TO X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with X X (== ) TEST FOR EQUAL TO X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with X X (!= ) TEST FOR NOT EQUAL TO X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with X X (>= ) TEST FOR GREATER THAN OR EQUAL TO X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with X X (> ) TEST FOR GREATER THAN X the left operand of the comparison X the right operand of the comparison X returns the result of comparing with //go.sysin dd * /bin/chmod 664 xlisp.doc /bin/echo -n ' '; /bin/ls -ld xlisp.doc