Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon.

Similar presentations


Presentation on theme: "Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon."— Presentation transcript:

1 Lisp Laboratory gcLisp (Golden Common Lisp)

2 Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon had developed “list processing” and created IPL (Information Processing Language), abstract for manipulated symbols and list. When FORTRAN had build, McCarthy designed a new languae, LISP ( List Processor), drew on idea from IPL, FORTRAN and FLPL, run on IBM704 In the 1970s Guy Steele and Gerald Sussman defined Scheme, combined Algol and Lisp.

3 Lect. ratchadaporn kanawong3 The history of Lisp By the early 1980s, there were dozens of incompatible Lisp. A project to define a Common Lisp that would merge the best feature of existing dialects into a coherent whole. The first edition of the Common Lisp standard appeared in 1984. Many idea in programming systems such as interpreted and compiled function, garbage collection, recursive function calls, source-level tracing and debugging, and syntax-directed editors.

4 Lect. ratchadaporn kanawong4 Installation Download GC-Lisp from web of course Double click for unzip file Extract at “C:\” Appear dialog, creating folder “C:\GCLisp” Answer OK

5 Lect. ratchadaporn kanawong5 Startup gclisp Click start bottom and click run and type, or Double Click Gclisp.exe for loading in “C:\gclisp” directory

6 Lect. ratchadaporn kanawong6 GC-LISP Environment You will see window of GCLISP as

7 Lect. ratchadaporn kanawong7 Some Command:Hot Key -H to get help -E to enter the LISP Explorer -E to enter the editor to exit editor into Lisp Environment to load a file into the editor to save a file to save a file as another name

8 Lect. ratchadaporn kanawong8 Command line Type these command follow symbol “*”

9 Lect. ratchadaporn kanawong9 Prefix command All command is in parentheses ( ) It will evaluate when we type “)” Command form in term prefix (function )

10 Lect. ratchadaporn kanawong10 GMAC editor window Press -E for getting GMAC editor to save file and back gcLisp

11 Lect. ratchadaporn kanawong11 Load file into gclisp environment Load first.lsp * (load ‘first)

12 Lect. ratchadaporn kanawong12 Functions and data The term data means information such as Numbers Words Lists of things The function operates on the data in some way and the result is output

13 Lect. ratchadaporn kanawong13 Functions Box Function on Data Function data result + 2 5 3

14 Lect. ratchadaporn kanawong14 A table function in lisp +Adds two numbers -Subtracts the second from the first *Multiplies two nubmers /Divides the first by the second ABSAbsolute value of a number

15 Lect. ratchadaporn kanawong15 SYMBOLs Symbols are another type of data in Lisp It is more interesting than numbers Symbols are named English words Phrases Common abbreviations Symbol may be letters, number, and special characters such as hyphen(-)

16 Lect. ratchadaporn kanawong16 EXERCISE Following : symbol or number AARDVARD 87 1-2-3-GO 3.12 7-11 22/7 -12

17 Lect. ratchadaporn kanawong17 THE SPECIAL SYMBOLs Two Lisp symbols have special meaning attached to them. TTruth, “yes” NILFalsity, emptiness, “no” ***NIL can express by ( )

18 Lect. ratchadaporn kanawong18 Some Predicate A predicate is a question-answering function (likely yes-or-no question) Two predicate : NUMBERP (number predicate) to check whether expression is number SYMBOLP (symbol predicate) to check whether expression is symbol

19 Lect. ratchadaporn kanawong19 Test Predicates Type following this screen

20 Lect. ratchadaporn kanawong20 More Predicates ZEROPto check zero ODDPto check odd number EVENPto check even number <to compare first < second >to compare first > second EQUALto compare first = second NOTto opposite

21 Lect. ratchadaporn kanawong21 Test Predicate * (ZEROP 0) * (ZEROP 5) * (ODDP 1) * (ODDP 2) * (EVENP 1) * (EVENP 2) * (< 2 1) * (> 2 1) * (EQUAL 1 (- 3 2)) * (NOT NIL)

22 Lect. ratchadaporn kanawong22 Set variable Binding free variables Sets variable to the value or the expression by (setq variable ) * (setq x 5) * (setq a ‘(1 2 3 x y z)) * (setq b ‘(red green blue))

23 Lect. ratchadaporn kanawong23 Lists LISP is named from LISt Processor Lists are central data type, the most versatile data type Lists are important because they can be made to represent practically anything: sets, tables, and graphs and even English sentences.

24 Lect. ratchadaporn kanawong24 Example of Lists (RED GREEN BLUE) (2 3 5 7 11 13 17 19) (Lisp is powerful) RED GREENBLUE NIL

25 Lect. ratchadaporn kanawong25 NESTED LISTs A list may contain other lists as elements Given the three lists (BLUE SKY) (GREEN GRASS) (BROWN EARTH) Make list that consists of the above lists ((BLUE SKY) (GREEN GRASS) (BROWN EARTH))

26 Lect. ratchadaporn kanawong26 LENGTH OF LISTs The length of a list is the number of elements it has (LENGTH ) * (setq x ‘(HI MOM)) * (LENGTH x) * (setq a ‘((blue sky) (green grass) (brown earth))) * (LENGTH a)

27 Lect. ratchadaporn kanawong27 Exercise How many elements of following lists have? (OPEN DOOR PLEASE) (OPEN (THE DOOR) PLEASE) ((1 2) (2 3) (3 4) (4 5) (5 6)) ((ONE) FOR ALL (AND (TWO (FOR ME)))) (A (B C) D ()) (A B (C D) ())

28 Lect. ratchadaporn kanawong28 Construct of List We have three function to make list (cons ) (list ) (append )

29 Lect. ratchadaporn kanawong29 Constructing Lists Using ‘cons’  (cons ‘(a b) ‘(c d))((A B) C D) Using ‘append’  (append ‘(a b) ‘(c d))(A B C D) Using ‘list’  (list ‘(a b) ‘(c d))((A B) (C D))

30 Lect. ratchadaporn kanawong30 Make List Example Type and look the result

31 Lect. ratchadaporn kanawong31 Element order in list In list are considered into two part : head and tail (a b c d) (b c d) a head tail CAR is function to get head part of list CDR is function to get tail part of list

32 Lect. ratchadaporn kanawong32 Result of car & cdr * (setq a ‘(x y z)) * (car a) * (cdr a) * (setq b ‘((blue sky) (green grass) (brown earth))) * (car b) * (cdr b) * (caar b) * (cadr b) * (cdar b) * (cddr b)

33 Lect. ratchadaporn kanawong33 Meaning function c?r (caar x)-(car (car x)) (cadr x)-(car (cdr x)) (cdar x)- (cdr (car x)) (cddr x)-(cdr (cdr x)) (caadr x)- (car (car (cdr x))) (caddr x)-(car (cdr (cdr x))) (cdddr x)- (cdr (cdr (cdr x)))

34 Lect. ratchadaporn kanawong34 Creating Function The syntax for creating function as: (defun (parameter-list) )

35 Lect. ratchadaporn kanawong35 Example Function Look this example (defun call-up (caller callee) (list ‘hello callee ‘this ‘is caller ‘calling)) * (call-up ‘FRED ‘WANDA)

36 Lect. ratchadaporn kanawong36 Example Function Look this example (defun double (n) (* n 2)) * (double 2)

37 Lect. ratchadaporn kanawong37 Example Function (defun absolute-value(x) (cond ((< x 0) (- x)) ((>= x 0) x))) * (absolute-value 2) (defun absolute-value(x) (cond ((< x 0) (- x)) (t x))) (defun absolute-value(x) (if (< x 0) (- x) x))

38 Lect. ratchadaporn kanawong38 Conditionals(1) Its form as: (cond ( ) …….. ( ))

39 Lect. ratchadaporn kanawong39 Conditionals Its form as: Some predicates for condition test: (if [ ]) = > = <= oddp evenp numberp minusp zerop plusp member atom listp null equal and or not

40 Lect. ratchadaporn kanawong40 Recursive Functions (defun my-member(element list) (cond ((null list) nil) ((equal element (car list)) list) (t (my-member element (cdr list))))) (defun my-length(list) (cond ((null list) 0) (t (+ (my-length(cdr list)) 1))))

41 Lect. ratchadaporn kanawong41 Recursive Functions (defun count-atoms(list) (cond ((null list) 0) ((atom list) 1) (t (+ (count-atoms (car list)) (count-atoms (cdr list))))))

42 Lect. ratchadaporn kanawong42 Linear or cdr recursion (length ((1 2) 3 (1 (4 (5))))) (length (3 (1 (4 (5))))) (length ((1 (4 (5))))) (length ()) 1 1 1 0 + + + 3

43 Lect. ratchadaporn kanawong43 Tree of recursion

44 Lect. ratchadaporn kanawong44 Side Effects *(defun f(x) (setq inc (+ inc 1)) (+ x inc)) *(setq inc 0) *(f 4) *inc *x *(defun foo(x) (setq x (+ x 1)) x) *(setq y 1) *(foo y) *y *x


Download ppt "Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon."

Similar presentations


Ads by Google