SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Class 4:
Making
Procedures


cs1120 Fall 2011
David Evans
30 August 2011
Announcements
PS1 is due Monday (electronic submission and
  paper submission): don’t wait to get started!
Quiz 1 is Wednesday (in class)
  Chapters 1-4 of Course Book
  Chapters 1-3 of The Information
  Classes 1-5 (including questions from class
  notes)
   I haven’t forgotten about answering your questions from PS0.
                 I will post my answers by tomorrow.
Recap: Assigning Meanings
Program ::= ε | ProgramElement Program
ProgramElement ::= Expression | Definition
Definition ::= (define Name Expression)
Expression ::= PrimitiveExpression | NameExpression
               | ApplicationExpression | ProcedureExpression | IfExpression
PrimitiveExpression ::= Number | true | false| PrimitiveProcedure
NameExpression ::= Name
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::= ε | Expression MoreExpressions
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters              ::= ε | Name Parameters
IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt)

This grammar generates (nearly) all surface forms in the Scheme.
language. If we have a meaning rule for each grammar rule, we can
determine the meaning of every Scheme program.

                                                                              3
Evaluation Rules: Last Class
PrimitiveExpression ::= Number | true | false| PrimitiveProcedure
    Rule 1: If the expression is a primitive, it evaluates to its pre-
    defined value.
NameExpression ::= Name
     Rule 2: A name evaluates to the value associated with that name.
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::= ε | Expression MoreExpressions
     Rule 3: To evaluate an application expression:
      a)   Evaluate all the subexpressions (in any order)
      b)   Apply the value of the first subexpression to the values of all the other
           subexpressions.

                                                                                       4
Last class: Rules for Application
1. Primitives. If the procedure to apply is a
   primitive procedure, just do it.

2. Constructed Procedures. If the procedure is
   a constructed procedure, evaluate the body
   of the procedure with each parameter name
   bound to the corresponding input
   expression value.
          This only makes sense if we know what a constructed procedure is!

                                                                              5
Constructing Procedures
Program ::= ε | ProgramElement Program
ProgramElement ::= Expression | Definition
Definition ::= (define Name Expression)
Expression ::= PrimitiveExpression | NameExpression
              | ApplicationExpression | ProcedureExpression | IfExpression
PrimitiveExpression ::= Number | true | false| PrimitiveProcedure
NameExpression ::= Name
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::= ε | Expression MoreExpressions
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters    ::= ε | Name Parameters
IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt)




                                                                             6
Constructing Procedures
 lambda means “make a procedure”

Expression ::= ProcedureExpression
ProcedureExpression ::=
       (lambda (Parameters) Expression)
Parameters ::= ε
Parameters ::= Name Parameters

                                          7
Evaluation Rule 4: Lambda
A lambda expression evaluates to a
procedure that takes the given
parameters and has the expression as
its body.

ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters     ::= ε | Name Parameters




                                                           8
Lambda Expressions
(lambda () true)

(lambda (x) (* x x))

(lambda (a)
  (lambda (b)
    (+ a b)))
Applying Compound Procedures
              Rule 3: To evaluate an application expression:
((lambda ()    (a) Evaluate all the subexpressions (in any
               order)
    true)      (b) Apply the value of the first subexpression
               to the values of all the other subexpressions.
 1120)
              Apply Rule for constructed procedures:
              Evaluate the body of the procedure with each
              parameter name bound to the corresponding
              input expression value.

              Evaluation Rule 4. A lambda expression
              evaluates to a procedure that takes the given
              parameters and has the expression as its body.
Applying Compound Procedures
                  Rule 3: To evaluate an application expression:
((lambda (x)       (a) Evaluate all the subexpressions (in any
                   order)
    (+ x 1000))    (b) Apply the value of the first subexpression
                   to the values of all the other subexpressions.
 120)
                  Apply Rule for constructed procedures:
                  Evaluate the body of the procedure with each
                  parameter name bound to the corresponding
                  input expression value.

                  Evaluation Rule 4. A lambda expression
                  evaluates to a procedure that takes the given
                  parameters and has the expression as its body.
Applying Compound Procedures
                  Rule 3: To evaluate an application expression:
((lambda (x)       (a) Evaluate all the subexpressions (in any
                   order)
    (+ x 1000))    (b) Apply the value of the first subexpression
                   to the values of all the other subexpressions.
 x)
                  Apply Rule for constructed procedures:
                  Evaluate the body of the procedure with each
                  parameter name bound to the corresponding
                  input expression value.

                  Evaluation Rule 4. A lambda expression
                  evaluates to a procedure that takes the given
                  parameters and has the expression as its body.
Applying Compound Procedures
                 Rule 3: To evaluate an application expression:
((lambda (a)      (a) Evaluate all the subexpressions (in any
                  order)
   (lambda (b)    (b) Apply the value of the first subexpression
                  to the values of all the other subexpressions.
     (+ a b)))
                 Apply Rule for constructed procedures:
 5)              Evaluate the body of the procedure with each
                 parameter name bound to the corresponding
                 input expression value.

                 Evaluation Rule 4. A lambda expression
                 evaluates to a procedure that takes the given
                 parameters and has the expression as its body.
Applying Compound Procedures
                 Rule 3: To evaluate an application expression:
(((lambda (a)     (a) Evaluate all the subexpressions (in any
                  order)
   (lambda (b)    (b) Apply the value of the first subexpression
                  to the values of all the other subexpressions.
     (+ a b)))
                 Apply Rule for constructed procedures:
  5)             Evaluate the body of the procedure with each
                 parameter name bound to the corresponding
 6)              input expression value.

                 Evaluation Rule 4. A lambda expression
                 evaluates to a procedure that takes the given
                 parameters and has the expression as its body.
Do we have everything we
   need to describe all
     computations?
Language Elements
        Question from Class 2:
When learning a foreign language, which
     elements are hardest to learn?

Primitives
Means of Combination
Means of Abstraction


                                          16
Primitives: lots of them, and hard to learn real meaning (but its
   just memorization)
Means of Combination
  Complex, but, all natural languages have similar ones [Chomsky]
  Sentence ::= Subject Object Verb (45%)

  Sentence ::= Subject Verb Object (42%)        Welsh: “Lladdodd y ddraig y dyn.”
  Sentence ::= Verb Subject Object (9%)

  Sentence ::= Object Subject Verb (<1%)

  Scheme:
Means of Abstraction: few of these, but tricky to learn
 differences across languages
  Tok Pisin (Papua New Guinea): mi (I), mitupela (he/she and I), mitripela
        (both of them and I), mipela (all of them and I), yumitupela (you and
        I), yumitripela (both of you and I), yumipela (all of you and I)
  Scheme:
                                                                                    17
Charge
PS1: Due Monday
  Wednesdays, 5-6:30pm (Jiamin, Rice 1xx)
  Thursdays, 9:45-11am (Dave, Rice 507)
  Thursdays, 10-11:30am (Peter, Rice 1xx)
  Thursdays, 1-2:30pm (Joseph, Rice 1xx)
  Thursdays, 4:30-6pm (Jonathan, Rice 1xx)
  Thursdays, 6-7:30pm (Jiamin, Rice 1xx)
By Friday
  Finish reading Chapters 1-4, Gleick Chapters 1-3
Quiz 1: Wednesday

Weitere ähnliche Inhalte

Was ist angesagt?

String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)Ravi Kant Sahu
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 Bdplunkett
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6dplunkett
 
Operators in java
Operators in javaOperators in java
Operators in javaRavi_Kant_Sahu
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Abdul Hannan
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Syed Farjad Zia Zaidi
 
Chapter 13 - Recursion
Chapter 13 - RecursionChapter 13 - Recursion
Chapter 13 - RecursionAdan Hubahib
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Adi Bolboaca
 
M C6java3
M C6java3M C6java3
M C6java3mbruggen
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use casesSrajan Mor
 

Was ist angesagt? (20)

Ch09
Ch09Ch09
Ch09
 
Ch08
Ch08Ch08
Ch08
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Ch03
Ch03Ch03
Ch03
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Ch05
Ch05Ch05
Ch05
 
Chapter 13 - Recursion
Chapter 13 - RecursionChapter 13 - Recursion
Chapter 13 - Recursion
 
Ch02
Ch02Ch02
Ch02
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16
 
Ch06
Ch06Ch06
Ch06
 
M C6java3
M C6java3M C6java3
M C6java3
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
 
Lab5
Lab5Lab5
Lab5
 

Ă„hnlich wie Class 4: Making Procedures

evaluation rules
evaluation rulesevaluation rules
evaluation rulesRajendran
 
procedures
proceduresprocedures
proceduresRajendran
 
Class 32: Interpreters
Class 32: InterpretersClass 32: Interpreters
Class 32: InterpretersDavid Evans
 
expressions
expressionsexpressions
expressionsRajendran
 
Ecet 370 week 1 lab
Ecet 370 week 1 labEcet 370 week 1 lab
Ecet 370 week 1 labagevpaswind1984
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5dplunkett
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismEelco Visser
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docxmccormicknadine86
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docxbissacr
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
Thesis Talk
Thesis TalkThesis Talk
Thesis TalkBhavyaRawal
 
PYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxPYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxgeorgejustymirobi1
 

Ă„hnlich wie Class 4: Making Procedures (20)

evaluation rules
evaluation rulesevaluation rules
evaluation rules
 
procedures
proceduresprocedures
procedures
 
Class 32: Interpreters
Class 32: InterpretersClass 32: Interpreters
Class 32: Interpreters
 
expressions
expressionsexpressions
expressions
 
11 ruby methods
11 ruby methods11 ruby methods
11 ruby methods
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Ecet 370 week 1 lab
Ecet 370 week 1 labEcet 370 week 1 lab
Ecet 370 week 1 lab
 
7 Methods and Functional Programming
7  Methods and Functional Programming7  Methods and Functional Programming
7 Methods and Functional Programming
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docx
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docx
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Thesis Talk
Thesis TalkThesis Talk
Thesis Talk
 
PYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxPYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptx
 
C# p8
C# p8C# p8
C# p8
 

Mehr von David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeDavid Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in BitcoinDavid Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm ConfirmationsDavid Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting TransactionsDavid Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in ParadiseDavid Evans
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin ScriptDavid Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid Evans
 
The Blockchain
The BlockchainThe Blockchain
The BlockchainDavid Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key SignaturesDavid Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to CryptographyDavid Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the MassesDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinDavid Evans
 

Mehr von David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

KĂĽrzlich hochgeladen

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

KĂĽrzlich hochgeladen (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Class 4: Making Procedures

  • 1. Class 4: Making Procedures cs1120 Fall 2011 David Evans 30 August 2011
  • 2. Announcements PS1 is due Monday (electronic submission and paper submission): don’t wait to get started! Quiz 1 is Wednesday (in class) Chapters 1-4 of Course Book Chapters 1-3 of The Information Classes 1-5 (including questions from class notes) I haven’t forgotten about answering your questions from PS0. I will post my answers by tomorrow.
  • 3. Recap: Assigning Meanings Program ::= ε | ProgramElement Program ProgramElement ::= Expression | Definition Definition ::= (define Name Expression) Expression ::= PrimitiveExpression | NameExpression | ApplicationExpression | ProcedureExpression | IfExpression PrimitiveExpression ::= Number | true | false| PrimitiveProcedure NameExpression ::= Name ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε | Expression MoreExpressions ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε | Name Parameters IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt) This grammar generates (nearly) all surface forms in the Scheme. language. If we have a meaning rule for each grammar rule, we can determine the meaning of every Scheme program. 3
  • 4. Evaluation Rules: Last Class PrimitiveExpression ::= Number | true | false| PrimitiveProcedure Rule 1: If the expression is a primitive, it evaluates to its pre- defined value. NameExpression ::= Name Rule 2: A name evaluates to the value associated with that name. ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε | Expression MoreExpressions Rule 3: To evaluate an application expression: a) Evaluate all the subexpressions (in any order) b) Apply the value of the first subexpression to the values of all the other subexpressions. 4
  • 5. Last class: Rules for Application 1. Primitives. If the procedure to apply is a primitive procedure, just do it. 2. Constructed Procedures. If the procedure is a constructed procedure, evaluate the body of the procedure with each parameter name bound to the corresponding input expression value. This only makes sense if we know what a constructed procedure is! 5
  • 6. Constructing Procedures Program ::= ε | ProgramElement Program ProgramElement ::= Expression | Definition Definition ::= (define Name Expression) Expression ::= PrimitiveExpression | NameExpression | ApplicationExpression | ProcedureExpression | IfExpression PrimitiveExpression ::= Number | true | false| PrimitiveProcedure NameExpression ::= Name ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε | Expression MoreExpressions ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε | Name Parameters IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt) 6
  • 7. Constructing Procedures lambda means “make a procedure” Expression ::= ProcedureExpression ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε Parameters ::= Name Parameters 7
  • 8. Evaluation Rule 4: Lambda A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body. ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε | Name Parameters 8
  • 9. Lambda Expressions (lambda () true) (lambda (x) (* x x)) (lambda (a) (lambda (b) (+ a b)))
  • 10. Applying Compound Procedures Rule 3: To evaluate an application expression: ((lambda () (a) Evaluate all the subexpressions (in any order) true) (b) Apply the value of the first subexpression to the values of all the other subexpressions. 1120) Apply Rule for constructed procedures: Evaluate the body of the procedure with each parameter name bound to the corresponding input expression value. Evaluation Rule 4. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.
  • 11. Applying Compound Procedures Rule 3: To evaluate an application expression: ((lambda (x) (a) Evaluate all the subexpressions (in any order) (+ x 1000)) (b) Apply the value of the first subexpression to the values of all the other subexpressions. 120) Apply Rule for constructed procedures: Evaluate the body of the procedure with each parameter name bound to the corresponding input expression value. Evaluation Rule 4. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.
  • 12. Applying Compound Procedures Rule 3: To evaluate an application expression: ((lambda (x) (a) Evaluate all the subexpressions (in any order) (+ x 1000)) (b) Apply the value of the first subexpression to the values of all the other subexpressions. x) Apply Rule for constructed procedures: Evaluate the body of the procedure with each parameter name bound to the corresponding input expression value. Evaluation Rule 4. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.
  • 13. Applying Compound Procedures Rule 3: To evaluate an application expression: ((lambda (a) (a) Evaluate all the subexpressions (in any order) (lambda (b) (b) Apply the value of the first subexpression to the values of all the other subexpressions. (+ a b))) Apply Rule for constructed procedures: 5) Evaluate the body of the procedure with each parameter name bound to the corresponding input expression value. Evaluation Rule 4. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.
  • 14. Applying Compound Procedures Rule 3: To evaluate an application expression: (((lambda (a) (a) Evaluate all the subexpressions (in any order) (lambda (b) (b) Apply the value of the first subexpression to the values of all the other subexpressions. (+ a b))) Apply Rule for constructed procedures: 5) Evaluate the body of the procedure with each parameter name bound to the corresponding 6) input expression value. Evaluation Rule 4. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.
  • 15. Do we have everything we need to describe all computations?
  • 16. Language Elements Question from Class 2: When learning a foreign language, which elements are hardest to learn? Primitives Means of Combination Means of Abstraction 16
  • 17. Primitives: lots of them, and hard to learn real meaning (but its just memorization) Means of Combination Complex, but, all natural languages have similar ones [Chomsky] Sentence ::= Subject Object Verb (45%) Sentence ::= Subject Verb Object (42%) Welsh: “Lladdodd y ddraig y dyn.” Sentence ::= Verb Subject Object (9%) Sentence ::= Object Subject Verb (<1%) Scheme: Means of Abstraction: few of these, but tricky to learn differences across languages Tok Pisin (Papua New Guinea): mi (I), mitupela (he/she and I), mitripela (both of them and I), mipela (all of them and I), yumitupela (you and I), yumitripela (both of you and I), yumipela (all of you and I) Scheme: 17
  • 18. Charge PS1: Due Monday Wednesdays, 5-6:30pm (Jiamin, Rice 1xx) Thursdays, 9:45-11am (Dave, Rice 507) Thursdays, 10-11:30am (Peter, Rice 1xx) Thursdays, 1-2:30pm (Joseph, Rice 1xx) Thursdays, 4:30-6pm (Jonathan, Rice 1xx) Thursdays, 6-7:30pm (Jiamin, Rice 1xx) By Friday Finish reading Chapters 1-4, Gleick Chapters 1-3 Quiz 1: Wednesday