doc repairs and 'fil'->'file' printing change to dir.ss teachpack (at a teacher's request)

svn: r16500
This commit is contained in:
Matthew Flatt 2009-11-02 12:26:06 +00:00
parent 71387d274c
commit ccd6659100
2 changed files with 15 additions and 17 deletions

View File

@ -1,7 +1,8 @@
#lang scheme #lang scheme
(require htdp/error (require htdp/error
lang/prim) lang/prim
(only-in scheme/base [file-size s:file-size]))
(provide (provide
create-dir ; path -> Directory create-dir ; path -> Directory
@ -14,16 +15,12 @@
dir-files dir-files
; structure ; structure
(rename-out (fil? file?) file? make-file file-name file-content file-size
(make-fil make-file)
(fil-name file-name)
(fil-content file-content)
(fil-size file-size))
) )
;; Structures: ;; Structures:
(define-struct dir (name dirs files) #:transparent) (define-struct dir (name dirs files) #:transparent)
(define-struct fil (name size content) #:transparent) (define-struct file (name size content) #:transparent)
(define-primitive create-dir create-dir/proc) (define-primitive create-dir create-dir/proc)
@ -45,9 +42,9 @@
(make-dir (make-dir
(string->symbol (path->string (my-split-path d))) (string->symbol (path->string (my-split-path d)))
(explore (map (lambda (x) (build-path d x)) ds)) (explore (map (lambda (x) (build-path d x)) ds))
(map make-fil (map make-file
(map (compose string->symbol path->string) fs) (map (compose string->symbol path->string) fs)
(map (lambda (x) (if (file-exists? x) (file-size x) 0)) (map (lambda (x) (if (file-exists? x) (s:file-size x) 0))
(map (lambda (x) (build-path d x)) fs)) (map (lambda (x) (build-path d x)) fs))
(map (lambda (x) (if (link-exists? x) 'link null)) fs))))) (map (lambda (x) (if (link-exists? x) 'link null)) fs)))))
dirs)) dirs))
@ -76,6 +73,6 @@
;; option to expand the library ... ;; option to expand the library ...
;; cache it ... ;; cache it ...
(define (get-file-content f) (define (get-file-content f)
(read-string (fil-size f) (read-string (file-size f)
(open-input-file (symbol->string (fil-name f))))) (open-input-file (symbol->string (file-name f)))))

View File

@ -2,7 +2,8 @@
@(require scribble/manual "shared.ss" @(require scribble/manual "shared.ss"
(for-label (except-in scheme/base file-size) (for-label (except-in scheme/base file-size)
teachpack/htdp/dir)) teachpack/htdp/dir
scheme/contract))
@teachpack["dir"]{Working with Files and Directories} @teachpack["dir"]{Working with Files and Directories}
@ -11,14 +12,14 @@
The teachpack provides structures and operations for working with files and The teachpack provides structures and operations for working with files and
directories: directories:
@defstruct[dir ([name string?][dirs (list-of dir?)][files (list-of file?)])]{} @defstruct[dir ([name symbol?][dirs (listof dir?)][files (listof file?)])]{}
@defstruct[file ([name string?][content (list-of char?)])]{} @defstruct[file ([name symbol?][size integer?][content (listof char?)])]{}
@defproc[(create-dir [path string?]) dir?]{ @defproc[(create-dir [path symbol?]) dir?]{
Turns the directory found at @scheme[path] on your computer into an instance of @scheme[dir?].} Turns the directory found at @scheme[path] on your computer into an instance of @scheme[dir?].}
Sample: Set teachpack to <code>dir.ss</code> and click RUN: Sample: Set teachpack to @filepath{dir.ss} and click RUN:
@(begin @(begin
#reader scribble/comment-reader #reader scribble/comment-reader
(schemeblock (schemeblock
@ -38,4 +39,4 @@ Using ``.'' usually means the directory in which your program is
located. In this case, the directory contains no sub-directories and six located. In this case, the directory contains no sub-directories and six
files. files.
Note: Softlinks are always treated as if they were empty files. Note: Soft links are always treated as if they were empty files.