;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/src/hash-tables (:documentation "Hash-table-oriented utilities.") (:use :c2cl) (:import-from :alexandria :with-gensyms) (:export :gethash-lazy)) (in-package :ukkoclot/src/hash-tables) (defmacro gethash-lazy (key hash-table default-lazy) "`gethash' alternative with lazily evaluated default value." (with-gensyms (res unique) `(let* ((,unique ',unique) (,res (gethash ,key ,hash-table ,unique))) (if (eq ,res ,unique) ,default-lazy ,res))))