Hash :
8fbe02c6
Author :
Thomas de Grivel
Date :
2023-06-19T15:36:04
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
;; cl-facts
;; Copyright 2011, 2023 Thomas de Grivel <thodg@kmx.io>
;;
;; Permission is hereby granted to use this software granted
;; the above copyright notice and this permission paragraph
;; are included in all copies and substantial portions of this
;; software.
;;
;; THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
;; PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
;; AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
;; THIS SOFTWARE.
(in-package :facts)
;; Anonymous values
(defpackage :facts.anon)
(defvar *randomize-anon* nil)
(defun anon (&rest sym-hints)
(let* ((sym (intern
(with-output-to-string (out)
(write-string (string-upcase (first sym-hints)))
(dolist (sym-hint (rest sym-hints))
(write-char #\- out)
(write-string (string-upcase sym-hint))))
(find-package :facts.anon))))
(labels ((guess (count)
(multiple-value-bind (n found) (intern
(format nil "~A-~4,'0X"
sym count)
:facts.anon)
(if found
(if *randomize-anon*
(guess (random most-positive-fixnum))
(guess (1+ count)))
(prog1 n
(setf (get sym 'anon-counter) count))))))
(guess (or (get sym 'anon-counter) 0)))))
(defmacro with-anon ((&rest vars) &body body)
`(let ,(mapcar (lambda (var)
`(,var (anon ,(symbol-name var))))
vars)
,@body))