in-directory: add optional argument to filter directories
This commit is contained in:
parent
3f30400a59
commit
99daa9b34d
|
@ -6,16 +6,19 @@
|
|||
;; moved out of the core, while a new "base2" package can represent
|
||||
;; the new, smaller core.
|
||||
|
||||
;; The "base" package also depends on "raclet-lib", which ensures that
|
||||
;; The "base" package also depends on "racket-lib", which ensures that
|
||||
;; any native libraries needed for a platform are installed along with
|
||||
;; practically any package installation.
|
||||
|
||||
(define collection 'multi)
|
||||
|
||||
(define deps '("racket-lib"))
|
||||
(define deps '("racket-lib"
|
||||
["racket" #:version "6.0.0.1"]))
|
||||
|
||||
(define implies '(core))
|
||||
|
||||
(define pkg-desc "Racket libraries that are currently always available")
|
||||
|
||||
(define pkg-authors '(mflatt))
|
||||
|
||||
(define version "6.0.0.1")
|
||||
|
|
|
@ -361,18 +361,26 @@ each element in the sequence.
|
|||
(printf "key and value: ~a\n" key+value))]
|
||||
}
|
||||
|
||||
@defproc[(in-directory [dir (or/c #f path-string?) #f]) sequence?]{
|
||||
@defproc[(in-directory [dir (or/c #f path-string?) #f]
|
||||
[use-dir? ((and/c path? complete-path?) . -> . any/c)
|
||||
(lambda (dir-path) #t)])
|
||||
sequence?]{
|
||||
Returns a sequence that produces all of the paths for files,
|
||||
directories, and links within @racket[dir]. If @racket[dir] is not
|
||||
directories, and links within @racket[dir], except for the
|
||||
contents of any directory for which @racket[use-dir?] returns
|
||||
@racket[#f]. If @racket[dir] is not
|
||||
@racket[#f], then every produced path starts with @racket[dir] as
|
||||
its prefix. If @racket[dir] is @racket[#f], then paths in and
|
||||
relative to the current directory are produced.
|
||||
|
||||
An @racket[in-directory] sequence traverses nested subdirectories
|
||||
recursively. To generate a sequence that includes only the immediate
|
||||
recursively (filtered by @racket[use-dir?]).
|
||||
To generate a sequence that includes only the immediate
|
||||
content of a directory, use the result of @racket[directory-list] as
|
||||
a sequence.
|
||||
}
|
||||
|
||||
@history[#:changed "6.0.0.1" @elem{Added @racket[use-dir?] argument.}]}
|
||||
|
||||
|
||||
@defproc*[([(in-producer [producer procedure?])
|
||||
sequence?]
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
Version 6.0.0.1
|
||||
Moved detailed-change recording to documentation
|
||||
|
||||
Version 6.0, January 2014
|
||||
Packages & collections: ----------
|
||||
Reorganized collections into packages
|
||||
|
|
|
@ -1946,9 +1946,10 @@
|
|||
(for/fold ([acc acc]) ([f (in-list (directory-list full-d))])
|
||||
(cons (build-path d f) acc)))
|
||||
|
||||
(define (next-body l d init-dir)
|
||||
(define (next-body l d init-dir use-dir?)
|
||||
(let ([full-d (path->complete-path d init-dir)])
|
||||
(if (directory-exists? full-d)
|
||||
(if (and (directory-exists? full-d)
|
||||
(use-dir? full-d))
|
||||
(dir-list full-d d (cdr l))
|
||||
(cdr l))))
|
||||
|
||||
|
@ -1960,15 +1961,16 @@
|
|||
|
||||
(define *in-directory
|
||||
(case-lambda
|
||||
[() (*in-directory #f)]
|
||||
[(orig-dir)
|
||||
[() (*in-directory #f (lambda (d) #t))]
|
||||
[(orig-dir) (*in-directory #f (lambda (d) #t))]
|
||||
[(orig-dir use-dir?)
|
||||
(define init-dir (current-directory))
|
||||
;; current state of the sequence is a list of paths to produce; when
|
||||
;; incrementing past a directory, add the directory's immediate
|
||||
;; content to the front of the list:
|
||||
(define (next l)
|
||||
(define d (car l))
|
||||
(next-body l d init-dir))
|
||||
(next-body l d init-dir use-dir?))
|
||||
(make-do-sequence
|
||||
(lambda ()
|
||||
(values
|
||||
|
@ -1984,16 +1986,19 @@
|
|||
(λ (stx)
|
||||
(syntax-case stx ()
|
||||
[((d) (_)) #'[(d) (*in-directory #f)]]
|
||||
[((d) (_ dir))
|
||||
[((d) (_ dir)) #'[(d) (*in-directory dir (lambda (d) #t))]]
|
||||
[((d) (_ dir use-dir?-expr))
|
||||
#'[(d)
|
||||
(:do-in
|
||||
([(orig-dir) (or dir #f)] [(init-dir) (current-directory)])
|
||||
([(orig-dir) (or dir #f)]
|
||||
[(init-dir) (current-directory)]
|
||||
[(use-dir?) use-dir?-expr])
|
||||
#true
|
||||
([l (initial-state orig-dir init-dir)])
|
||||
(pair? l)
|
||||
([(d) (car l)])
|
||||
#true
|
||||
#true
|
||||
[(next-body l d init-dir)])]])))
|
||||
[(next-body l d init-dir use-dir?)])]])))
|
||||
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user