1 / 12

Templates

Templates. CS 5010 Program Design Paradigms “ Bootcamp ” Lesson 1.4. Learning Objectives for This Lesson. By the time you finish this lesson, you should be able to: explain what a destructor template is write destructor templates for typical data. DDR Step 5: Destructor Template.

mikko
Télécharger la présentation

Templates

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Templates CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.4

  2. Learning Objectives for This Lesson • By the time you finish this lesson, you should be able to: • explain what a destructor template is • write destructor templates for typical data.

  3. DDR Step 5: Destructor Template The destructor template (or just the template, for short) gives a skeleton for functions that examine or use the data. Once you write the template, writing the function is just a matter of filling in the blanks. This step is a little more complicated than the preceding ones, so we have a recipe for that, too!

  4. The template recipe

  5. Let's see where we are

  6. In this lesson

  7. Lesson Outline In this lesson, we'll learn how to apply the template recipe to itemization, compound, and mixed data. Itemization Data will require Steps 1 and 2 of the recipe Compound Data requires only Step 3 of the recipe. Mixed data will require Steps 1-4 of the recipe

  8. How to write a template for itemization data source file: 01-2-traffic-light-template.rkt

  9. How to write a template for compound data This one is a little easier, so we don't need a video The constructor template The structure definition No subclasses, so no cond. The selector functions give you the pieces of data that you can calculate with. The interpretation of each field (define-struct book (author title on-hand price)) ;; A Book is a ;; (make-book String String Number Number) ;; Interpretation: ;; author is the author’s name ;; title is the title ;; on-hand is the number of copies on hand ;; price is the price in USD ;; book-fn : Book -> ?? (define (book-fn b) (... (book-author b) (book-title b) (book-on-hand b) (book-price b))) source file: 01-2-book-template.rkt

  10. How to write a template for mixed data source file: 01-4-bar-order-template.rkt

  11. Summary You should now be able to write a template for itemization, compound, and mixed data.

  12. Next Steps Study the files in the examples folder. If you have questions about this lesson, ask them on the Discussion Board Do the Guided Practices Go on to the next lesson

More Related