SlideShare a Scribd company logo
1 of 32
Class 22: Stateful
Evaluation Rules




                     cs1120 Fall 2011
                     David Evans
                     14 October 2011
Plan
Names and Places
Environments
Revised Evaluation Rules
Exam 1




                           2
Dennis Ritchie, 1941-2011




1972 (with Ken Thompson and PDP-11)


                                      3
Fortran
                                             LISP         (1955, Backus)
Programming Languages                 (1959, McCarthy)


                                                                   Algol
    Brief History of


                                                                  (1960)

                                      Scheme
                           PS1-5    (1975, S&S)                  C                    Simula
                                                           (1969, Ritchie)            (1967)



                        PS6-7                                                 C++
                                                                       (1983, Stroustrup)
                              Python
                        (1991, von Rossum)
                                                            Java
                                        JavaScript                           PS8
                                                         (1995, Sun)
                                       (1995, Eich)



                                                                                               4
Why design a new
programming
language?


 C: wanted both
 portability and
 low-level machine
 access



                     5
Multics

Ken Thompson and Dennis Ritchie




                                                  Windows and Symbian:
                                                  not direct descendants of
                                                  Unix, but they are mostly
                                                  programmed in C
    Android   iOS

                              Image: cc http://en.wikipedia.org/wiki/File:Unix_history-simple.svg   6
“Here’s how to
succeed: by being
lucky. Grab on to
something that’s
moving pretty fast.
Let yourself be
carried on when
you’re in the right
place at the right
time.”
        Dennis Ritchie


                         7
Recap: Names and Places
A name refers to a place for storing a value.
define creates a new place
(set! name expr) changes the value in the place
  name to the value of expr
mcons creates a mutable pair of two new places
  (set-mcar! pair expr) changes the value in the mcar
    place of pair to the value of expr
  (set-mcdr! pair expr) changes the value in the mcdr
    place of pair to the value of expr

                                                        8
Application and Places
(lambda (x) …) also creates a new place named x
   The passed argument is put in that place


 > (define x 3)               x:3
 > ((lambda (x) x) 4)
                               x:4
 4
 >x
 3                       How are these
                         places different?
                                                  9
Location, Location, Location
Places live in frames
An environment is a frame and a pointer to a
  parent environment
All environments except the global environment
  have exactly one parent environment, global
  environment has no parent
Application creates a new environment


                                                 10
Environments


global              + : #<primitive:+>
environment         null? : #<primitive:null?>
                   x:3



              The global environment points to the outermost frame.
              It starts with all Scheme built-ins defined.


   > (define x 3)
                                                                      11
Stateful Definition Evaluation Rule
A definition creates a new place with the
definition’s name in the frame associated with
the evaluation environment. The value in the
place is value of the definition’s expression.

If there is already a place with the name in the
current frame, the definition replaces the old
place with a new place and value.

                                                   12
Stateful Name Evaluation Rule
To evaluate a name expression, search the
evaluation environment’s frame for a place with a
name that matches the name in the expression.
If such a place exists, the value of the name
expression is the value in that place.
Otherwise, the value of the name expression is the
result of evaluating the name expression in the
parent environment. If the evaluation environment
has no parent, the name is not defined and the
name expression evaluates to an error.

                                                     13
Evaluating Names
To evaluate a name expression,
search the evaluation                  global
environment’s frame for a place           env                             x:3
with a name that matches the
name in the expression.
If such a place exists, the value of
the name expression is the value
in that place.
                                                  x : 17
Otherwise, the value of the name
expression is the result of
evaluating the name expression
in the parent environment. If the
evaluation environment has no
parent, the name is not defined                             y:3
and the name expression
evaluates to an error.
                                                How are environments like this created?
                                                                                          14
Procedures


global         + : #<primitive:+>
environment                         null? : #<primitive:null?>
                  x:3


                                      double: ??




  > (define double (lambda (x) (+ x x)))

                                                                 15
How to Draw a Procedure
A procedure needs both code and an
  environment
  We’ll see why soon
We draw procedures like this:
                                       Environment
                                       pointer



                       environment:
                       parameters: x
                       body: (+ x x)


                                                     16
How to Draw a Procedure
                (for artists only)
                         Environment
                         pointer




                   x
Input parameters
                             (+ x x)
(in mouth)                       Procedure Body




                                                  17
Procedures


global          + : #<primitive:+>
environment                           null? : #<primitive:null?>
                   x:3


                                         double:




> (define double                     environment:
                                     parameters: x
                                     body: (+ x x)
     (lambda (x) (+ x x)))

                                                                   18
Application
Old rule: (Substitution model)

  Apply Rule 2: Constructed Procedures. To
  apply a constructed procedure, evaluate the
  body of the procedure with each formal
  parameter replaced by the corresponding
  actual argument expression value.


                                                19
Stateful Application Rule
        (Constructed Procedures)
To apply a constructed procedure:
1. Construct a new environment, whose parent is the
   environment of the applied procedure.
2. For each procedure parameter, create a place in the
   frame of the new environment with the name of the
   parameter. Evaluate each operand expression in the
   environment or the application and initialize the value
   in each place to the value of the corresponding
   operand expression.
3. Evaluate the body of the procedure in the newly
   created environment. The resulting value is the value
   of the application.
                                                             20
1.       Construct a new             global
                                     environment
         environment, parent is
         procedure’s environment
                                          + : #<primitive:+>
         pointer
2.       Make places in that frame
                                               x:3     double:
         with the names of each
         parameter, and operand
         values
                                                     environment:
3.       Evaluate the body in the                    parameters: x
         new environment                             body: (+ x x)



                                          x:   4
     > (double 4)                        (+ x x)
     8
                                                                     21
x:3
What would
create this
environment?
                          x : 17




                                   y:3
Think about this, we’ll
discuss it next week…

                                               22
Exam 1




         23
Overall Results


5 below 70                                            5 above 100


Come to my office
hours or arrange a
meeting to go
                          Solutions/comments will be posted on
over things you           course site later by tomorrow.
didn’t understand


                                                                    24
Honor
15. Do you trust your classmates to follow the honor expectations in this class?
— Yes, I trust them completely.
— I worry that there may be a few transgressions, but I believe the vast majority
   of the class is honorable and it is fair and beneficial to rely on this.
— I think this class places too high a burden on students’ honor, and there are
   enough dishonorable students that it is unfair on the honorable students.
— I have reason to suspect that other students violated the honor policy on
0  problem sets.
— I have direct knowledge of other students violating the honor policy on
0  problem sets.
— I have reason to suspect that other students violated the honor policy on this
0  exam.
0
— I have direct knowledge of other students violating the honor policy on this
   exam.

                                                                                25
Honor Responses
Trust Completely



Between 1 and 2



   Vast Majority



       Too High


                   0   5   10   15   20   25   30   35


                                                         26
Problem 11
Define a procedure, count-tandem-repeats, that takes
as input a list, p, and a number, n. The output should be
the total number of times the first n elements of p are
consecutively repeated at the beginning of p.
Repetitions may not overlap.




                                                            27
28
(define (count-tandem-repeats p n)
 (count-prefix-repeats p (list-prefix p n)))




                                               29
(define (list-prefix p n)
 (if (= n 0) null
    (cons (car p) (list-prefix (cdr p) (- n 1)))))
  What is the asymptotic running time of list-prefix?




                                                        30
(define (contains-matching-prefix p q) ; question 10
 (or (null? q)
     (and (eq? (car p) (car q))
          (contains-matching-prefix (cdr p) (cdr q)))))

(define (list-prefix p n)
 (if (= n 0) null (cons (car p) (list-prefix (cdr p) (- n 1)))))

(define (count-prefix-repeats p q)
 (if (contains-matching-prefix p q)
    (+ 1 (count-prefix-repeats ((n-times cdr (length q)) p) q))
    0))

(define (count-tandem-repeats p n)
 (count-prefix-repeats p (list-prefix p n)))         Not defensive: errors if
                                                         (< (length p) n)

                                                                                31
Returning Exam 1
                                                                 Code from Chapter 8
(define (list-quicksort cf p)
  (if (null? p) null
      (list-append
        (list-quicksort cf
           (list-filter (lambda (el) (cf el (car p))) (cdr p)))
           (cons (car p)
                   (list-quicksort cf
                                 (list-filter (lambda (el) (not (cf el (car p)))) (cdr p)))))))

 (list-quicksort
    (lambda (s1 s2) (< (get-email-id s1) (get-email-id s2)))
    cs1120-students)

                                                                                                 32

More Related Content

What's hot

Deep Learning: R with Keras and TensorFlow
Deep Learning: R with Keras and TensorFlowDeep Learning: R with Keras and TensorFlow
Deep Learning: R with Keras and TensorFlowOswald Campesato
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp languageDavid Gu
 
Discrete Models in Computer Vision
Discrete Models in Computer VisionDiscrete Models in Computer Vision
Discrete Models in Computer VisionYap Wooi Hen
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowOswald Campesato
 
CS 354 Global Illumination
CS 354 Global IlluminationCS 354 Global Illumination
CS 354 Global IlluminationMark Kilgard
 

What's hot (7)

Deep Learning: R with Keras and TensorFlow
Deep Learning: R with Keras and TensorFlowDeep Learning: R with Keras and TensorFlow
Deep Learning: R with Keras and TensorFlow
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Discrete Models in Computer Vision
Discrete Models in Computer VisionDiscrete Models in Computer Vision
Discrete Models in Computer Vision
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
BMC 2012
BMC 2012BMC 2012
BMC 2012
 
Special topics in finance lecture 2
Special topics in finance   lecture 2Special topics in finance   lecture 2
Special topics in finance lecture 2
 
CS 354 Global Illumination
CS 354 Global IlluminationCS 354 Global Illumination
CS 354 Global Illumination
 

Viewers also liked

Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel SpaceDavid Evans
 
Quiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, SupsersizingQuiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, SupsersizingDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Class 6: Programming with Data
Class 6: Programming with DataClass 6: Programming with Data
Class 6: Programming with DataDavid Evans
 

Viewers also liked (7)

Lecture38
Lecture38Lecture38
Lecture38
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel Space
 
Lecture33
Lecture33Lecture33
Lecture33
 
Quiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, SupsersizingQuiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, Supsersizing
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Class 6: Programming with Data
Class 6: Programming with DataClass 6: Programming with Data
Class 6: Programming with Data
 
Selfish Mining
Selfish MiningSelfish Mining
Selfish Mining
 

Similar to Class 22: Stateful Evaluation Rules

LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийSigma Software
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Intro to threp
Intro to threpIntro to threp
Intro to threpHong Wu
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Class 11: Deeper List Procedures
Class 11: Deeper List ProceduresClass 11: Deeper List Procedures
Class 11: Deeper List ProceduresDavid Evans
 
Project - Deep Locality Sensitive Hashing
Project - Deep Locality Sensitive HashingProject - Deep Locality Sensitive Hashing
Project - Deep Locality Sensitive HashingGabriele Angeletti
 
Class 26: Objectifying Objects
Class 26: Objectifying ObjectsClass 26: Objectifying Objects
Class 26: Objectifying ObjectsDavid Evans
 
Class 32: Interpreters
Class 32: InterpretersClass 32: Interpreters
Class 32: InterpretersDavid Evans
 
Extending lifespan with Hadoop and R
Extending lifespan with Hadoop and RExtending lifespan with Hadoop and R
Extending lifespan with Hadoop and RRadek Maciaszek
 
Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Chris Richardson
 
ENBIS 2018 presentation on Deep k-Means
ENBIS 2018 presentation on Deep k-MeansENBIS 2018 presentation on Deep k-Means
ENBIS 2018 presentation on Deep k-Meanstthonet
 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standardsHector Garzo
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingFilip De Sutter
 
The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)Pierre Schaus
 

Similar to Class 22: Stateful Evaluation Rules (20)

LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Intro to threp
Intro to threpIntro to threp
Intro to threp
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Class 11: Deeper List Procedures
Class 11: Deeper List ProceduresClass 11: Deeper List Procedures
Class 11: Deeper List Procedures
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Project - Deep Locality Sensitive Hashing
Project - Deep Locality Sensitive HashingProject - Deep Locality Sensitive Hashing
Project - Deep Locality Sensitive Hashing
 
Class 26: Objectifying Objects
Class 26: Objectifying ObjectsClass 26: Objectifying Objects
Class 26: Objectifying Objects
 
Class 32: Interpreters
Class 32: InterpretersClass 32: Interpreters
Class 32: Interpreters
 
Extending lifespan with Hadoop and R
Extending lifespan with Hadoop and RExtending lifespan with Hadoop and R
Extending lifespan with Hadoop and R
 
Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)
 
ENBIS 2018 presentation on Deep k-Means
ENBIS 2018 presentation on Deep k-MeansENBIS 2018 presentation on Deep k-Means
ENBIS 2018 presentation on Deep k-Means
 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standards
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
 
The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 

More from 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
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid 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
 
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
 
Alternate Cryptocurrencies
Alternate CryptocurrenciesAlternate Cryptocurrencies
Alternate CryptocurrenciesDavid Evans
 

More from 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
 
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
 
Alternate Cryptocurrencies
Alternate CryptocurrenciesAlternate Cryptocurrencies
Alternate Cryptocurrencies
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Class 22: Stateful Evaluation Rules

  • 1. Class 22: Stateful Evaluation Rules cs1120 Fall 2011 David Evans 14 October 2011
  • 2. Plan Names and Places Environments Revised Evaluation Rules Exam 1 2
  • 3. Dennis Ritchie, 1941-2011 1972 (with Ken Thompson and PDP-11) 3
  • 4. Fortran LISP (1955, Backus) Programming Languages (1959, McCarthy) Algol Brief History of (1960) Scheme PS1-5 (1975, S&S) C Simula (1969, Ritchie) (1967) PS6-7 C++ (1983, Stroustrup) Python (1991, von Rossum) Java JavaScript PS8 (1995, Sun) (1995, Eich) 4
  • 5. Why design a new programming language? C: wanted both portability and low-level machine access 5
  • 6. Multics Ken Thompson and Dennis Ritchie Windows and Symbian: not direct descendants of Unix, but they are mostly programmed in C Android iOS Image: cc http://en.wikipedia.org/wiki/File:Unix_history-simple.svg 6
  • 7. “Here’s how to succeed: by being lucky. Grab on to something that’s moving pretty fast. Let yourself be carried on when you’re in the right place at the right time.” Dennis Ritchie 7
  • 8. Recap: Names and Places A name refers to a place for storing a value. define creates a new place (set! name expr) changes the value in the place name to the value of expr mcons creates a mutable pair of two new places (set-mcar! pair expr) changes the value in the mcar place of pair to the value of expr (set-mcdr! pair expr) changes the value in the mcdr place of pair to the value of expr 8
  • 9. Application and Places (lambda (x) …) also creates a new place named x The passed argument is put in that place > (define x 3) x:3 > ((lambda (x) x) 4) x:4 4 >x 3 How are these places different? 9
  • 10. Location, Location, Location Places live in frames An environment is a frame and a pointer to a parent environment All environments except the global environment have exactly one parent environment, global environment has no parent Application creates a new environment 10
  • 11. Environments global + : #<primitive:+> environment null? : #<primitive:null?> x:3 The global environment points to the outermost frame. It starts with all Scheme built-ins defined. > (define x 3) 11
  • 12. Stateful Definition Evaluation Rule A definition creates a new place with the definition’s name in the frame associated with the evaluation environment. The value in the place is value of the definition’s expression. If there is already a place with the name in the current frame, the definition replaces the old place with a new place and value. 12
  • 13. Stateful Name Evaluation Rule To evaluate a name expression, search the evaluation environment’s frame for a place with a name that matches the name in the expression. If such a place exists, the value of the name expression is the value in that place. Otherwise, the value of the name expression is the result of evaluating the name expression in the parent environment. If the evaluation environment has no parent, the name is not defined and the name expression evaluates to an error. 13
  • 14. Evaluating Names To evaluate a name expression, search the evaluation global environment’s frame for a place env x:3 with a name that matches the name in the expression. If such a place exists, the value of the name expression is the value in that place. x : 17 Otherwise, the value of the name expression is the result of evaluating the name expression in the parent environment. If the evaluation environment has no parent, the name is not defined y:3 and the name expression evaluates to an error. How are environments like this created? 14
  • 15. Procedures global + : #<primitive:+> environment null? : #<primitive:null?> x:3 double: ?? > (define double (lambda (x) (+ x x))) 15
  • 16. How to Draw a Procedure A procedure needs both code and an environment We’ll see why soon We draw procedures like this: Environment pointer environment: parameters: x body: (+ x x) 16
  • 17. How to Draw a Procedure (for artists only) Environment pointer x Input parameters (+ x x) (in mouth) Procedure Body 17
  • 18. Procedures global + : #<primitive:+> environment null? : #<primitive:null?> x:3 double: > (define double environment: parameters: x body: (+ x x) (lambda (x) (+ x x))) 18
  • 19. Application Old rule: (Substitution model) Apply Rule 2: Constructed Procedures. To apply a constructed procedure, evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value. 19
  • 20. Stateful Application Rule (Constructed Procedures) To apply a constructed procedure: 1. Construct a new environment, whose parent is the environment of the applied procedure. 2. For each procedure parameter, create a place in the frame of the new environment with the name of the parameter. Evaluate each operand expression in the environment or the application and initialize the value in each place to the value of the corresponding operand expression. 3. Evaluate the body of the procedure in the newly created environment. The resulting value is the value of the application. 20
  • 21. 1. Construct a new global environment environment, parent is procedure’s environment + : #<primitive:+> pointer 2. Make places in that frame x:3 double: with the names of each parameter, and operand values environment: 3. Evaluate the body in the parameters: x new environment body: (+ x x) x: 4 > (double 4) (+ x x) 8 21
  • 22. x:3 What would create this environment? x : 17 y:3 Think about this, we’ll discuss it next week… 22
  • 23. Exam 1 23
  • 24. Overall Results 5 below 70 5 above 100 Come to my office hours or arrange a meeting to go Solutions/comments will be posted on over things you course site later by tomorrow. didn’t understand 24
  • 25. Honor 15. Do you trust your classmates to follow the honor expectations in this class? — Yes, I trust them completely. — I worry that there may be a few transgressions, but I believe the vast majority of the class is honorable and it is fair and beneficial to rely on this. — I think this class places too high a burden on students’ honor, and there are enough dishonorable students that it is unfair on the honorable students. — I have reason to suspect that other students violated the honor policy on 0 problem sets. — I have direct knowledge of other students violating the honor policy on 0 problem sets. — I have reason to suspect that other students violated the honor policy on this 0 exam. 0 — I have direct knowledge of other students violating the honor policy on this exam. 25
  • 26. Honor Responses Trust Completely Between 1 and 2 Vast Majority Too High 0 5 10 15 20 25 30 35 26
  • 27. Problem 11 Define a procedure, count-tandem-repeats, that takes as input a list, p, and a number, n. The output should be the total number of times the first n elements of p are consecutively repeated at the beginning of p. Repetitions may not overlap. 27
  • 28. 28
  • 29. (define (count-tandem-repeats p n) (count-prefix-repeats p (list-prefix p n))) 29
  • 30. (define (list-prefix p n) (if (= n 0) null (cons (car p) (list-prefix (cdr p) (- n 1))))) What is the asymptotic running time of list-prefix? 30
  • 31. (define (contains-matching-prefix p q) ; question 10 (or (null? q) (and (eq? (car p) (car q)) (contains-matching-prefix (cdr p) (cdr q))))) (define (list-prefix p n) (if (= n 0) null (cons (car p) (list-prefix (cdr p) (- n 1))))) (define (count-prefix-repeats p q) (if (contains-matching-prefix p q) (+ 1 (count-prefix-repeats ((n-times cdr (length q)) p) q)) 0)) (define (count-tandem-repeats p n) (count-prefix-repeats p (list-prefix p n))) Not defensive: errors if (< (length p) n) 31
  • 32. Returning Exam 1 Code from Chapter 8 (define (list-quicksort cf p) (if (null? p) null (list-append (list-quicksort cf (list-filter (lambda (el) (cf el (car p))) (cdr p))) (cons (car p) (list-quicksort cf (list-filter (lambda (el) (not (cf el (car p)))) (cdr p))))))) (list-quicksort (lambda (s1 s2) (< (get-email-id s1) (get-email-id s2))) cs1120-students) 32