Download presentation
Presentation is loading. Please wait.
Published byBeatrix Lyons Modified over 8 years ago
1
Functional Languages A function is an “association of a certain object from one set (the range) with each object from another set (the domain) A function is an expression and its associated values, where the expression provides a method or rule for making the association between domain and range values.
2
Functional languages Ways of expressing functions –Age(Amalia) = 7 –(Age Amalia) –(age Amalia 7) function / applicative Functions are single valued – for each domain value there is exactly one associated range value.
3
Functional Languages Distinguishing Features –Programs are a composition of functions –Functions are supported as first-class objects Functions can be arguments to other functions –There are relatively few side effects –Simple semantics –Recursive control prevalent
4
Functional Languages LISP –Typeless –Primary data structure is the list Scheme – a dialog of LISP –typeless ML = Meta Language –Strongly typed APL – not purely functional –Primary data structure is the array FP
5
Relations vs Functions Relation is –Ordered association of elements of ten listed as a tuple Function –Given an ordered tuple (argument list of elements) returns a value Composition of functions example (+ (* w x) ( - y z))
6
First Order Functions A function is first-order if it takes individuals as arguments and returns an individual value –Numbers –Strings –Records –Etc. An individual is a function of order 0
7
Side Effects A function (f x y z) is said to have a side effect if x,y, and/or z change in the calling environment during application of the function. –GetData (x,y,z) –(GetData Getx Gety Getz) A function defined with all value parameters, and where no assignments are made to global variables, has no side effects.
8
Clean Semantics Language means what it says Language is not ambiguous Results of a program can be verified
9
LISP – a functional language History –First major AI workshop summer 1956 – at Dartmouth –John McCarthy – late 50’s – MIT Kleene’s - recursive function theory Alonzo Church’s – lambda calculus –IBM 704 few primitives Punched cards –Good for AI areas of Robotics & knowledge engineering –Standardization attempt: Common LISP
10
Knowledge Engineering Expert Systems –Public knowledge Textbooks –Private knowledge Heuristics (rules of thumb) –Examples DENDRAL – data analysis MACYSYMA – symbolic calculus EXPERT – medical MYCIN – infectious disease diagnosis & prescription
11
LISP – a functional language McCarthy’s original LISP – 6 functions cons, cond, car, cdr, eq, atom Today’s LISP – many more functions –Arithmetic –Input –Output
12
LISP – a functional language Simple Data Type –Atom Number –Use built in hardware for integer & real arithmetic String Structured Data Type –List Cam be empty () Can contain an ordered list
13
LISP – a functional language LISP manages pointers for you –ordinary Lisp lists are singly linked lists When dealing with recursion –Need a base case (stopping case) –Need a recursive case Common Lisp provides macros for push and pop (xlisp doesn’t)
14
LISP – a functional language (setf pair (cons ‘a ‘b)) –returns the dotted pair (A.B) –(A.B) is a two part data structure –A is the car of the cons –B is the cdr of the cons
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.