Iterative Refinement - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Iterative Refinement

Description:

hang (8) draw (2) Read! ( 19) Model 2. Characteristics. Still use symbols ... hang (8) draw (2) Read! ( 19) Program Design Philosophy. Two different structures ... – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 16
Provided by: BillL161
Category:

less

Transcript and Presenter's Notes

Title: Iterative Refinement


1
Iterative Refinement
2
Outline
  • Prerequisites
  • Complex Lists
  • Mutual Reference
  • Teachpack dir.ss
  • Objectives
  • Macro view of developing complex programs
  • Example processing directory trees

3
Background
  • As programs become more complex, it becomes less
    likely that you will have the mechanization right
    the first time
  • Using directory trees as an example, we will look
    at the process of developing and refining programs

4
The Problem
  • We want to do some analysis on file directories
  • Scheme provides a handy way to read your computer
    hard drive and construct a representation of the
    directory and file structure.
  • Calculate the total storage used by a directory
    tree
  • Before we look at that structures, let's follow
    the thought process that led up to it.

TS (DIR)
Read! (10)
Libs (DIR)
Text (DIR)
Code (DIR)
Docs (DIR)
part1 (99)
part2 (52)
hang (8)
Read! (19)
part3 (17)
draw (2)
5
Model 1
  • Characteristics
  • Use symbols for file names
  • Use lists for directories
  • Problems
  • Directories have attributes in addition to file
    lists

TS (DIR)
Read! (10)
Libs (DIR)
Text (DIR)
Code (DIR)
Docs (DIR)
part1 (99)
part2 (52)
hang (8)
Read! (19)
part3 (17)
draw (2)
6
Model 2
  • Characteristics
  • Still use symbols for file names
  • Use structure for directories containing lists of
    other directories and files
  • Problems
  • Files also have attributes

TS (DIR)
Read! (10)
Libs (DIR)
Text (DIR)
Code (DIR)
Docs (DIR)
part1 (99)
part2 (52)
hang (8)
Read! (19)
part3 (17)
draw (2)
7
Model 3
  • Characteristics
  • Use structure for files with attributes like
    name, size, and content
  • Use structure for directories containing lists of
    other directories and files

TS (DIR)
Read! (10)
Libs (DIR)
Text (DIR)
Code (DIR)
Docs (DIR)
part1 (99)
part2 (52)
hang (8)
Read! (19)
part3 (17)
draw (2)
8
Program Design Philosophy
  • Two different structures
  • (make-file name size content)
  • (make-dir name dirs files)
  • where dirs and files are separate lists
  • Three collections to process
  • Directory structure
  • List of directories
  • List of files
  • Probably need three programs to process these
    collections

9
Program Design
  • dir-size dir -gt number
  • Returns the sum of the sizes of a directory's
  • directory list and file list
  • dir-list-size dir-list -gt number
  • returns the total size of a directory list
  • if the list is empty -gt return 0
  • else -gt return (dir-size first)
  • (dir-list-size rest)
  • file-list-size file-list -gt number
  • returns the total size of a file list
  • if the list is empty -gt return 0
  • else -gt return (file-size first)
  • (file-list-size rest)

10
(No Transcript)
11
Actual Code 1
  • provided by teachpack dir.ss
  • (define-struct file (name size content))
  • (define-struct dir (name dirs files))
  • (define directory-name "E\\TECH\\CS1321")
  • (define my-dir (create-dir directory-name))
  • dir-size dir -gt number
  • Returns the sum of the sizes of its
  • directory list and file list
  • (define (dir-size here)
  • ( (dir-list-size (dir-dirs here))
  • (file-list-size (dir-files here))))

12
Actual Code 2
  • dir-list-size dir-list -gt number
  • if the list is empty -gt return 0
  • else -gt return (dir-size first)
  • (dir-list-size rest)
  • (define (dir-list-size my-list)
  • (cond (empty? my-list) 0
  • else ( (dir-size (first my-list))
  • (dir-list-size (rest
    my-list)))))
  • file-list-size file-list -gt number
  • if the list is empty -gt return 0
  • else -gt return (file-size first)
  • (file-list-size rest)
  • (define (file-list-size my-list)
  • (cond (empty? my-list) 0
  • else ( (file-size (first my-list))
  • (file-list-size (rest
    my-list)))))

13
Questions?
14
Summary
  • You should now know
  • Macro view of developing complex programs
  • Example processing directory trees

15
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com