SlideShare a Scribd company logo
Class 3:
   Rules of
   Evaluation


David Evans
cs1120 Fall 2011
Menu
Describing Languages
Questions from Notes
  Computing photomosaics, non-recursive languages,
    hardest language elements to learn
Scheme: Grammar and Rules of Evaluation




                                                     2
Code written by
     humans
                                  Compiler translates
                                  from code in a high-
Compiler/Interpreter              level language to
                                  machine code.
Code machine can run
  Scheme uses an interpreter. An interpreter is like a
  compiler, except it runs quickly and quietly on small
  bits of code at a time.
John Backus
Chemistry major at UVA
  (entered 1943)
Flunked out after second
  semester
Joined IBM as programmer
  in 1950
Developed Fortran, first
  commercially successful
  programming language
  and compiler              John Backus, 1924 – 2007
IBM 704 Fortran manual, 1956
Describing Languages
Fortran language was described using English
   Imprecise
   Verbose, lots to read
   Ad hoc
      DO 10 I=1.10
        Assigns 1.10 to the variable DO10I
      DO 10 I=1,10
        Loops for I = 1 to 10
     (Often incorrectly blamed for loss of Mariner-I)
Backus wanted a precise way of describing a language
Backus Naur Form
  symbol ::= replacement
    We can replace symbol with replacement
        A ::= B means anywhere you have an A,
               you can replace it with a B.

  nonterminal – symbol that appears on left side of
    rule
  terminals – symbol that never appears on the left
    side of a rule
Note: this is named for John Backus for being the first person to advocate using it for
describing programming languages, but linguists were using similar techniques much earlier.
                                                                                              7
Recap: Zero, One, Infinity

word ::= anti-word               This rule can make 0 words.



word ::= hippopotomonstrosesquipedaliophobia
                                   This rule can make 1 word.

word ::= anti-word
word ::= hippopotomonstrosesquipedaliophobia
          These two rules can make infinitely many words,
          enough to express all ideas in the universe!
                                                                8
Simple BNF Grammar
s ::= 0s
s ::= 0




                            9
Rapid Exponential Growth
Question from Class 1: What other things have changed as
much as (or more that!) computing power in your lifetime?

 Communication (global IP traffic, PB/month) (Alex)
 Energy Consumption (world energy use, TW) (Filip)
 Human (number of cells) (Ouamdwipwaw)
 Knowledge (Tyson’s measure) (Deirdre Regan)
 National Debt (Michael)
 TV (number of pixels) (gtc5sn)
 Wealth (world GDP) (Chris Smith)


                                                            10
http://www.wolframalpha.com/input/?i=india+china+brazil+usa+gdp+1990-2011




                                                                            11
1991 value   2011 value       Growth     Doubling time
Energy Consumption (world              102,300      142,300 (2008)   1.39       38 years
energy use, TW) (Filip)
      Communication (global IP traffic, PB/month) (Alex)
Wealth (world GDP) (Chris        $21T           $60T (2008)          2.67       12 years
Smith)Energy Consumption (world energy use, TW) (Filip)
      Human (number of cells) (Ouamdwipwaw)
Knowledge (Tyson’s measure)                                                     15 years
(Deirdre Regan) (Tyson’s measure) (Deirdre Regan)
      Knowledge
National Debt Debt (Michael)
      National (Michael)               $3.2T (56% $14.7T (93% of     4.6        9 years
                                       of GDP)    GDP)
      TV (number of pixels) (gtc5sn)
TV (number of pixels) (gtc5sn)         486x243, 3   1920×1080, 500 2926         1.73 years
      Wealth (world GDP) (Chris Smith)
                                       channels =   channels =
                                       354292       1036800000
Computing Power/Dollar                                                          18 months
(Moore’s Law)
Communication (global IP               0.001        20,197           20M        9.9 months
traffic, PB/month) (Alex)
Human (number of cells)                1            50 Trillion      50         5.3 months
(Ouamdwipwaw)                                                        Trillion

                                                                                                12
Genome Sequencing
1990: Human Genome Project starts, estimate
$3B to sequence one genome ($0.50/base)

2000: Human
Genome Project
declared
complete, cost
~$300M


                         Whitehead Institute, MIT
                                                    13
$100,000,000
                                                                                                Cost to sequence human genome

                                                                                                                                                                                               Moore’s Law prediction
                                                                                                                                                                                               (halve every 18 months)
 $10,000,000




  $1,000,000




   $100,000




    $10,000




                                                                                                                                                                                                                                                      Jun 2010
                                                                                                                  Jun 2005
               Sep 2001
                          Feb 2002




                                                                                                                                                   Sep 2006
                                                                                                                                                              Feb 2007
                                                           May 2003




                                                                                                                                        Apr 2006
                                                                                            Aug 2004




                                                                                                                                                                                               May 2008



                                                                                                                                                                                                                                Aug 2009
                                                                                 Mar 2004


                                                                                                       Jan 2005


                                                                                                                             Nov 2005




                                                                                                                                                                                                                     Mar 2009


                                                                                                                                                                                                                                           Jan 2010
                                                Dec 2002




                                                                                                                                                                                    Dec 2007
                                     Jul 2002




                                                                                                                                                                         Jul 2007
                                                                      Oct 2003




                                                                                                                                                                                                          Oct 2008
                                                                                        14
 Data from National Human Genome Research Institute: http://www.genome.gov/sequencingcosts
$100,000,000
                                                                                                Cost to sequence human genome

                                                                                                                                                                                          Moore’s Law prediction
                                                                                                                                                                                         (halve every 18 months)
 $10,000,000




  $1,000,000




   $100,000




    $10,000                  Ion torrent Personal Genome Machine
               Sep 2001
                          Feb 2002




                                                                                                                                                   Sep 2006
                                                                                                                                                              Feb 2007
                                                           May 2003



                                                                                            Aug 2004



                                                                                                                             Nov 2005
                                                                                                                                        Apr 2006




                                                                                                                                                                                               May 2008



                                                                                                                                                                                                                                Aug 2009
                                                                                 Mar 2004


                                                                                                       Jan 2005




                                                                                                                                                                                                                     Mar 2009
                                                Dec 2002




                                                                                                                  Jun 2005




                                                                                                                                                                                                                                           Jan 2010
                                                                                                                                                                                                                                                      Jun 2010
                                                                                                                                                                                    Dec 2007
                                     Jul 2002



                                                                      Oct 2003




                                                                                                                                                                         Jul 2007



                                                                                                                                                                                                          Oct 2008
                                                                                        15
 Data from National Human Genome Research Institute: http://www.genome.gov/sequencingcosts
Doubling time: 38000 in 2 years = 48 days




Human Genome Sequencing Using Unchained Base Reads on Self-Assembling DNA Nanoarrays. Radoje
Drmanac, Andrew B. Sparks, Matthew J. Callow, Aaron L. Halpern, Norman L. Burns, Bahram G. Kermani, Paolo
Carnevali, Igor Nazarenko, Geoffrey B. Nilsen, George Yeung, Fredrik Dahl, Andres Fernandez, Bryan Staker,
Krishna P. Pant, Jonathan Baccash, Adam P. Borcherding, Anushka Brownley, Ryan Cedeno, Linsu Chen, Dan
Chernikoff, Alex Cheung, Razvan Chirita, Benjamin Curson, Jessica C. Ebert, Coleen R. Hacker, Robert Hartlage,
Brian Hauser, Steve Huang,Church (Personal Genome Project)Calvin Kong, Tom Landers, Catherine Le,
                   George Yuan Jiang, Vitali Karpinchyk, Mark Koenig,
Jia Liu, Celeste E. McBride, Matt Morenzoni, Robert E. Morey, Karl Mutch, Helena Perazich, Kimberly Perry, Brock
A. Peters, Joe Peterson, Charit L. Pethiyagoda, Kaliprasad Pothuraju, Claudia Richter, Abraham M. Rosenbaum,
Shaunak Roy, Jay Shafto, Uladzislau Sharanhovich, Karen W. Shannon, Conrad G. Sheppy, Michel Sun, Joseph V.
Thakuria, Anne Tran, Dylan Vu, Alexander Wait Zaranek, Xiaodi Wu, Snezana Drmanac, Arnold R. Oliphant,
William C. Banyai, Bruce Martin, Dennis G. Ballinger, George M. Church, Clifford A. Reid. Science, January 2010.
Rules of
Evaluation
Scheme Grammar
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)
                                                                          18
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.
 What do we need to do to know the meaning of every Scheme program?



                                                                              19
Expressions and Values
  Expression    ::= PrimitiveExpression | NameExpression
                   | ApplicationExpression
                   | ProcedureExpression | IfExpression

When an expression with a value is evaluated, a
value is produced
Our goal is to define a meaning function, Eval, that
defines the value of every Scheme expression:
       Eval(Expression) Value
Today we do this informally with rules in English.
(In PS7 we will do it with a program.)

                                                           20
Primitive Expressions
PrimitiveExpression ::= Number | true | false | PrimitiveProcedure




                                                                     21
Evaluation Rule 1: Primitives
If the expression is a primitive, it
evaluates to its pre-defined value.
 >2               Primitives are the
 2                smallest units of
 > true           meaning: they can’t
 #t               be broken down
 >+               further, you need to
 #<primitive:+>   know what they mean.


                                         22
Name Expressions
Expression ::= NameExpression
NameExpression ::= Name




                                23
Evaluation Rule 2: Names
A name evaluates to the value associated
with that name.

    > (define two 2)
    > two
    2
            Caveat: this simple rule only works if the value
            associated with a name never changes (until PS5).


                                                                24
Application Expressions
Expression ::= Application Expression
ApplicationExpression
           ::= (Expression MoreExpressions)
MoreExpressions ::= ε
MoreExpressions ::= Expression MoreExpressions




                                                 25
Evaluation Rule 3: Application
3. To evaluation 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.


   (Expression0 Expression1 Expression2 … )
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.


                                                 27
Eval and Apply are
defined recursively.
                           Eval

Without Eval, there
would be no            Apply
Apply, without
Apply there would
be no Eval!

                                  28
Language Elements

   When learning a foreign
language, which elements are
      hardest to learn?



                           29
Charge
We will cover the rest of the rules
  Wednesday, then you will know enough to
  describe every possible computation!
Reading: should be finished with Chapter 3 now,
  Chapter 4, Gleick Ch 1-3 by Friday
PS1 is Due Monday: Find your assigned partner
  Get started earlier and take advantage of
      scheduled help hours

                                                  30

More Related Content

PPTX
Class 4: Making Procedures
PPTX
Lecture 2: Language
PPTX
Computing Cooperatively with People You Don't Trust
PDF
Telefonica
PDF
Umw Software Engineering Guest Lecture 05 Sep2007
PDF
Cloud Computing at Academia UOL
PPTX
LDD2012 - Do Digital Better in 2013
PDF
Department Presentation on Grace Hopper Conference 2008
Class 4: Making Procedures
Lecture 2: Language
Computing Cooperatively with People You Don't Trust
Telefonica
Umw Software Engineering Guest Lecture 05 Sep2007
Cloud Computing at Academia UOL
LDD2012 - Do Digital Better in 2013
Department Presentation on Grace Hopper Conference 2008

Similar to Lecture 3: Rules of Evaluation (20)

PDF
Data Science
PDF
CSTalks - The Multicore Midlife Crisis - 30 Mar
PPT
The Web, From Whence, & Whither
PPT
The Open University's Digilab - benefits for Library staff
PDF
Model-based Testing: Today And Tomorrow
PDF
History of programming languages
PDF
Persist or Die! Learning in World of Warcraft
PPTX
Kevin Ms Web Platform
PDF
Leitura complementar 07 - Linha do tempo, ling.progr
PDF
OSGi Provisioning With Apache ACE
PPTX
TMRE 2011 _Alcaraz _Data Visualization
DOC
Suggested Reading List.doc
PDF
FOSS, history and philosophy
PDF
NPI Evaluation of Wikimedia Foundation
PDF
The Power of Hierarchical Thinking - Ray Kurzweil - H+ Summit @ Harvard
PPTX
Big Data has Big Implications for Customer Experience Management
PDF
droidcon 2012: Developing Fault Tolerant, “German-Engineered” Android Apps, ...
PDF
Who Wants To Be a Munger
PDF
Broadband Access - beyond learning from the US
PPTX
The Rise and Rise of Mobile: a Guardian Case Study
Data Science
CSTalks - The Multicore Midlife Crisis - 30 Mar
The Web, From Whence, & Whither
The Open University's Digilab - benefits for Library staff
Model-based Testing: Today And Tomorrow
History of programming languages
Persist or Die! Learning in World of Warcraft
Kevin Ms Web Platform
Leitura complementar 07 - Linha do tempo, ling.progr
OSGi Provisioning With Apache ACE
TMRE 2011 _Alcaraz _Data Visualization
Suggested Reading List.doc
FOSS, history and philosophy
NPI Evaluation of Wikimedia Foundation
The Power of Hierarchical Thinking - Ray Kurzweil - H+ Summit @ Harvard
Big Data has Big Implications for Customer Experience Management
droidcon 2012: Developing Fault Tolerant, “German-Engineered” Android Apps, ...
Who Wants To Be a Munger
Broadband Access - beyond learning from the US
The Rise and Rise of Mobile: a Guardian Case Study
Ad

More from David Evans (20)

PPTX
Cryptocurrency Jeopardy!
PPTX
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
PPTX
Hidden Services, Zero Knowledge
PPTX
Anonymity in Bitcoin
PPTX
Midterm Confirmations
PPTX
Scripting Transactions
PPTX
How to Live in Paradise
PPTX
Bitcoin Script
PPTX
Mining Economics
PPTX
Mining
PPTX
The Blockchain
PPTX
Becoming More Paranoid
PPTX
Asymmetric Key Signatures
PPTX
Introduction to Cryptography
PPTX
Class 1: What is Money?
PPTX
Multi-Party Computation for the Masses
PPTX
Proof of Reserve
PPTX
Silk Road
PPTX
Blooming Sidechains!
PPTX
Useful Proofs of Work, Permacoin
Cryptocurrency Jeopardy!
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Hidden Services, Zero Knowledge
Anonymity in Bitcoin
Midterm Confirmations
Scripting Transactions
How to Live in Paradise
Bitcoin Script
Mining Economics
Mining
The Blockchain
Becoming More Paranoid
Asymmetric Key Signatures
Introduction to Cryptography
Class 1: What is Money?
Multi-Party Computation for the Masses
Proof of Reserve
Silk Road
Blooming Sidechains!
Useful Proofs of Work, Permacoin
Ad

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Spectroscopy.pptx food analysis technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
MYSQL Presentation for SQL database connectivity
Machine Learning_overview_presentation.pptx
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Assigned Numbers - 2025 - Bluetooth® Document
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectroscopy.pptx food analysis technology
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25-Week II
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MYSQL Presentation for SQL database connectivity

Lecture 3: Rules of Evaluation

  • 1. Class 3: Rules of Evaluation David Evans cs1120 Fall 2011
  • 2. Menu Describing Languages Questions from Notes Computing photomosaics, non-recursive languages, hardest language elements to learn Scheme: Grammar and Rules of Evaluation 2
  • 3. Code written by humans Compiler translates from code in a high- Compiler/Interpreter level language to machine code. Code machine can run Scheme uses an interpreter. An interpreter is like a compiler, except it runs quickly and quietly on small bits of code at a time.
  • 4. John Backus Chemistry major at UVA (entered 1943) Flunked out after second semester Joined IBM as programmer in 1950 Developed Fortran, first commercially successful programming language and compiler John Backus, 1924 – 2007
  • 5. IBM 704 Fortran manual, 1956
  • 6. Describing Languages Fortran language was described using English Imprecise Verbose, lots to read Ad hoc DO 10 I=1.10 Assigns 1.10 to the variable DO10I DO 10 I=1,10 Loops for I = 1 to 10 (Often incorrectly blamed for loss of Mariner-I) Backus wanted a precise way of describing a language
  • 7. Backus Naur Form symbol ::= replacement We can replace symbol with replacement A ::= B means anywhere you have an A, you can replace it with a B. nonterminal – symbol that appears on left side of rule terminals – symbol that never appears on the left side of a rule Note: this is named for John Backus for being the first person to advocate using it for describing programming languages, but linguists were using similar techniques much earlier. 7
  • 8. Recap: Zero, One, Infinity word ::= anti-word This rule can make 0 words. word ::= hippopotomonstrosesquipedaliophobia This rule can make 1 word. word ::= anti-word word ::= hippopotomonstrosesquipedaliophobia These two rules can make infinitely many words, enough to express all ideas in the universe! 8
  • 9. Simple BNF Grammar s ::= 0s s ::= 0 9
  • 10. Rapid Exponential Growth Question from Class 1: What other things have changed as much as (or more that!) computing power in your lifetime? Communication (global IP traffic, PB/month) (Alex) Energy Consumption (world energy use, TW) (Filip) Human (number of cells) (Ouamdwipwaw) Knowledge (Tyson’s measure) (Deirdre Regan) National Debt (Michael) TV (number of pixels) (gtc5sn) Wealth (world GDP) (Chris Smith) 10
  • 12. 1991 value 2011 value Growth Doubling time Energy Consumption (world 102,300 142,300 (2008) 1.39 38 years energy use, TW) (Filip) Communication (global IP traffic, PB/month) (Alex) Wealth (world GDP) (Chris $21T $60T (2008) 2.67 12 years Smith)Energy Consumption (world energy use, TW) (Filip) Human (number of cells) (Ouamdwipwaw) Knowledge (Tyson’s measure) 15 years (Deirdre Regan) (Tyson’s measure) (Deirdre Regan) Knowledge National Debt Debt (Michael) National (Michael) $3.2T (56% $14.7T (93% of 4.6 9 years of GDP) GDP) TV (number of pixels) (gtc5sn) TV (number of pixels) (gtc5sn) 486x243, 3 1920×1080, 500 2926 1.73 years Wealth (world GDP) (Chris Smith) channels = channels = 354292 1036800000 Computing Power/Dollar 18 months (Moore’s Law) Communication (global IP 0.001 20,197 20M 9.9 months traffic, PB/month) (Alex) Human (number of cells) 1 50 Trillion 50 5.3 months (Ouamdwipwaw) Trillion 12
  • 13. Genome Sequencing 1990: Human Genome Project starts, estimate $3B to sequence one genome ($0.50/base) 2000: Human Genome Project declared complete, cost ~$300M Whitehead Institute, MIT 13
  • 14. $100,000,000 Cost to sequence human genome Moore’s Law prediction (halve every 18 months) $10,000,000 $1,000,000 $100,000 $10,000 Jun 2010 Jun 2005 Sep 2001 Feb 2002 Sep 2006 Feb 2007 May 2003 Apr 2006 Aug 2004 May 2008 Aug 2009 Mar 2004 Jan 2005 Nov 2005 Mar 2009 Jan 2010 Dec 2002 Dec 2007 Jul 2002 Jul 2007 Oct 2003 Oct 2008 14 Data from National Human Genome Research Institute: http://www.genome.gov/sequencingcosts
  • 15. $100,000,000 Cost to sequence human genome Moore’s Law prediction (halve every 18 months) $10,000,000 $1,000,000 $100,000 $10,000 Ion torrent Personal Genome Machine Sep 2001 Feb 2002 Sep 2006 Feb 2007 May 2003 Aug 2004 Nov 2005 Apr 2006 May 2008 Aug 2009 Mar 2004 Jan 2005 Mar 2009 Dec 2002 Jun 2005 Jan 2010 Jun 2010 Dec 2007 Jul 2002 Oct 2003 Jul 2007 Oct 2008 15 Data from National Human Genome Research Institute: http://www.genome.gov/sequencingcosts
  • 16. Doubling time: 38000 in 2 years = 48 days Human Genome Sequencing Using Unchained Base Reads on Self-Assembling DNA Nanoarrays. Radoje Drmanac, Andrew B. Sparks, Matthew J. Callow, Aaron L. Halpern, Norman L. Burns, Bahram G. Kermani, Paolo Carnevali, Igor Nazarenko, Geoffrey B. Nilsen, George Yeung, Fredrik Dahl, Andres Fernandez, Bryan Staker, Krishna P. Pant, Jonathan Baccash, Adam P. Borcherding, Anushka Brownley, Ryan Cedeno, Linsu Chen, Dan Chernikoff, Alex Cheung, Razvan Chirita, Benjamin Curson, Jessica C. Ebert, Coleen R. Hacker, Robert Hartlage, Brian Hauser, Steve Huang,Church (Personal Genome Project)Calvin Kong, Tom Landers, Catherine Le, George Yuan Jiang, Vitali Karpinchyk, Mark Koenig, Jia Liu, Celeste E. McBride, Matt Morenzoni, Robert E. Morey, Karl Mutch, Helena Perazich, Kimberly Perry, Brock A. Peters, Joe Peterson, Charit L. Pethiyagoda, Kaliprasad Pothuraju, Claudia Richter, Abraham M. Rosenbaum, Shaunak Roy, Jay Shafto, Uladzislau Sharanhovich, Karen W. Shannon, Conrad G. Sheppy, Michel Sun, Joseph V. Thakuria, Anne Tran, Dylan Vu, Alexander Wait Zaranek, Xiaodi Wu, Snezana Drmanac, Arnold R. Oliphant, William C. Banyai, Bruce Martin, Dennis G. Ballinger, George M. Church, Clifford A. Reid. Science, January 2010.
  • 18. Scheme Grammar 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) 18
  • 19. 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. What do we need to do to know the meaning of every Scheme program? 19
  • 20. Expressions and Values Expression ::= PrimitiveExpression | NameExpression | ApplicationExpression | ProcedureExpression | IfExpression When an expression with a value is evaluated, a value is produced Our goal is to define a meaning function, Eval, that defines the value of every Scheme expression: Eval(Expression) Value Today we do this informally with rules in English. (In PS7 we will do it with a program.) 20
  • 21. Primitive Expressions PrimitiveExpression ::= Number | true | false | PrimitiveProcedure 21
  • 22. Evaluation Rule 1: Primitives If the expression is a primitive, it evaluates to its pre-defined value. >2 Primitives are the 2 smallest units of > true meaning: they can’t #t be broken down >+ further, you need to #<primitive:+> know what they mean. 22
  • 23. Name Expressions Expression ::= NameExpression NameExpression ::= Name 23
  • 24. Evaluation Rule 2: Names A name evaluates to the value associated with that name. > (define two 2) > two 2 Caveat: this simple rule only works if the value associated with a name never changes (until PS5). 24
  • 25. Application Expressions Expression ::= Application Expression ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε MoreExpressions ::= Expression MoreExpressions 25
  • 26. Evaluation Rule 3: Application 3. To evaluation 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. (Expression0 Expression1 Expression2 … )
  • 27. 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. 27
  • 28. Eval and Apply are defined recursively. Eval Without Eval, there would be no Apply Apply, without Apply there would be no Eval! 28
  • 29. Language Elements When learning a foreign language, which elements are hardest to learn? 29
  • 30. Charge We will cover the rest of the rules Wednesday, then you will know enough to describe every possible computation! Reading: should be finished with Chapter 3 now, Chapter 4, Gleick Ch 1-3 by Friday PS1 is Due Monday: Find your assigned partner Get started earlier and take advantage of scheduled help hours 30