On 22 Aug 2016, at 23:48, Robert Goldman rpgoldman@sift.net wrote:
I am translating some existing code that does something like the following:
concatenate f1 and f2 > temp file 1 concatenate f2 and f1 (i.e., reverse concat) > temp file 2 compute function of temp file 1 compute function of temp file 2 return minimum of f(temp file1), f(temp file2)
I did this using "cat" for which it is more convenient to have the name of the file than the stream.
In general, when invoking the shell, the shell "speaks" names, not CL streams.
Now, as you said, I could simply replicate the logic of GET-TEMPORARY-FILE, but since GET-TEMPORARY-FILE pretty much replicates the interface of mktemp, which the shell wizards consider to be valuable, I think there's precedent for something like GET-TEMPORARY-FILE being supplied. Although, perhaps calling it GET-TEMPORARY-FILENAME would be better.
Is there some reason it would be inappropriate to export this?
I see your point now and support your plan to export get-temporary-filename.
What I was thinking is: the non-trivial part of generating a temporary file is that you need to at the same time check that your filename is not already taken and then reserve it right away, ideally atomically. So you cannot hand out a temporary file name without also creating the file, and to that end you need to open it. So if you were to write code such as
(with-open-file (stream (get-temporary-filename)))
you’d open-close-open-close the file unnecessarily, whereas with-temporary-file would only open and close the file once. But I was forgetting the case where you’re calling an external process. Since LispWorks e.g. will not accept existing streams as :input/:output
(run-program … :input (get-temporary-filename))
would be the most portable solution.
Elias