Plaster
New
List
Login
common-lisp
default
phoe
2022.01.31 19:32:23
Clozure Common Lisp Version 1.12 (v1.12) LinuxX8664 For more information about CCL, please see http://ccl.clozure.com. CCL is free software. It is distributed under the terms of the Apache Licence, Version 2.0. ? (defmacro first-time-value (form) (let ((cache-var (gensym (string '#:cache)))) `(let ((,cache-var (load-time-value (cons nil nil)))) (if (car ,cache-var) (cdr ,cache-var) (prog1 (setf (cdr ,cache-var) ,form) (setf (car ,cache-var) t)))))) FIRST-TIME-VALUE ? (defvar *x*) *X* ? (defun foo () (first-time-value (1+ *x*))) FOO ? (let ((*x* 42)) (foo)) 43 ? (foo) 43 ? (let ((*x* 0)) (foo)) 43
Raw
Annotate
Repaste