Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

List Processing Language - Programming Languages - Lecture Slides, Slides of Programming Languages

List Processing Language, List Process, Variations, Valid objects, Predicates, Set Operations, Iteration, Dotimes and dolist, Property Lists, Arrays, Functional Programming Paradigm are key points of this lecture. Programming languages is basic subject of computer science. Its not about any specific language but almost cover all of them.

Typology: Slides

2011/2012

Uploaded on 11/10/2012

omni
omni 🇮🇳

4.6

(9)

46 documents

1 / 41

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming
Languages
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

Partial preview of the text

Download List Processing Language - Programming Languages - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

Programming

Languages

LISP

LISt Processing Language

A Brief Introduction

  • Atoms :
    • numbers : (real 1.0, integer 1)
    • symbols : a consecutive sequence of characters (no space) e.g., a, x, price-of-beef.
    • two special symbols: T and NIL for logical true and false.
    • strings : a sequence of characters bounded by double quotes e.g., "this is red".

Valid objects (S-expression)

  • Lists : a list of atoms and/or lists, bounded by ( and ) e.g., (a b c), (a (b c))
  • top elements of a list – first level
  • example:
  • top elements of list (a b c) are a, b, and c
  • top elements of list (a (b c)) are a and (b c)
  • nil : empty list, same as ().

Valid objects (S-expression)

  • Function calls
    • Examples:

(sqrt 4) 2

  • Evaluation of S-expression
  1. Evaluate an atom.
  • numerical and string atoms evaluate to themselves;
  • symbols evaluate to their values if they are assigned values, return Error, otherwise;
  • the values of T and NIL are themselves.
  • Evaluation of S-expression
    • Examples

(sqrt x) Error: The variable X is unbound.

(+ (sqrt 4) 4.0)

  1. To assign a value to a symbol ( setq, set, setf )
  • setq is a special form of function (with two arguments);
  • the first argument is a symbol which will not be evaluated;
  • the second argument is a S-expression, which will be evaluated;
  • the value of the second argument is assigned to be the value of the first argument

(setq x 3.0)

x

(setq y x)

; the value of x is assigned as the value of y

y

(+ x y)

Functions:

  • Math functions:
    • +, -, *, /, exp, expt, log, sqrt, sin, cos, tan, max, min
  • Constructors: Cons, list and append
    • ( cons 'x L) ; insert symbol x at the front of list L, which is (X A B C) ; (A B C) - >( list 'a 'b 'c) ; making a list with the arguments as its elements (A B C) ; if a, b, c have values A, B, C, then (list a b c) ; returns list (A B C) - >( append '(a b) '(c d)) (A B C D) ; appends one list in front of another

Functions: (cont’)

  • Selectors: nth, first, rest, car, cdr…

>(first '(a s d f))

a

>(first '((a s) d f))

(a s)

>(rest '(a s d f))

(s d f).

>(rest '((a s) d f))

(d f)

>(rest '((a s) (d f))

((d f))

Functions (cont’)

  • Other operations:

>( reverse L) ; reverses a list

(C B A)

>( length L) ; returns the length of list L

Predicates

  • a special function which returns NIL if the

predicate is false, T or anything other than NIL, otherwise

  • = , > , < , >= , <= for numerical values;
  • equal eq for others
  • atom : test if x is an atom
  • listp : test if x is a list
  • Also number , symbolp , null

Defining LISP functions

  • ( defun func-name (arg-1 ... Arg-n) func-body)
    • Example:

(defun y-plus (x) (+ x y)) ;definition of y-plus

(setq y 2) (y-plus 23) 25

  • Local and global variables: local variables defined in

function body

  • Function returns the value of last expression in its body
  • Conditional control: if, when and cond
    • if

(if )

> (setq SCORE 78)

> (if (> score 85) ‘HIGH

(if (and (< score 84) (> score 65)) ‘MEDIUM ‘LOW))

> MEDIUM