Starting a Dribble File and Loading a File in xlisp



Download 151.04 Kb.
Date23.04.2018
Size151.04 Kb.

Starting a Dribble File and Loading a File in XLisp


  1. Start a dribble file. In XLisp, click in File, Dribble. You will get a dialog box asking where to save the dribble file and what is to be used as the filename. Below is a sample response. Click Save.


A
fter you save the dribble file, XLisp will be recording your session in a text file. When you exit XLisp, (exit), the dribble file will be closed.


  1. Load some SETQs from the J Drive. There's a file on the J-drive that contains most of the setq's used in the XLisp-stat Lab:

(setq eins 1)

(setq xx 'x)

(setq name 'Smith)

(setq couple "John + Jane Doe")

(setq L1 '(a b c d e))

(setq L2 '(a (b c) d e ))

(setq L3 '((a b c) (d e)))

(Setq L4 '( a (b c) d (e (f g))))

(setq L5 (append L3 L2))


Load this file from the J-drive:
> (load "j:/schaefer/cs325/setqs.lsp")

; loading j:\schaefer\cs325\setqs.lsp

> T  True is displayed if the file was loaded successfully.

> L5  Enter L5 and press enter. List 5 should be displayed as:


((A B C) (D E) A (B C) D E)


  1. Assuming the load from step 2 was successful, you can start the Lisp lab.



XLisp Version 2.0 Lab Name ________________________________________________

Work Left-to-Right (across), then down.
Summary of Symbols Used in the Exercises

(Symbols are NOT case sensitive)

(setq eins 1) eins 1

(setq xx 'x) xx x

(setq y 4.6) 4.6

(setq name 'Smith) name Smith

(setq couple "John + Jane Doe") couple John + Jane Doe

(setq L1 (list 'a 'b 'c 'd 'e )) L1 ( a b c d e )

(setq L2 '( a (b c) d e )) L2 ( a (b c) d e )

(setq L3 '( (a b c) (d e))) L3 ( (a b c) (d e) )

(setq L4 '( a (b c) d ( e ( f g)))) L4 ( a ( b c) d ( e ( f g) ) )

(setq L5 (append L3 L2)) L5 ( (a b c) (d e) a (b c) d e)


Atoms

An "atom" is the basic elementary data item. Syntactically an atom is just an identifier--a string of letters and digits beginning with a letter. An atom is represented by a pointer during execution. The location pointed to contains a special atom data type designator and a pointer to a property list, which contains the various properties associated with the atom. [Pratt75, 422]


  1. (atom t) ____ ; atom is a predicate function

  1. (atom nil) ____

  1. (atom 1) ____

  1. (atom 4.6) ____

  1. (atom eins) ____

  1. (type-of eins) ______________

  1. (atom xx) ____

  1. (type-of xx )

  1. (atom name)

  1. (type-of name)

  1. (atom couple) ____

  1. (type-of couple) ______________

  1. (/ 4 6)

  1. (type-of 4/6))

Some Predicate Functions

  1. (atom (list 1)) ____

  1. (atom ()) ____

  1. (numberp -5)

  1. (numberp 'a)

  1. (boundp name)

  1. (boundp smith)

  1. (stringp name) ____

  1. (stringp couple) ____

  1. (characterp xx) ____

  1. (type-of 4.6) ____


Numeric Atoms

Numbers in integer or floating-point format may be used. The hardware representation is used, but a run-time descriptor is also required, so each number uses two words. A number is an atom with a special type designator and a pointer to the bit string representing the number... [Pratt75, 423-424]
The functions ending with "p" are predicate functions that return T (true), or NIL (false), if the operand has, or doesn't have, that property respectively. [See Betz, 27]


  1. (numberp 1) ____

  1. (numberp eins) ____

  1. (numberp 'w) ____

  1. (numberp nil) ____

  1. (integerp 1) ____

  1. (integerp 1.1) ____

  1. (floatp 1) ____

  1. (floatp 1.1) ____

  1. (evenp 11) ____

  1. (oddp 11) ____

  1. (onep 0) ____

  1. (onep 1) ____

  1. (minusp 1) ____

  1. (minusp -1) ____

  1. (zerop 0) ____

  1. (zerop 1) ____

  1. (plusp 1) ____

  1. (plusp -1) ____

  1. (< 1 2) ____

  1. (< 2 1) ____

  1. (> 1 2) ____

  1. (> 2 1) ____

  1. (truncate 4.3) ____

  1. (truncate 4.999) ____

  1. (truncate -4.3) ____

  1. (truncate -4.9) ____

  1. (+ 2 3) ____

  1. (+ 2 3 4 5 6 7) ____

  1. (+ 2 3.1) ____

  1. (+ 2 -3 4 -5 6 -7) ____

  1. (- 3) ____

  1. (- -3) ____

  1. (- 3 4) ____

  1. (- 18 4 3 9) ____

  1. (1+ 3) ____

  1. (1- 3) ____

  1. (* 3 4) ____

  1. (* 3 4 5 6) ____

  1. (* 3.2 4) ____

  1. (gcd 8 28) ____

  1. (gcd 481 629) ____

  1. (/ 10 3) ____

  1. (/ 33.0 16) ____

  1. (rem 10 3) ____

  1. (/ 100 15.0) ____

  1. (rem 15 3) ____

  1. (/ 6.0 5.0 4.0) ____

  1. (/ 576 4 8 3) ____

  1. (float (/ 3 4)) ____

  1. (/ 3 (float 4)) ____

  1. (expt 2.0 3.0) ____

  1. (expt (float 2) (float 3)) ____

  1. (max 4 1 5 3) ____

  1. (min 4 1 5 3) ____

  1. (= 1 1) ____

  1. (= 1 2) ____

  1. (= (+ 2 3) (- 9 4)) ____

  1. (/= 1 2) ____

  1. (sqrt (float 2)) _________________

  1. (random 997) ____

  1. (abs -5) ____

  1. ( ^ 3 4)

Logical Operators

  1. (not nil) ___

  1. (not t) ____

  1. (not 1) ____

  1. (not (list 1)) ____

  1. (and t t ) ____

  1. (or t t ) ____

  1. (and t nil) ____

  1. (or t nil) ____

  1. (and nil t ) ____

  1. (or nil t ) ____

  1. (and nil nil) ____

  1. Interchange with XOR: (setq x -6 z 15)
    (setq x (logxor x z))
    (setq z (logxor x z ))
    (setq x (logxor x z))


  1. (and) ____

  1. (or) ____

  1. (not) ____

Lists

Lists are simple singly linked structures. Each list element contains a pointer to a data item and a pointer to the following list element. The last list element points to the special atom NIL as its successor. The two pointers in a list element are termed the CAR pointer and CDR pointer. The CAR pointer points to the data item [Contents of the Address part of Register]. The CDR pointer points to the successor of the list element [Contents of the Decrement part of Register]. Pratt75, 424.

  1. (list 1 2) ____________

  1. (list 1 2 3 4) ____________

  1. (list 1 2 2 2) ____________

  1. (list eins)

  1. (list) ____________

  1. (list nil) ____________

  1. (list ()) ____________

  1. (list () 1 2) ____________

  1. (list 1 (list 2)) ____________

  1. (list (list (list 1) 2) 3) ____________

  1. (list 1 (list 2 (list 3))) ____________

  1. (list eins xx name) _____________________

  1. (setq L1 (list 'a 'b 'c 'd 'e ))

  1. (setq L2 '(a ( b c ) d e ) )

  1. (list L1 L2)

  1. (list L2) ________

  1. (list (list 1 2))

  1. (list nil)

  1. (null nil)

  1. (null (list))

  1. (null ())

  1. (null L1)

  1. (null (list 1))

  1. (eq nil (list))

  1. (eq L1 L2)

List Selectors: CAR and CDR (See notes above.)

  1. (car nil) ________

  1. (car 1) ________

  1. (car (list 1 2)) ________

  1. (cdr (list 1 2)) ________

  1. (car L1) ________

  1. (cdr L1) ________

  1. (setq L3 '( (a b c) (d e))) __________

  1. (setq L4 '(a (b c) d (e (f g) ) ) ) ______________

  1. (car L3) ________

  1. (car L4) ________

  1. (car (car L3)) ________

  1. (caar L3) ________

  1. (car (cdr L3)) ________

  1. (cadr L3) ________

  1. (cadr L4) ________

  1. (cddar L3) ________

  1. (caadr L4) ________

  1. (cdadddr L4) ________

List Construction: CONS, APPEND, and DOT Notation

"cons takes two pointers as operands, allocates a new list element memory word, stores the two pointers in the CAR and CDR fields of the word, and returns a pointer to the new word." [Pratt84, 507].


cons

Nil

Atom2

List2

Nil

1 (Nil)

4 (Nil . Atom2)

7 (Nil List-2 w/o( ) )

Atom1

2 (Atom1)

5 (Atom1 . Atom2)

8 (Atom1 List-2)

List1

3 (List1)

6 (List1 . Atom2)

9 ((List1) List-2)

1. (cons nil nil) ==> (nil) 4. (cons nil 2) ==> (nil . 2)

2. (cons 1 nil) ==> (1) 5. (cons 1 2) ==> (1 . 2)

3. (cons (list 1) nil) ==> ((1)) 6. (cons (list 1) 2) ==> ((1) . 2)

7. (cons nil (list 2)) ==> (nil 2)

8. (cons 1 (list 2)) ==> (1 2)

9. (cons (list 1) (list 2)) ==> ((1) 2)

(cons '( (1 2) 3 4) '(5 (6 7)) ) ==>9 ( ((1 2) 3 4) 5 (6 7))

(cons (cons 1 nil) (cons 2 nil)) ==>2 (cons (1) (2))

==>9 ((1) 2)

(cons 1 (cons 2 nil)) ==>4 (cons 1 (2)) ==>6 (1 2)

(cons (car L) (cdr L)) ==> L



  1. (cons 1 nil) __________

  1. (Observe . spacing!) '(1 . nil) __________

  1. (cons 1 2) __________

  1. '(1 . 2) __________

  1. (cons nil 2) __________

  1. '(nil . 2) __________

  1. (cons nil nil) __________

  1. '(nil . nil) __________

  1. (atom (cons 1 2)) ______

  1. (listp (cons 1 2)) ______

  1. (car (cons 1 2)) __________

  1. (car (list 1 2)) __________

  1. (cdr (cons 1 2)) __________

  1. (cdr (list 1 2)) __________

  1. (cons nil (list 2)) __________

  1. '(nil . (2)) __________

  1. (cons 1 (list 2)) __________

  1. '(1 . (2)) __________

  1. (cons 1 (list 2 3)) __________

  1. '(1 . (2 3)) __________

  1. (cons (list 1) nil) __________

  1. '((1) . nil) __________

  1. (cons (list 1) 2) __________

  1. '((1) . 2) __________

  1. (cons 1 (cons 2 nil)) __________

  1. (cons 1 (cons 2 (cons 3 nil))) __________

  1. '(1 . (2 . (3 . nil))) __________

  1. '(((1 . 2) . 3) . nil) __________

  1. '((1 . nil) . (2 . nil)) __________

  1. '((1 . nil) . ((2 . nil) . nil)) __________

  1. (cons L1 L2) ____________________

  1. (cons L2 L1) ____________________

  1. (length (cons L1 L2)) ____

  1. (length (cons L2 L1)) ____

  1. (append L1 L2) ____________________

  1. (list L1 L2) _____________________

  1. (append L1 nil) __________

  1. (append nil L1) __________

  1. (append 1 L3) __________

  1. (append L3 5) __________

  1. (cons 1 L3) __________

  1. (cons L3 5) __________

  1. (append L1 L4) ____________________

  1. (append L4 L1) ____________________

  1. (setq L5 (append L3 L2)) _________________________________________________________

Property Lists Associated with Atoms

A property list is an ordinary list with elements that are logically paired in alternating property name -- property value sequence. Pratt75, 425.


  1. (setq cat 'cat) ____________

  1. (putprop cat 'katie 'name) ____________

  1. (putprop cat 'grey 'color) ____________

  1. (putprop cat 4 'legs) ____________

  1. (putprop cat 'yes 'tail) ____________

  1. (symbol-plist cat) ___________________________________________________

  1. (get cat 'color) ____________

  1. (remprop cat 'tail) ____

  1. (symbol-plist cat) ___________________________________________________

User Functions

(defun first (L) (car L)) ;This is a comment.

; Define first, one parameter: L




  1. (first L1) ________

  1. (first L2) ________

  1. (first (list (list (list 1 2 ) 3) 4 5)) ________

  1. (load "pp")

  1. (pp-def first)

  1. (defun rest (L) (cdr L))

  1. (rest L1) ________________

  1. (rest L2) ________________


(defun len (L) ;Find the length of a list. ; Alternate, recursive definition

(cond (defun len (L)

( (null L) 0) (cond ( (null L) 0)

( (not (cdr L)) 1) ( T (+ 1 (len (cdr L))))

( (not (cddr L)) 2) )

( t (quote long)) )

)

)



  1. (len ()) ____

  1. (len (list 1)) ____

  1. (len '(a b)) ____

  1. (len L1) ____


(defun average (x y) ; x, y are local; sum is nonlocal

(setq sum (+ x y))

(/ sum 2)

)

  1. sum ____

  1. (average 9 37) ____

  1. sum ____

  1. x ____ y ____

  1. (average 11 12) ____

  1. (average 11.0 12) ____


(defun factorial (N) ; A non-recursive function

(prog (y) ; local variable y, unknown outside of factorial

( cond ; check for possible problems



( (not (numberp N)) (return NIL) ) ; N is not numeric

( (minusp N) (return NIL) ) ; N is negative

( (not (integerp N)) (return NIL) ) ; N is float

) ; remaining N's are nonnegative integers

(setq y 1) ; initialize Y

fetch ; a label for a later goto

(cond ( (zerop N) (return y))) ; return condition, N = 0

(setq y (* y N )) ; next product

(setq N (1- N)) ; reduce N by 1

(go fetch) ; repeat

) )

  1. (factorial 0)

  1. (factorial 1)

  1. (factorial 4)

  1. (factorial 10)

  1. (factorial 'A)

  1. (factorial '(1 2))

  1. (factorial -7)

  1. (factorial 3.7)

(defun fact (n) ; recursive factorial

(cond ((= n 1) 1)

( T (* n (fact (- n 1))))

)

)



Miscellaneous

  1. (setq x '(1 2 3)) ________

  1. (setq y (cdr x)) ________

  1. (setq w y) ________

  1. (setq z '(2 3)) ________

  1. (eq w y) ________

  1. (= y z) ____

  1. (eq y z) ____

  1. (type-of nil) ________

  1. (type-of eins) ________

  1. (type-of name) ________

  1. (type-of couple) ________

  1. (type-of L1) ________

  1. (room) ;Show memory allocation statistics

  1. ; this is a comment

  1. (dribble "a:filename.txt") ;Start recording in a file

  1. (gc) ;Force garbage collection

  1. (room)

  1. (dribble) ;Stop recording in the file

  1. (exit) ; get out of XLISP







References

[Betz] Betz, David. XLISP: An Object-oriented Lisp, Version 2.0. Peterborough, NH: David Betz, 6 Feb 1988.

[Fladung] Fladung, Bonnie J. The XLISP Primer. Englewood-Cliffs, NJ: Prentice-Hall, 1987.

[Friedman] Friedman. Little LISPer. [QA76.73/L23/F74].

[Pratt84] Pratt, Terrence W. Programming Language Design and Implementation, Second Edition. Englewood-Cliffs, NJ: Prentice-Hall, 1984. [QA76.7/P7].

[Sebesta97] Sebesta, Robert W. Concepts of Programming Languages, 3rd Ed. Reading, MA: Addison-Wesley, 1997, pp. 503-506. 6th Ed:584, much of Scheme material, 587-603.

[Wilensky] Wilensky, Robert. Common LISPcraft. New York: W. W. Norton and Company, 1986.

[Winston] Winston, Patrick H. and Horn, B. H. LISP. Reading, MA: Addison-Wesley, 1981. [QA76.73/L23/W56].

  • newLISP "newLISP is a general purpose scripting language for developing web applications and programs in general and in the domain of artificial intelligence (AI) and statistics."

  • U of Minnesota Statistics Software

  • XLisp-Stat Information University of Minn., Luke Tierney

  • XLISP Home Page David Betz started all this a long time ago and he has an object based, XLisp 3.0, but needs to be built with .Net and I still can't find out how to run it. 

  • XLISP-PLUS Home Page Tom Almy's version of XLisp

  • The Eternal Flame, Lyrics The Eternal Flame recording



Share with your friends:


The database is protected by copyright ©ininet.org 2019
send message

    Main page