Lisp - FUNCTIONAL ORIENTED PARADIGM * Functional...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
FUNCTIONAL ORIENTED PARADIGM * Functional ( applicative ) paradigm language, where functions application is the central idea. Striking features of The“Pure” Functional Paradigm: 1) The syntactic equivalence of programs and data (programs are list and lists are programs). 2) Recursion replaces iteration. 3) There is no intermediate results to be kept around, hence the concept of “memory” is not part of the execution semantics, i.e., there is no “side effect” on the memory state, except at the end of program execution! 4) Functions are “first-class-citizens”. 5) Symbolic-expressions (Cambridge Polish notation) versus Meta-expressions. * Unfortunately there was no way to practically keep the conceptual view of the “pure” functional paradigm, hence many variations of the “pure) concepts have been implemented as functional languages, the most famous is LISP.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
LISP ( LIS t P rocessing) (John McCarthy, MIT,1961) Lisp is functional language widely used in applications like: Artificial Intelligence, Expert Systems, Machine Learning, and Speech Modeling, etc. (why?). Interpreted , with the possibility of compiled functions, to be invoked at run time; Also, two versions of LISP scoping: static and dynamic! S-expressions: (f (g a b) (h c d)) f ( g (a, b) , h (c,d)) M -Expressions: Prefix (+ ( * 2 3) (/ 8 2)) (2 * 3) + (8/2) Infix S-expressions: 1) lists 2) atoms (literal/numeric) The first item in a list (S-expression) is considered to be an “operation” with the rest of the list items as its “operands”. The system will attempt to evaluate any list as an S-expression unless it is “quoted” with . % (set ‘text ‘(to be or not to be)) (to be or not to be) % text (to be or not to be) Primary data types ( no explicit declarations 1) ) are: atoms i) numeric: numbers (integer, real, rational, …) (indivisible S-expression)— ii) literals: symbols
Background image of page 2
2) lists They are the primary data structure constructors. (S-expressions): Consists of atoms and/or lists. They construct programs (functions) and data. %(make-table text nil) make-table (text,nil) !----------(code)--------! %(set ‘X ‘(make-table text nil)) !-----------(data)----------! There are also built-in atoms’ property lists , with automatic storage management, to hold useful info about each atom. The empty list is considered to be the atom “nil”: %(atom ()) %(listp ()) t t - When you have an error in your list code you are sent to the debugger: Important commands: 0] abort ; gets you out of the debugger to the lisp interpreter level - In order to exit the lisp interpreter , back to the Linux level: * (quit) Pseudo Functions (procedures): They are function with side effect on the memory state. i) set : %(set ‘text ‘(to be or not to be)) ; bind the second operand to (to be or not to be) ; the first operand. % text ; text is bound to the above list (to be or not to be) ii) defun : Function definition %(defun f (p 1 p 2 … p n ) body-code) ; the equivalent M-expression: procedure f (p 1 p 2 … p n ); begin <body-code> end ;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Operations on Lists: Lists are ADTs with the following two major sets of operations: A) Selectors B) Constructors A) Selectors Operations (“pure” functions):
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/23/2011 for the course CSE 324 taught by Professor Soliman during the Spring '11 term at NMT.

Page1 / 19

Lisp - FUNCTIONAL ORIENTED PARADIGM * Functional...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online