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

Evaluation of S Expression - Programming Languages - Lecture Slides, Slides of Programming Languages

Evaluation of S expression, Evaluating an atom, Evaluate a list, Assign a value to a symbol, Math functions, Selectors, Function Calls, Valid Objects, Top elements of a list 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 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
LISP
Invented by John McCarthy (1958)
Two simple data structure (atoms and lists)
Heavy use of recursion
Interpretive language
Variations
Scheme
Common Lisp (de facto industrial standard)
Most widely used AI programming language
Functional Programming Paradigm
Low maintenance overhead
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Evaluation of S Expression - Programming Languages - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

LISP

  • Invented by John McCarthy (1958)
  • Two simple data structure (atoms and lists)
  • Heavy use of recursion
  • Interpretive language
  • Variations
    • Scheme
    • Common Lisp (de facto industrial standard)
  • Most widely used AI programming language
  • Functional Programming Paradigm
  • Low maintenance overhead
  • Atoms may be;
    • 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

  • Its also a list
  • Uses prefix notation:

(function-name arg1,arg2 ... argN)

  • It returns function value for the given list of arguments
  • Functions are either provided by LISP function library or defined by the user

Function Calls

  • Examples:

(+ 1 3 5) 9

(/ 3 5) 3/

(/ 3.0 5)

(sqrt 4) 2

Function Calls

Command Line Prompt

Evaluation of S-expression

2) Evaluate a list - evaluate every top element of the list

as follows, unless explicitly forbidden:

  • The first element is always a function name;

evaluating it means to call the function body

  • Each of the rest elements will then be evaluated, and

their values returned as the arguments for the

function

  • Examples :

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

> (+ (sqrt 4) 4.0)

Evaluation of S-expression

> (setq y x)

> y

> (+ x y)

  • To forbid evaluation of a symbol use : quote or

(quote x) x

'x x

(setq z 'x) x

Functions (cont’)

• Selectors

  • first, rest, nth, car, cdr…

> (first '(a s d f)) ;returns the first element of a list

a

> (rest '((a s) d f)) ;deletes the first element from the

;list and returns the rest as a list

(d f)

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

(a s)

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

((d f)) Docsity.com

> (setq L '(A B C))

(A B C)

> (car L)

; returns the first top level element of list L

A

> (cdr L)

; returns the rest of list L

(B C)