Changeset 35979 in project


Ignore:
Timestamp:
07/18/18 02:19:37 (14 months ago)
Author:
Kon Lovett
Message:

rmv typed-define use

Location:
release/4/directory-utils/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/directory-utils/trunk/directory-utils.meta

    r35381 r35979  
    1313        (stack "2.1.1")
    1414        (check-errors "1.11.0")
    15         (stack "2.1.1")
    16         (dsssl-utils "2.2.2"))
     15        (stack "2.1.1"))
    1716 (test-depends test)
    1817 (files
  • release/4/directory-utils/trunk/directory-utils.scm

    r35368 r35979  
    1313  check-directory error-directory
    1414  ;
     15  dot-filename-prefix?
    1516  dot-pathname? dot-filename?
    1617  ;
     
    3031  which-command-pathnames
    3132  which-command-pathname
    32   remove-dotfiles
    33   ;DEPRECATED
    34   create-directory/parents
    35   file-exists/directory?)
     33  remove-dotfiles)
    3634
    3735(import scheme chicken)
     
    5957  (only type-checks
    6058    define-check+error-type
    61     check-procedure)
    62   typed-define)
     59    check-procedure))
    6360
    6461;;; Helpers
     
    6764
    6865(define-type stack (struct stack))
     66
     67(define-type optional-list (or boolean list))
    6968
    7069(define-type filename string)
     
    8786
    8887;no . or .. since directoryname
    89 (define: (dot-filename-prefix? (str filename)) -> boolean
     88(: dot-filename-prefix? (filename -> boolean))
     89;
     90(define (dot-filename-prefix? str)
    9091  (and
    9192    (string-prefix? "." str)
    92     ;FIXME unix-centric
     93    #+unix
    9394    (not (or (string=? "." str) (string=? ".." str)))) )
    9495
     
    99100(define-check+error-type directory)
    100101
    101 ;NOTE do not type these as 'predicate'
    102 ;ex: (: filename? (* -> boolean : filename))
    103 ;since the compiler will treat a literal ".." as
    104 ;meeting the criteria at compile time!
     102;NOTE do not type these as 'predicate', ex: (: filename? (* -> boolean : filename))
     103;since the compiler will treat a literal ".." as meeting the criteria at compile time!
    105104
    106105;; A null pathname or only extension is not a pathname, here at least
     
    108107; detecting only an extension is impossible with string pathnames
    109108
    110 (define: (pathname? (obj *)) --> boolean
     109(: pathname? (* --> boolean))
     110;
     111(define (pathname? obj)
    111112  (and
    112113    (string? obj)
     
    118119;; Just a filename, no directory
    119120
    120 (define: (filename? (obj *)) --> boolean
     121(: filename? (* --> boolean))
     122;
     123(define (filename? obj)
    121124  (and
    122125    (string? obj)
     
    128131;;
    129132
    130 (define: (dot-filename? (obj *)) --> boolean
     133(: dot-filename? (* --> boolean))
     134;
     135(define (dot-filename? obj)
    131136  (and
    132137    (filename? obj)
     
    135140;; Is any pathname component is a dot-filename?
    136141
    137 (define: (dot-pathname? (obj *)) --> boolean
     142(: dot-pathname? (* --> boolean))
     143;
     144(define (dot-pathname? obj)
    138145  (and
    139146    (string? obj)
     
    150157;; Remove dot files from a directory list
    151158
    152 (define: (remove-dotfiles (files (list-of pathname))) -> (list-of pathname)
    153         (remove
    154           (lambda (pn)
    155             (dot-filename? (pathname-file pn)) )
    156           files) )
     159(: remove-dotfiles ((list-of pathname) --> (list-of pathname)))
     160;
     161(define (remove-dotfiles files)
     162        (remove (lambda (pn) (dot-filename? (pathname-file pn))) files) )
    157163
    158164;;
     
    162168;attribute, the MacOS X birthtime, etc.
    163169
    164 (define: (directory-fold (func procedure) (ident *) (dir pathname) . (opts (list pathname))) -> *
     170(: directory-fold (procedure * pathname #!rest -> *))
     171;
     172(define (directory-fold func ident dir . opts)
    165173  (check-procedure 'directory-fold func)
    166174  (let* (
     
    181189        (directory-utility-stack)))))
    182190
    183 (define: (ignored-directory? (dir pathname)) --> boolean
     191;;
     192
     193(: ignored-directory? (pathname --> boolean))
     194;
     195(define (ignored-directory? dir)
    184196  (or
    185197    (string-null? dir)
    186198    (string=? +dot-directory+ (make-pathname dir #f))) )
    187199
    188 (define: (push-directory (dir (or boolean pathname)))
     200(: push-directory ((or boolean pathname) -> void))
     201;
     202(define (push-directory dir)
    189203  (stack-push! (directory-utility-stack) (current-directory))
    190204  ;don't cd unless necessary
     
    192206    (current-directory dir) ) )
    193207
    194 (define: (pop-directory)
     208(: pop-directory (-> void))
     209;
     210(define (pop-directory)
    195211  (unless (stack-empty? (directory-utility-stack))
    196212    (current-directory (stack-pop! (directory-utility-stack))) ) )
    197213
    198 (define: (pop-toplevel-directory)
     214(: pop-toplevel-directory (-> void))
     215;
     216(define (pop-toplevel-directory)
    199217  (until (stack-empty? (directory-utility-stack))
    200218    (pop-directory) ) )
     
    202220;; Ensure the directory for the specified path exists.
    203221
    204 (define: (create-pathname-directory (pn pathname)) -> boolean
     222(: create-pathname-directory (pathname -> boolean))
     223;
     224(define (create-pathname-directory pn)
    205225  (->boolean
    206226    (create-directory
     
    210230;; Platform specific program filename.
    211231
    212 (define: (make-program-filename (bn basename)) -> filename
     232(: make-program-filename (basename --> filename))
     233;
     234(define (make-program-filename bn)
    213235  (cond-expand
    214236    (windows
     
    219241      bn ) ) )
    220242
    221 (define: (make-shell-filename (bn basename)) -> filename
     243(: make-shell-filename (basename -> filename))
     244;
     245(define (make-shell-filename bn)
    222246  (cond-expand
    223247    (windows
     
    232256;; Pathname if file exists in directory.
    233257
    234 (define: (file-exists-in-directory? (fil filename) . (opts (list-of pathname))) -> (or boolean pathname)
     258(: file-exists-in-directory? (filename #!rest (list pathname) -> (or boolean pathname)))
     259;
     260(define (file-exists-in-directory? fil . opts)
    235261  (let* (
    236262    (dir (optional opts #f))
     
    240266;; List of all found pathnames.
    241267
    242 (define: (find-file-pathnames-in-directory (fil filename) (dir pathname)) -> (list-of pathname)
     268(: find-file-pathnames-in-directory (filename pathname -> (list-of pathname)))
     269;
     270(define (find-file-pathnames-in-directory fil dir)
    243271  (filter-map
    244272    (cut file-exists-in-directory? fil <>)
    245273    (ensure-list dir)) )
    246274
    247 (define: (*find-file-pathnames (fil filename) (dirs (list-of pathname))) -> (or boolean (list-of pathname))
     275(: *find-file-pathnames (filename (list-of pathname) -> (or boolean (list-of pathname))))
     276;
     277(define (*find-file-pathnames fil dirs)
    248278  (let loop ((dirs dirs) (paths '()))
    249279    (if (null? dirs)
     
    255285          (find-file-pathnames-in-directory fil (car dirs))))) ) )
    256286
    257 (define: (find-file-pathnames (fil filename) . (dirs (list-of pathname))) -> (or boolean (list-of pathname))
     287(: find-file-pathnames (filename #!rest -> (or boolean (list-of pathname))))
     288;
     289(define (find-file-pathnames fil . dirs)
    258290  (*find-file-pathnames fil dirs) )
    259291
    260292;; All found program pathname in directories.
    261293
    262 (define: (find-program-pathnames (cmd filename) . (dirs (list pathname))) -> (or boolean list)
     294(: find-program-pathnames (filename #!rest (list-of pathname) -> optional-list))
     295;
     296(define (find-program-pathnames cmd . dirs)
    263297  (cond-expand
    264298    (windows
     
    276310;; All found program pathname in path.
    277311
    278 (define: (which-command-pathnames (cmd filename) . (opts (list string))) -> (or boolean list)
     312(: which-command-pathnames (filename #!rest (list string) -> optional-list))
     313;
     314(define (which-command-pathnames cmd . opts)
    279315  (let (
    280316    (varnam (optional opts "PATH")) )
     
    285321;; First found program pathname in path.
    286322
    287 (define: (which-command-pathname (cmd filename) . (opts (list string))) -> (or boolean list)
     323(: which-command-pathname (filename #!rest (list string) -> optional-list))
     324;
     325(define (which-command-pathname cmd . opts)
    288326  (let (
    289327    (varnam (optional opts "PATH")) )
     
    292330      (first ps) ) ) )
    293331
    294 ;;
    295 
    296 ;; Ensure the directory exists.
    297 
    298 (: create-directory/parents (deprecated create-directory))
    299 (define (create-directory/parents dir)
    300   (create-directory (check-pathname 'create-directory/parents dir) #t) )
    301 
    302 #; ;Not Needed Anymore
    303 (define (create-directory/parents dir)
    304   (let loop ((dir dir))
    305     (when (and dir (not (directory? dir)))
    306       (loop (pathname-directory dir))
    307       (create-directory dir) ) ) )
    308 
    309 (: file-exists/directory? (deprecated file-exists-in-directory?))
    310 (define file-exists/directory? file-exists-in-directory?)
    311 
    312332) ;directory-utils
Note: See TracChangeset for help on using the changeset viewer.