grokking simplicity and refactoring

This commit is contained in:
Geir Okkenhaug Jerstad 2025-06-16 13:43:21 +02:00
parent 89a7fe100d
commit fb4361d938
67 changed files with 6275 additions and 56 deletions

View file

@ -0,0 +1,30 @@
;; utils/logging/level.scm - Pure log level management
(define-module (utils logging level)
#:export (log-levels
should-log-pure
validate-log-level))
;; Pure data: Log levels with numeric values for comparison
(define log-levels
'((debug . 0)
(info . 1)
(warn . 2)
(error . 3)))
;; Pure function: Check if message should be logged at given levels
;; Input: current-level symbol, message-level symbol
;; Output: #t if should log, #f otherwise
(define (should-log-pure current-level message-level)
"Pure function to determine if message should be logged"
(let ((current-value (assoc-ref log-levels current-level))
(message-value (assoc-ref log-levels message-level)))
(and current-value message-value
(<= current-value message-value))))
;; Pure function: Validate log level
;; Input: level symbol
;; Output: #t if valid, #f otherwise
(define (validate-log-level level)
"Pure function to validate log level"
(assoc-ref log-levels level))