Hans Hübner hans.huebner@gmail.com writes:
(defun generate-random-name (prefix) (format nil "~A-~36R-~36R" prefix (random 100000000) (get-internal-real-time)))
I'd use:
(format nil "~:@(~36,8,'0R~)" (random (expt 36 8)))
to generate a random part of the name.
And if you want to include the time:
(format nil "~:@(~36,11,'0R-~36,8,'0R~)" (get-internal-real-time) (random (expt 36 8)))
but the time is not very random (ie. you're using up file name characters for nothing). If you want to add ten characters to the file name, just use a bigger random number:
(let ((n 18)) (format nil "~:@(~36,V,'0R~)" n (random (expt 36 n))))
But I'd argue that with a program specific prefix and 8 base-36 random digits are enough to avoid collisions (that's 41+ bits). Just make sure to use a really random seed: use your own random-state randomly initialized!
(defun open-temporary (&rest open-arguments
I'd prefer the name OPEN-TEMPORARY-FILE.
&key type (prefix "temp")
I'd use "TEMP"; "temp" is not conforming for a logical pathname component. See 19.3.1 Syntax of Logical Pathname Namestrings
(directory #P"TEMPORARY-FILES:")
(translate-logical-pathname (make-pathname
:name (funcall generate-random-name prefix) :type type
:defaults directory))
Add :case :common ; :case :local which is the default doesn't sound safe to me with logical pathnames.
(defmacro with-open-temporary-file ((stream &rest args) &body body)
I'd name it WITH-TEMPORARY-FILE but WITH-OPEN-TEMPORARY-FILE might be ok.