SlideShare uma empresa Scribd logo
1 de 28
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

Mais conteúdo relacionado

Mais procurados

Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming LangugeYaser Jaradeh
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) wahab khan
 
Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To LispDamien Garaud
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISPDevnology
 
Aaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced conceptsAaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced conceptsAminaRepo
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Modules 17 12_2020
Modules 17 12_2020Modules 17 12_2020
Modules 17 12_2020Sugnan M
 

Mais procurados (20)

Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Lisp
LispLisp
Lisp
 
Lisp
LispLisp
Lisp
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Lisp
LispLisp
Lisp
 
Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To Lisp
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
Aaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced conceptsAaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced concepts
 
Ch6
Ch6Ch6
Ch6
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Modules 17 12_2020
Modules 17 12_2020Modules 17 12_2020
Modules 17 12_2020
 

Semelhante a Scheme language

LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To LispLISP Content
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and FuturePushkar Kulkarni
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)jaxLondonConference
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 

Semelhante a Scheme language (20)

LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and Future
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Introduction2R
Introduction2RIntroduction2R
Introduction2R
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 

Último

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

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))