chickadee » pathfinder » pf:extensions

pf:extensions extsprocedure

Create a matcher object suitable for passing to path-find or path-find-all. For each directory, this matcher tries each extension in the EXTS list in order, by appending it to the current search term. If the extension was already present in the search term, it is not appended again.

The extensions in the EXTS list should include the dot, meaning ".exe" not "exe". It is legal to include a dot in the extension itself. The empty string "" is allowed as well, meaning the search term itself will be tried without any extension.

An example in which we search only one path, the Chicken repository path, with several extensions.

(define p (make-pathfinder (list (repository-path))))
(define eggs (pf:extensions '(".setup-info" ".so" ".import.so")))

(path-find p "matchable" eggs)
  ; => "/usr/local/lib/chicken/6/matchable.setup-info"
(path-find-all p "matchable" eggs)
  ; => ("/usr/local/lib/chicken/6/matchable.setup-info"
  ;     "/usr/local/lib/chicken/6/matchable.so"
  ;     "/usr/local/lib/chicken/6/matchable.import.so")

(path-find p "txpath" eggs)
  ; => "/usr/local/lib/chicken/6/txpath.so"
(path-find-all p "txpath" eggs)
  ; => ("/usr/local/lib/chicken/6/txpath.so"
  ;     "/usr/local/lib/chicken/6/txpath.import.so")

(path-find p "posix" eggs)
  ; => "/usr/local/lib/chicken/6/posix.import.so"
(path-find-all p "posix" eggs)
  ; => ("/usr/local/lib/chicken/6/posix.import.so")

Example in which we search subdirectories in multiple paths:

(define p (make-pathfinder (list "user" "template") root: "/var/www/htdocs"))
(define webs (pf:extensions '(".css" ".scss" ".js")))

(path-find p "js/jquery" webs)
  ; => "/var/www/htdocs/template/js/jquery.js"
(path-find p "css/screen" webs)
  ; => "/var/www/htdocs/user/css/screen.css"
(path-find-all p "css/screen" webs)
  ; => ("/var/www/htdocs/user/css/screen.css"
  ;     "/var/www/htdocs/user/css/screen.scss"
  ;     "/var/www/htdocs/template/css/screen.css"
  ;     "/var/www/htdocs/template/css/screen.scss")
(path-find p "css/screen.scss" webs)
  ; => "/var/www/htdocs/user/css/screen.scss"
(path-find-all p "css/screen.scss" webs)
  ; => ("/var/www/htdocs/user/css/screen.scss"
  ;     "/var/www/htdocs/template/css/screen.scss")
(path-find p "/template/css/screen" webs)
  ; => "/var/www/htdocs/template/css/screen.css"