Presentation is loading. Please wait.

Presentation is loading. Please wait.

 If you want to open an already existing file select file->open on the menu and then choose the program you want to modify. If you want to open a new.

Similar presentations


Presentation on theme: " If you want to open an already existing file select file->open on the menu and then choose the program you want to modify. If you want to open a new."— Presentation transcript:

1  If you want to open an already existing file select file->open on the menu and then choose the program you want to modify. If you want to open a new file select file->new on the menu and start typing your program on the editor.  You have to save by clicking file->save after you type. Be sure your filename has an extension.lisp  Then you have to compile and load by using file->compile and load… from the menu  Open the listener by clicking tools->listener on the menu. And check to see if the functions defined in your program are correctly working. Lisp File Basics

2 At the LISP prompt one can type the command or source code(programs) and retrieve the results just like at the DOS or UNIX prompt. In the solaris based LISP as you type /usr/acl5.0.1/lisp at the $ prompt you get the LISP prompt USER. In the windows based LISP you acces the LISP by clicking START menu-->Harlequin lispworks-->lispworks. Then you select tools->listener from the menu bar to invoke the LISP prompt.

3 Defining functions using “defun” USER(1):(defun funct1 (x) (+ x 1)) FUNCT1 USER(2):(funct1(3)) 4

4 Manipulating Lists Using Quote:- eg: USER(1): ‘(1 2 3) (1 2 3) Using CAR:- eg: USER(2): CAR( 1 2 3 4) 1 Using CDR:- eg:- USER(3): CDR( 1 2 3) ( 2 3)

5 RECURSION LISP supports recursion just like any procedural language(eg: C) Eg: Raise X to the Nth power (defun raise (x n) (if (= n 0) 1 (* x ( raise x (- n 1) ) ) ) )

6 ITERATION Using dolist :- dolist repeats a set of operations for as many times as there are entries in a list. Eg:-USER(1): (dolist (x ‘(a b c)) (print x)) A B C NIL

7 Using LOOP Eg:- USER(15):- (loop for x from 1 to 7 collect x) (1 2 3 4 5 6 7)

8 Using dotimes :- dotimes repeats an evaluation as many times as it is requested Eg:- USER(10):-(dotimes (i 5 i) (print i) o 1 2 3 4 5

9 Conditional Expressions:- Using CASE. Eg:- User(10):(defun goose (x) (case x (1 ‘one) (2 ‘two) (3 ‘three) (4 ‘four) (otherwise ‘many))) goose

10 Input and Output > (progn (format t “Please enter your name: ”) (read-line)) > (prin1 “hello”) > (format nil “Dear ~A, ~% Our records indicate …” “Mr. Malatesta”) Note: There are many variants. You need to refer to a CL book.


Download ppt " If you want to open an already existing file select file->open on the menu and then choose the program you want to modify. If you want to open a new."

Similar presentations


Ads by Google