SlideShare una empresa de Scribd logo
1 de 11
Descargar para leer sin conexión
Recursive Data Definitions Everywhere CS 5010 Program Design Paradigms “Bootcamp” Week 03, Lesson 2 TexPoint fonts used in EMF.  Read the TexPoint manual before you delete this box.: AAA 1
Lists of Structures (define-struct payroll-entry    (name ssn position     current-hrs-worked pay-rate current-pay ytd-pay)) ;; A PayrollEntry is a  ;; (make-payroll-entry  ;;   String Number String  ;;   Number NumberNumberNumber) ;; where: ;; name                   is the employee's name ;; ssn                    is the employee's Social Security Number ;; position               is the the employee's position ;; current-hrs-worked     is the number of hours the employee has worked  ;;                         in the current pay period ;; pay-rate               is the employee's pay in $/hr ;; current-pay            is the amount the employee is to be paid ;;                         for the current pay period ;; ytd-pay                is the employee's total pay for the current year ;;                         through the current pay period.
Examples (define entry1 (make-payroll-entry                  "Joe" 123456789 "teaching assistant"                 0 20.00 0 1000)) (define entry2 (make-payroll-entry                 "Mitch" 987654321 "professor"                 10 100.00 1000. 10000.))
;; update-entry : PayRollEntry Number -> PayRollEntry ;; produces a payroll entry like the given one,  ;; except that current-hrs-worked is updated to the given  ;; number, and current-pay and ytd-pay are updated ;; accordingly. ;; example: ;(update-entry entry1 10)  ;= (make-payroll-entry ;   "Joe" 123456789 "teaching assistant" ;   200 20.00 400.0 1400) update-entry
update-entry (cont’d) ;; Design Strategy: structural decomposition on entry [PayrollEntry] (define (update-entry entry hrs)   (make-payroll-entry    (payroll-entry-name entry)    (payroll-entry-ssn entry)    (payroll-entry-position entry)    hrs    (payroll-entry-pay-rate entry)    (* hrs (payroll-entry-pay-rate entry)) ; the pay for      	                                   ; this period    (+ (payroll-entry-ytd-pay entry)       (* hrs (payroll-entry-pay-rate entry)))))
Exercise: Observe that     (* hrs (payroll-entry-pay-rate entry)) occurs twice in the code. What information does this quantity represent? Design a function to compute this. Rewrite update-entry to use your new function.
But there are many people in our company! ;; A ListOfPayrollEntries (LoPE) is one of ;; -- empty ;; -- (cons PayrollEntryLoPE) ;; A Payroll is a LoPE
Exercise: ;; raise-all : Payroll * Number -> Payroll ;; Produces a payroll like the given payroll, but with everyone's ;; pay rate increased by the given number. ;(raise-all (list entry1 entry2) 0.10) ;= (list ;   (make-payroll-entry  ;    "Joe" 123456789 "teaching assistant" ;    0 22.00 0 1000) ;   (make-payroll-entry ;    "Mitch" 987654321 "professor" ;    10 110.00 1100. 10000.)) What does the example show us that isn’t obvious from the purpose statement?
Exercise: ;; rename-position : Payroll * String * String ;; Given a payroll, an old position name, and a new position name, ;; returns a payroll like the given one, except all entries matching  ;; the old position name are updated.
An Example/Test ;(rename-position  ; (list entry1 entry2) ; "teaching assistant" ; "grader") ;= (list ;   (make-payroll-entry  ;    "Joe" 123456789 "teaching assistant" ;    0 20.00 0 1000) ;   (make-payroll-entry ;    "Mitch" 987654321 "professor" ;    10 100.00 1000. 10000.)) This test is insufficient!  How could you write an incorrect function that would still pass this test?
Summary Lists of structures occur all the time Important to have interpretation in the data defs! The recipe is your friend! Study the tests:   always ask:  how could a program pass the tests and still be wrong?

Más contenido relacionado

La actualidad más candente

Clojure testing with Midje
Clojure testing with MidjeClojure testing with Midje
Clojure testing with Midjeinovex GmbH
 
Testing with Midje
Testing with MidjeTesting with Midje
Testing with MidjeTobias Bayer
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
Practice create procedure
Practice   create procedurePractice   create procedure
Practice create procedurecit gubbi
 
怖くない!Implicit!
怖くない!Implicit!怖くない!Implicit!
怖くない!Implicit!HonMarkHunt
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices pythonUtkarsh Asthana
 

La actualidad más candente (9)

Lab 07
Lab 07Lab 07
Lab 07
 
Clojure testing with Midje
Clojure testing with MidjeClojure testing with Midje
Clojure testing with Midje
 
Testing with Midje
Testing with MidjeTesting with Midje
Testing with Midje
 
Arrays
ArraysArrays
Arrays
 
Call by value
Call by valueCall by value
Call by value
 
Practice create procedure
Practice   create procedurePractice   create procedure
Practice create procedure
 
怖くない!Implicit!
怖くない!Implicit!怖くない!Implicit!
怖くない!Implicit!
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices python
 
Document
DocumentDocument
Document
 

Destacado

Lesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresLesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresMitchell Wand
 
Week 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsWeek 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsMitchell Wand
 

Destacado (6)

Class 10
Class 10Class 10
Class 10
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Lesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresLesson 05 Analyzing Structures
Lesson 05 Analyzing Structures
 
Week 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsWeek 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data Definitions
 
Consolas de jogo
Consolas de jogoConsolas de jogo
Consolas de jogo
 
T E C H N O L O G Y
T E C H N O L O G YT E C H N O L O G Y
T E C H N O L O G Y
 

Similar a Week 03 Lesson 02 recursive data definitions everywhere

MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docx
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docxPart A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docx
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docxpauline234567
 
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdf
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdfThe solution is as belowEmployeeDemo.javaimport java.util.Scann.pdf
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdfaparnatiwari291
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfanwarsadath111
 
MYSQL Aggregate Functions
MYSQL Aggregate FunctionsMYSQL Aggregate Functions
MYSQL Aggregate FunctionsLeroy Blair
 
Sql task answers
Sql task answersSql task answers
Sql task answersNawaz Sk
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functionssinhacp
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxmetriohanzel
 
How to Create a l10n Payroll Structure
How to Create a l10n Payroll StructureHow to Create a l10n Payroll Structure
How to Create a l10n Payroll StructureOdoo
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfsharnapiyush773
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Charles Givre
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdfaamousnowov
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfpnaran46
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdffashioncollection2
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Thuan Nguyen
 

Similar a Week 03 Lesson 02 recursive data definitions everywhere (20)

MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docx
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docxPart A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docx
Part A VSM SampleNameChinue UeckerTitle Employment Lead ProcessDa.docx
 
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdf
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdfThe solution is as belowEmployeeDemo.javaimport java.util.Scann.pdf
The solution is as belowEmployeeDemo.javaimport java.util.Scann.pdf
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
MYSQL Aggregate Functions
MYSQL Aggregate FunctionsMYSQL Aggregate Functions
MYSQL Aggregate Functions
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptx
 
How to Create a l10n Payroll Structure
How to Create a l10n Payroll StructureHow to Create a l10n Payroll Structure
How to Create a l10n Payroll Structure
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdf
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16
 
Structure and union
Structure and unionStructure and union
Structure and union
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
 

Week 03 Lesson 02 recursive data definitions everywhere

  • 1. Recursive Data Definitions Everywhere CS 5010 Program Design Paradigms “Bootcamp” Week 03, Lesson 2 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1
  • 2. Lists of Structures (define-struct payroll-entry (name ssn position current-hrs-worked pay-rate current-pay ytd-pay)) ;; A PayrollEntry is a ;; (make-payroll-entry ;; String Number String ;; Number NumberNumberNumber) ;; where: ;; name is the employee's name ;; ssn is the employee's Social Security Number ;; position is the the employee's position ;; current-hrs-worked is the number of hours the employee has worked ;; in the current pay period ;; pay-rate is the employee's pay in $/hr ;; current-pay is the amount the employee is to be paid ;; for the current pay period ;; ytd-pay is the employee's total pay for the current year ;; through the current pay period.
  • 3. Examples (define entry1 (make-payroll-entry "Joe" 123456789 "teaching assistant" 0 20.00 0 1000)) (define entry2 (make-payroll-entry "Mitch" 987654321 "professor" 10 100.00 1000. 10000.))
  • 4. ;; update-entry : PayRollEntry Number -> PayRollEntry ;; produces a payroll entry like the given one, ;; except that current-hrs-worked is updated to the given ;; number, and current-pay and ytd-pay are updated ;; accordingly. ;; example: ;(update-entry entry1 10) ;= (make-payroll-entry ; "Joe" 123456789 "teaching assistant" ; 200 20.00 400.0 1400) update-entry
  • 5. update-entry (cont’d) ;; Design Strategy: structural decomposition on entry [PayrollEntry] (define (update-entry entry hrs) (make-payroll-entry (payroll-entry-name entry) (payroll-entry-ssn entry) (payroll-entry-position entry) hrs (payroll-entry-pay-rate entry) (* hrs (payroll-entry-pay-rate entry)) ; the pay for ; this period (+ (payroll-entry-ytd-pay entry) (* hrs (payroll-entry-pay-rate entry)))))
  • 6. Exercise: Observe that (* hrs (payroll-entry-pay-rate entry)) occurs twice in the code. What information does this quantity represent? Design a function to compute this. Rewrite update-entry to use your new function.
  • 7. But there are many people in our company! ;; A ListOfPayrollEntries (LoPE) is one of ;; -- empty ;; -- (cons PayrollEntryLoPE) ;; A Payroll is a LoPE
  • 8. Exercise: ;; raise-all : Payroll * Number -> Payroll ;; Produces a payroll like the given payroll, but with everyone's ;; pay rate increased by the given number. ;(raise-all (list entry1 entry2) 0.10) ;= (list ; (make-payroll-entry ; "Joe" 123456789 "teaching assistant" ; 0 22.00 0 1000) ; (make-payroll-entry ; "Mitch" 987654321 "professor" ; 10 110.00 1100. 10000.)) What does the example show us that isn’t obvious from the purpose statement?
  • 9. Exercise: ;; rename-position : Payroll * String * String ;; Given a payroll, an old position name, and a new position name, ;; returns a payroll like the given one, except all entries matching ;; the old position name are updated.
  • 10. An Example/Test ;(rename-position ; (list entry1 entry2) ; "teaching assistant" ; "grader") ;= (list ; (make-payroll-entry ; "Joe" 123456789 "teaching assistant" ; 0 20.00 0 1000) ; (make-payroll-entry ; "Mitch" 987654321 "professor" ; 10 100.00 1000. 10000.)) This test is insufficient! How could you write an incorrect function that would still pass this test?
  • 11. Summary Lists of structures occur all the time Important to have interpretation in the data defs! The recipe is your friend! Study the tests: always ask: how could a program pass the tests and still be wrong?

Notas del editor

  1. Welcome to Week 3, Lesson 2: Recursive Data Definitions EverywhereIn this lesson, we will see some of the many ways in which recursive data definitions can arise.