2. Introduction
• First appeared in 1975
• Functional programming language
• Scheme was developed at the MIT AI Lab by Guy L. Steele and
Gerald Jay Sussman
• Scheme is influenced by Lisp
• Scheme influenced Java Script, Ruby, Common Lisp
• Clojure, Common Lisp, Dylan, EuLisp, Haskell, Hop, JavaScript,
Kernel, Lua, R, Racket, Ruby
• s-expressions, parenthesized lists in which a prefix operator is
followed by its arguments.
• It supports both in Windows and Linux platform.
3. Introduction Continues…
• It uses small size interpreter
• Uses in embedded system, compiler design, scripting.
• Google App Inventor for Android uses Scheme, where Kawa is used
to compile the Scheme code down to byte-codes for the Java Virtual
Machine running on Android devices
• List of Universities teach Scheme :
• MIT
• Northeastern University and Worcester Polytechnic Institute
• Rice University, etc
10. Local & Global Binding
• Local
>(let ((number 5)) (* number (+ number 1)))
30
Question : What will be the output ?
> (+ 12 number)
11. Local & Global Binding
• Global Binding
>(define number 100)
>number
100
>(let ((number 5)) (* number (+ number 1)))
30
Q: What is output ?
> number
20. Pairs
• Pascal, in which procedures can return only simple data
values; but in Scheme a procedure can return anything
• If you have exactly two values to pack together, the best data
structure to use is a pair -- a container designed specifically to
hold two values. The two values packed into a pair are
completely independent of one another; they need not belong
to the same data type.
21. Pairs continue…
How do you construct a pair?
>(cons 1 2)
(1 . 2)
>(cons #t #f)
(#t . #f)
So a pair can be a component of another pair?
>(cons (cons 1 2) 3) ((1 . 2) . 3)
Q:What Will bé the output ?
(define lp (cons (cons (cons (cons (cons 1 2) 3) 4) 5) 6) )
22. Pairs continue…
• How do you recover the contents of a pair?
>(define my-pair (cons 1 2))
>(car my-pair)
1
23. List
Using list we can pack more than two values.
How does Scheme treat lists differently from other pairs in Scheme?
>(cons 1 (cons 2 '()))
(1 2)
use the shorthand notation for lists when you type them in, too?
>'(8 4 6 1)
(8 4 6 1)
>'()
()
Q: What will be the output
> (cons 1 (cons 2 (cons 3 4)))
24. List continues…
>(define list-of-six (list 6 5 4 3 2 1))
Empty List: null procedure defines it. which takes one argument and
determines whether its operand is the empty list and returns Boolean
value.
>(null? '()) #t
> (null? '(3)) #f
>(null? (cons 1 2)) #f
>(null? (cdr '(3))) #t
> (null? (cdr (cons 3 '()))) #t
26. Vectors
• Vectors are heterogeneous structures whose elements are indexed
by integers. A vector typically occupies less space than a list of the
same length, and the average time required to access a randomly
chosen element is typically less for the vector than for the list.
> (define my-vec (vector 1 2 3))
> my-vec
#(1 2 3)
> (vector-ref my-vec 2)
3
27. Vector continues…
• Useful procedures
(vector obj)
Create a vector
(vector? Obj )
Returns boolean
(vector-length vector)
Returns the number of elements of the venctor.
Vector->list vector
(vector-list ‘#(12 13 14))
List->vector
(list->vector ‘(1 2 3))