If you want to open an already existing file select

1 / 10
About This Presentation
Title:

If you want to open an already existing file select

Description:

Eg:- User(10):(defun goose (x) (case x (1 one) (2 two) (3 three) (4 four) ... goose. Input and Output (progn (format t 'Please enter your name: ') (read-line) ... –

Number of Views:30
Avg rating:3.0/5.0
Slides: 11
Provided by: shi85
Category:

less

Transcript and Presenter's Notes

Title: If you want to open an already existing file select


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

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--gtHarlequin
    lispworks--gtlispworks .
  • Then you select tools-gtlistener 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
gt (progn (format t Please enter your
name ) (read-line)) gt (prin1 hello) gt
(format nil Dear A, Our records indicate
Mr. Malatesta) Note There
are many variants. You need to refer to a CL book.
Write a Comment
User Comments (0)
About PowerShow.com