SlideShare a Scribd company logo
SCHEME LANGUAGE
Jitendra Lenka
Sr. Software Engineer,
L&T Tech Services, Mysore
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.
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
Scheme Variant
• Chez Scheme
• Chicken Scheme
• Racket Scheme
First Program
>(sqrt 23)
4.79583152331272
>(display “Hello World”)
(newline)
Integer Arithmetic
(+ 100 200)
(+ 10 20 30 40 50 )
Q: What about negative number
Integer Procedures
• remainder
• quotient
• Max
• min
Nested Procedure Call
(* (- 7 3) (+ 5 12))
(* (quotient (* 7 41) (- (max 38 14) 35))
Definition
>(define freezing 32)
> (define boiling 212)
(- boiling freezing)
180
(define seconds-in-week (* 7 24 60 60))
Local & Global Binding
• Local
>(let ((number 5)) (* number (+ number 1)))
30
Question : What will be the output ?
> (+ 12 number)
Local & Global Binding
• Global Binding
>(define number 100)
>number
100
>(let ((number 5)) (* number (+ number 1)))
30
Q: What is output ?
> number
Internal Definition
(let ((number 5))
(define successor (+ number 1)) (* number
successor))
Simple Procedure
Definition :
> (define (square root) (* root root))
Calling ‘square’ procedure:
> (square 10)
Lambda Expression
• Lambda
(define disparity (lambda (a b) (abs (- a b))))
• Without Lambda
(define (disparity a b) (abs (- a b)))
Boolean Expression
>(not #f)
>(not #t)
>(not 5)
>(not not)
Boolean Expression Continues…
• So you use the boolean? predicate to distinguish Boolean
values from values of other types?
>(boolean? #t) #t
> (boolean? #f) #t
> (boolean? 0) #f
> (boolean? (lambda (augend) (+ augend 3))) #f
> (boolean? boolean?) #f
> (boolean? (boolean? boolean?)) #t
Compare Boolean expression
• >(eq? #t #t)
Equal and Inequality Procedure
• Equal
>(= 5 6)
• Inequality
(define (~= first-num second-num)
(not (= first-num second-num)))
Factorial Function
>(define (factorial n)
(if (zero? n)
1
(* (factorial (sub1 n)) n)))
>(factorial 0)
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.
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) )
Pairs continue…
• How do you recover the contents of a pair?
>(define my-pair (cons 1 2))
>(car my-pair)
1
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)))
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
List continues…
> (list 1 2 3 4) (1 2 3 4)
> (list (cons 1 2) (cons 3 4) (cons 5 6)) ((1 . 2) (3 . 4) (5 . 6))
> (list (+ 1 12) (* 60 4)) (13 240)
> (list 28) (28) > (list) ()
List-ref procédure : extract value from a list.
>(list-ref '(0 1 4 9 16 25 36 49 64 81 100 121) 7)
49
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
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))
THANK YOU

More Related Content

PDF
The Scheme Language -- Using it on the iPhone
PPTX
Scheme Programming Language
PPT
INTRODUCTION TO LISP
PPTX
ODP
Introduction to Programming in LISP
PPTX
LISP: Input And Output
PPTX
A brief introduction to lisp language
The Scheme Language -- Using it on the iPhone
Scheme Programming Language
INTRODUCTION TO LISP
Introduction to Programming in LISP
LISP: Input And Output
A brief introduction to lisp language

What's hot (20)

PPTX
Prolog & lisp
PPTX
LISP: Data types in lisp
PPT
(Ai lisp)
PPTX
PPTX
Python Data-Types
PPTX
LISP: Introduction to lisp
PPT
Designing A Syntax Based Retrieval System03
PPT
Lisp Programming Languge
PPT
Advance LISP (Artificial Intelligence)
PDF
Lecture4 lexical analysis2
PPT
PDF
Gentle Introduction To Lisp
PDF
Learn a language : LISP
PDF
Aaa ped-3. Pythond: advanced concepts
PPT
Lisp and scheme i
PDF
Compiler Construction | Lecture 7 | Type Checking
PPTX
Regular Expressions
PPT
Modules 17 12_2020
Prolog & lisp
LISP: Data types in lisp
(Ai lisp)
Python Data-Types
LISP: Introduction to lisp
Designing A Syntax Based Retrieval System03
Lisp Programming Languge
Advance LISP (Artificial Intelligence)
Lecture4 lexical analysis2
Gentle Introduction To Lisp
Learn a language : LISP
Aaa ped-3. Pythond: advanced concepts
Lisp and scheme i
Compiler Construction | Lecture 7 | Type Checking
Regular Expressions
Modules 17 12_2020
Ad

Similar to Scheme language (20)

PPTX
Principles of programming language intro
PPTX
Funtional Programming
PDF
The Scheme Programming Language 4th Fourth Edition R K Dybvig R Kent Dybvig
PDF
2006 Small Scheme
PPT
pairs
PDF
Scheme 核心概念(一)
PPT
lists
PPTX
Class 21: Changing State
ODP
Recursion and Functional Programming
PPTX
Array Data StructureData StructureData Structure.pptx
PDF
Lambda Zero Programming Language Introduction
PPT
expressions
PPTX
What is c
PDF
iRODS Rule Language Cheat Sheet
PDF
Mit gnu scheme reference manual
PDF
Scheme language brief introduction
PPTX
Functional Programming.pptx
PPT
Pl vol1
PDF
201801 CSE240 Lecture 17
PDF
Lambda? You Keep Using that Letter
Principles of programming language intro
Funtional Programming
The Scheme Programming Language 4th Fourth Edition R K Dybvig R Kent Dybvig
2006 Small Scheme
pairs
Scheme 核心概念(一)
lists
Class 21: Changing State
Recursion and Functional Programming
Array Data StructureData StructureData Structure.pptx
Lambda Zero Programming Language Introduction
expressions
What is c
iRODS Rule Language Cheat Sheet
Mit gnu scheme reference manual
Scheme language brief introduction
Functional Programming.pptx
Pl vol1
201801 CSE240 Lecture 17
Lambda? You Keep Using that Letter
Ad

Recently uploaded (20)

PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Mushroom cultivation and it's methods.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
August Patch Tuesday
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hindi spoken digit analysis for native and non-native speakers
A novel scalable deep ensemble learning framework for big data classification...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MIND Revenue Release Quarter 2 2025 Press Release
SOPHOS-XG Firewall Administrator PPT.pptx
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
Tartificialntelligence_presentation.pptx
Chapter 5: Probability Theory and Statistics
Encapsulation_ Review paper, used for researhc scholars
Mushroom cultivation and it's methods.pdf
A comparative study of natural language inference in Swahili using monolingua...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Zenith AI: Advanced Artificial Intelligence
NewMind AI Weekly Chronicles - August'25-Week II
Web App vs Mobile App What Should You Build First.pdf
August Patch Tuesday
1 - Historical Antecedents, Social Consideration.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf

Scheme language

  • 1. SCHEME LANGUAGE Jitendra Lenka Sr. Software Engineer, L&T Tech Services, Mysore
  • 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
  • 4. Scheme Variant • Chez Scheme • Chicken Scheme • Racket Scheme
  • 6. Integer Arithmetic (+ 100 200) (+ 10 20 30 40 50 ) Q: What about negative number
  • 7. Integer Procedures • remainder • quotient • Max • min
  • 8. Nested Procedure Call (* (- 7 3) (+ 5 12)) (* (quotient (* 7 41) (- (max 38 14) 35))
  • 9. Definition >(define freezing 32) > (define boiling 212) (- boiling freezing) 180 (define seconds-in-week (* 7 24 60 60))
  • 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
  • 12. Internal Definition (let ((number 5)) (define successor (+ number 1)) (* number successor))
  • 13. Simple Procedure Definition : > (define (square root) (* root root)) Calling ‘square’ procedure: > (square 10)
  • 14. Lambda Expression • Lambda (define disparity (lambda (a b) (abs (- a b)))) • Without Lambda (define (disparity a b) (abs (- a b)))
  • 15. Boolean Expression >(not #f) >(not #t) >(not 5) >(not not)
  • 16. Boolean Expression Continues… • So you use the boolean? predicate to distinguish Boolean values from values of other types? >(boolean? #t) #t > (boolean? #f) #t > (boolean? 0) #f > (boolean? (lambda (augend) (+ augend 3))) #f > (boolean? boolean?) #f > (boolean? (boolean? boolean?)) #t
  • 18. Equal and Inequality Procedure • Equal >(= 5 6) • Inequality (define (~= first-num second-num) (not (= first-num second-num)))
  • 19. Factorial Function >(define (factorial n) (if (zero? n) 1 (* (factorial (sub1 n)) n))) >(factorial 0)
  • 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
  • 25. List continues… > (list 1 2 3 4) (1 2 3 4) > (list (cons 1 2) (cons 3 4) (cons 5 6)) ((1 . 2) (3 . 4) (5 . 6)) > (list (+ 1 12) (* 60 4)) (13 240) > (list 28) (28) > (list) () List-ref procédure : extract value from a list. >(list-ref '(0 1 4 9 16 25 36 49 64 81 100 121) 7) 49
  • 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))