Lisp Tutorial - PowerPoint PPT Presentation

About This Presentation
Title:

Lisp Tutorial

Description:

Lisp Tutorial Click on Xlisp icon you enter the interpreter You can now Define functions Load program files with .lsp extension Execute Lisp functions – PowerPoint PPT presentation

Number of Views:109
Avg rating:3.0/5.0
Slides: 11
Provided by: siy2
Learn more at: https://cs.winona.edu
Category:
Tags: lisp | tutorial

less

Transcript and Presenter's Notes

Title: Lisp Tutorial


1
Lisp Tutorial
  • Click on Xlisp icon you enter the interpreter
  • You can now
  • Define functions
  • Load program files with .lsp extension
  • Execute Lisp functions

2
  • gt is the lisp prompt
  • gt mylist
  • Error unbound variable mylist
  • gt (mylist)
  • Error unbound function mylist
  • (setq mylist (a b c d))
  • (A B C D)
  • gt mylist
  • (A B C D)

3
  • (car mylist)
  • A
  • (cdr mylist)
  • (B C D)
  • (car (cdr mylist)
  • waiting
  • ) .. Need to complete the balanced parenthesis
  • B
  • (cdr (car mylist)) ? What will happen
  • Error bad argument type - A

4
  • gt nil
  • nil
  • gt t
  • t
  • gt (atom mylist)
  • nil
  • gt (listp mylist)
  • t
  • gt (equal nil mylist)
  • nil

5
  • gt (null cdr mylist)
  • Error unbound variable cdr
  • gt (null (cdr mylist) )
  • nil
  • gt (cdddr mylist)
  • (D)
  • gt (list (car mylist))
  • (A)
  • gt (list (cdr mylist))
  • ((B C D))

6
  • gt (list (car mylist) (caddr mylist))
  • (A C)
  • gt mylist
  • (A B C D)
  • gt (last mylist) as defined in the interpreter
  • (D)
  • gt (cond ((null mylist) (print list is empty
    ) ) )
  • NIL
  • LISP is NOT case sensitive

7
  • gt (equal A a)
  • T
  • gt (cond ( (null mylist) (print empty))
  • ( t (print not empty) )
  • )
  • not empty
  • not empty
  • Action print not empty
  • Return not empty

8
  • gt (cond ( (null mylist) (print empty))
  • ( t mylist )
  • )
  • (A B C D)
  • gt (defun second (l ) (cadr l))
  • SECOND
  • (second mylist)
  • B

9
  • gt (list (second mylist) (car mylist) (cddr
    mylist) )
  • (B A (C D))
  • Get the last element of a list
  • Define this function
  • Recursive definition

10
  • Define a function to reverse a list
Write a Comment
User Comments (0)
About PowerShow.com