vexing problem or bug?

Started by tburton, July 21, 2006, 09:13:02 PM

Previous topic - Next topic

tburton

the following works fine:



(set 'out-buff "Now is the time to try men's souls")

(write-file "soulTest1.txt" out-buff)




but this doesn't:



(set 'out-buff "Now is the time to try men's souls")

(set 'out-file-handle (open "soulTest2.txt" "write"))

(write-file out-file-handle out-buff)




What's going on here?  Many thanks.

cormullion

#1
I think out-file-handle is in fact an integer:


(integer? out-file-handle)
;-> true


but write-file wants a string...

Lutz

#2
Yes, (write-file <str-file-name> <str-content>) is for writing an entire file in one shot.

Use (write-buffer <int-handle> <str-content>) if you want to write to a file handle, which also must be closed after writing.
(set 'out-buff "Now is the time to try men's souls")
(set 'out-file-handle (open "soulTest2.txt" "write"))
(write-buffer out-file-handle out-buff)
(close out-file-handle)


Most of the time write-file does the job much easier in one statement. Use write-buffer only for bigger files, or when writing to a string buffer for fast destructive string appending (see manual).



Lutz

tburton

#3
Thanks; that clarifies.  



Tim