From 1225b4c5c922ebcd3848dddf9bb8791509e5dc58 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 Mar 2023 07:57:55 -0400 Subject: Add file-extension, absolute-file-name, and tmpdir utility procedures. --- chickadee/utils.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'chickadee/utils.scm') diff --git a/chickadee/utils.scm b/chickadee/utils.scm index 8869e8d..2d218c4 100644 --- a/chickadee/utils.scm +++ b/chickadee/utils.scm @@ -17,9 +17,25 @@ ;;; . (define-module (chickadee utils) - #:export (memoize + #:use-module (ice-9 match) + #:export (file-extension + absolute-file-name + tmpdir + memoize for-range)) +(define (file-extension file-name) + (match (string-split file-name #\.) + ((_ ... ext) ext))) + +(define (absolute-file-name file-name) + (if (absolute-file-name? file-name) + file-name + (string-append (getcwd) "/" file-name))) + +(define (tmpdir) + (or (getenv "TMPDIR") "/tmp")) + ;; Written by Ludovic Courtès. Taken from GNU Guix. (define (memoize proc) "Return a memoizing version of PROC." -- cgit v1.2.3