Functional languages (e.g. Scheme, ML). Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined using the keyword lambda: (lambda (<parameters>) <body>) Syntax of Scheme is very simple:
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
 12
val it=12:int
 val x=12;
val x=12:int
 x
val it=12:int
 fun addOne x = x+1;
val addOne=fn:int>int
 addOne x
val it=13:int
 fun add (x,y) = x+y;
val add=fn:int*int>int;
 add(3,x);
val it=15:int
 fun adder x y = x+y;
val adder=fn:int>int>int
 val add3 = adder 3;
val add3=fn:int>int
 add3 x;
val it=15:int;
 val add7 = adder 7;
val add7=fn:int>int
 add7 x;
val it=19:int;
> 12
12
> (define x 12)
> x
12
> (define addOne
(lambda (x) (+ x 1)))
> (addOne x)
13
> (define add
(lambda (x y) (+ x y)))
> (add 3 x)
15
> (define adder
(lambda (x)
(lambda (y) (+ x y))))
> (define add3 (adder 3))
> (add3 x)
15
> (define add7 (adder 7))
> (add7 x)
19
> 213 if you ask Scheme to evaluate a number
213 you get the number as a result
> x
Error: reference to undefined identifier: x
> (define x 12)
> x
12
>
> (define applyOperator (lambda (op) (op 3 4)))
> (applyOperator +)
7
> (applyOperator )
1
>
> (+ 3 4) name “+” refers to addition function
7
> (define + ) name “+” now refers to subtraction function
> (+ 3 4)
1
(lambda (<parameters>) <body>)
> (define addOne (lambda (p) (+ p 1)))
> addOne
#<procedure:addOne>
>
int mystery(int x, int y, int z) {
int a = func1(x,y);
int b = func2(y,z);
<body>
}
(define mystery (lambda (x y z)
(let ((a (func1 x y)) (b (func2 y z))) <body>)
((lambda (a b) <body>) (func1 x y) (func2 y z))
primitive env
c
+
<proc>
(+ a b c)

<proc>
cons
<proc>
…
user env
a b
(lambda (c)
(+ a b c))
addOne
a
1
foo
b
2
(lambda (c) (+ a b c))
> (define x 12)
> x
12
> (define fifi 'poodle)
> fifi
poodle
> (define fifi (quote poodle))
a
b
> (define myPair (cons 'a 'b))
> (car myPair)
a
> (cdr myPair)
b
> (define myPair (cons 'a 'b))
> myPair
(a . b)
> (define myList (cons 'a '()))
> myList
(a)
> (define myPair (cons 'a 'b))
> myPair
(a . b)
> (define myList (cons 'a '())
> myList
(a)
a
b
c
d
and so on!
(fido . bulldog) (clifford . bigRed)
(lassie . collie)))
> (assoc 'fido aList)
(fido . bulldog)
> (assoc 'rufus aList)
#f
> (define myPair (cons 'a 'b))
> myPair
(a . b)
> (setcar! myPair 'fred)
> myPair
(fred . b)
> (setcdr! myPair 'wilma)
> myPair
(fred . wilma)