monastery/monastery.lisp
2026-07-16 20:26:22 -03:00

36 lines
1.2 KiB
Common Lisp

(in-package :monastery)
;; conditions
;;; dict-error is the general interface error, when handling conditions
;;; it is the general case to use when catching all signals that may happen
(define-condition dict-error (error)
(message :initarg :message :reader dict-error-message)
(:report
(lambda (condition stream)
(write-string (dict-error-message condition) stream)))
(:documentation "General error interface regarding the dictionary."))
(define-condition dict-initialization-error (dict-error)
()
(:documentation "Error regarding the initialization of the dictionary."))
(define-condition dict-operation-error (dict-error)
()
(:documentation "Error regarding the operations involving the dictionary."))
;; useful macros
(defmacro with-dict ((dict filepath) &body body)
"opens the dictionary path, executes the operations and closes automatically"
`(let ((,dict (dict-init ,filepath)))
(unwind-protect (progn ,@body)
(dict-close ,dict))))
;; functions
(defun dict-init (filepath)
"receives the dictionary filepath and opens the file")
(defun dict-close (dict)
"receives the dictionary instance and closes it")