I need to write a little file from #guile code
I d love an example, I can t bother to read about ports 😑
guile manal can be especially daunting to browse 😑
@catonano Yep, though I usually use call-with-output-file or with-output-to-file which close the file automatically when you're finished.
does call-with-output-port exist ?
anyway I managed to have a file created
the problem now is that I expected something written in it
but it's empty🙄
@catonano If you use open-output-file, you have to remember to call close-port on it when you're finished. If you don't the contents may remain buffered and not get written to the file. Or you can call force-output on the port to flush the buffers.
a that is probably what happened to me !
aahhh it works !!
I mean, there is:
Guile modules -> POSIX -> Ports and file descriptors
then ther is
API rreferrence -> Input and Output -> Port types -> File ports
Where open-output-file and open-input-file are found
And this "call-with-output-file" is not to be fond in any of these places, so it must be somewhere else
Whe ALL is needed is this:
(call-with-output-file "outpt.scm"
(lambda (port)
(write-csexp $exp port)))
🙄
ah there's also
API rreferrence -> Input and Output -> Buffering
this is where call-with-output" is found
🙄
@catonano Huh, I never realized that the manual could be so confusing...
I think this talk is pertinent
I could try to write a blog post about this
@catonano call-with-output-file takes the filename and a procedure of one argument, and calls the procedure with the open port.
(call-with-output-file "foo.txt"
(lambda (port)
(display "Hello, world!\n" port)))
with-output-to-file is similar but takes a procedure of zero arguments, and changes the default output port instead:
(with-output-to-file "foo.txt"
(lambda ()
(display "Hello, world!\n")))
ok, it s
(open-output-file "output.scm")