blob: f285aa24fb3605fd7f3b820761bc04644e4de7a7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
;; SPDX-License-Identifier: EUPL-1.2
;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
(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))))
|